Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxStreamerServiceProxy.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxStreamerServiceProxy.h"
12 
13 #include <boost/bind.hpp>
14 #include "cxNullDeleter.h"
15 
16 namespace cx
17 {
18 StreamerServiceProxy::StreamerServiceProxy(ctkPluginContext *context, QString name) :
19  mPluginContext(context),
20  mServiceName(name),
21  mStreamerService(StreamerService::getNullObject())
22 {
23  this->initServiceListener();
24 }
25 
27 {
28  return mStreamerService->getName();
29 }
30 
32 {
33  return mStreamerService->getType();
34 }
35 
37 {
38  return mStreamerService->stop();
39 }
40 
41 std::vector<PropertyPtr> StreamerServiceProxy::getSettings(QDomElement root)
42 {
43  return mStreamerService->getSettings(root);
44 }
45 
47 {
48  return mStreamerService->createStreamer(root);
49 }
50 
51 void StreamerServiceProxy::initServiceListener()
52 {
53  mServiceListener.reset(new ServiceTrackerListener<StreamerService>(
54  mPluginContext,
55  boost::bind(&StreamerServiceProxy::onServiceAdded, this, _1),
56  boost::function<void (StreamerService*)>(),
57  boost::bind(&StreamerServiceProxy::onServiceRemoved, this, _1)
58  ));
59  mServiceListener->open();
60 }
61 
62 void StreamerServiceProxy::onServiceAdded(StreamerService* service)
63 {
64  if(service && service->getName() == mServiceName)
65  mStreamerService.reset(service, null_deleter());
66 }
67 
68 void StreamerServiceProxy::onServiceRemoved(StreamerService *service)
69 {
70  if(service && (service->getName() == mServiceName))
71  mStreamerService = StreamerService::getNullObject();
72 }
73 } //end namespace cx
static StreamerServicePtr getNullObject()
virtual QString getType() const
virtual QString getName()=0
virtual StreamerPtr createStreamer(QDomElement root)
Helper class for listening to services being added, modified and removed.
StreamerServiceProxy(ctkPluginContext *context, QString name)
Abstract class. Interface to Streamers.
virtual std::vector< PropertyPtr > getSettings(QDomElement root)
boost::shared_ptr< class Streamer > StreamerPtr
Namespace for all CustusX production code.