NorMIT-nav  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
cx::StreamerServiceProxy::getType
virtual QString getType() const
Definition: cxStreamerServiceProxy.cpp:31
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::StreamerServiceProxy::getSettings
virtual std::vector< PropertyPtr > getSettings(QDomElement root)
Definition: cxStreamerServiceProxy.cpp:41
cx::ServiceTrackerListener
Helper class for listening to services being added, modified and removed.
Definition: cxServiceTrackerListener.h:53
cx::StreamerServiceProxy::getName
virtual QString getName()
Definition: cxStreamerServiceProxy.cpp:26
cx::StreamerService::getNullObject
static StreamerServicePtr getNullObject()
Definition: cxStreamerService.cpp:19
cx::StreamerServiceProxy::StreamerServiceProxy
StreamerServiceProxy(ctkPluginContext *context, QString name)
Definition: cxStreamerServiceProxy.cpp:18
cxStreamerServiceProxy.h
cxNullDeleter.h
cx::StreamerServiceProxy::stop
virtual void stop()
Definition: cxStreamerServiceProxy.cpp:36
cx::StreamerServiceProxy::createStreamer
virtual StreamerPtr createStreamer(QDomElement root)
Definition: cxStreamerServiceProxy.cpp:46
cx::StreamerService
Abstract class. Interface to Streamers.
Definition: cxStreamerService.h:42
cx::StreamerPtr
boost::shared_ptr< class Streamer > StreamerPtr
Definition: cxImageReceiverThread.h:29