NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxVideoServiceProxy.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 
12 #include "cxVideoServiceProxy.h"
13 
14 #include <boost/bind.hpp>
15 #include <ctkPluginContext.h>
16 #include "cxNullDeleter.h"
17 
18 #include "cxStreamerService.h"
19 //#include "cxTypeConversions.h"
20 
21 namespace cx
22 {
23 
24 VideoServicePtr VideoServiceProxy::create(ctkPluginContext *pluginContext)
25 {
26  return VideoServicePtr(new VideoServiceProxy(pluginContext));
27 }
28 
29 VideoServiceProxy::VideoServiceProxy(ctkPluginContext *pluginContext) :
30  mPluginContext(pluginContext),
31  mVideoService(VideoService::getNullObject())
32 {
33  this->initServiceListener();
34 }
35 
36 void VideoServiceProxy::initServiceListener()
37 {
38  mVideoServiceListener.reset(new ServiceTrackerListener<VideoService>(
39  mPluginContext,
40  boost::bind(&VideoServiceProxy::onVideoServiceAdded, this, _1),
41  boost::function<void (VideoService*)>(),
42  boost::bind(&VideoServiceProxy::onVideoServiceRemoved, this, _1)
43  ));
44  mVideoServiceListener->open();
45 }
46 
47 void VideoServiceProxy::onVideoServiceAdded(VideoService* service)
48 {
49  mVideoService.reset(service, null_deleter());
50 
51  connect(service, &VideoService::connected, this, &VideoService::connected);
54  connect(service, &VideoService::fps, this, &VideoService::fps);
55 
57 }
58 
59 void VideoServiceProxy::onVideoServiceRemoved(VideoService *service)
60 {
61  disconnect(service, &VideoService::connected, this, &VideoService::connected);
64  disconnect(service, &VideoService::fps, this, &VideoService::fps);
65 
66  mVideoService = VideoService::getNullObject();
67 
68  emit connected(false);
70 }
71 
73 {
74  return mVideoService->isNull();
75 }
76 
78 {
79  return mVideoService->getStreamerService(uid);
80 }
81 
82 QList<StreamerServicePtr> VideoServiceProxy::getStreamerServices()
83 {
84  return mVideoService->getStreamerServices();
85 }
86 
88 {
89  mVideoService->setActiveVideoSource(uid);
90 }
91 
93 {
94  return mVideoService->getActiveVideoSource();
95 }
96 
97 std::vector<VideoSourcePtr> VideoServiceProxy::getVideoSources()
98 {
99  return mVideoService->getVideoSources();
100 }
101 
102 void VideoServiceProxy::setConnectionMethod(QString connectionMethod)
103 {
104  mVideoService->setConnectionMethod(connectionMethod);
105 }
106 
108 {
109  return mVideoService->getConnectionMethod();
110 }
111 
113 {
114  mVideoService->openConnection();
115 }
116 
118 {
119  mVideoService->closeConnection();
120 }
121 
123 {
124  return mVideoService->isConnected();
125 }
126 
128 {
129  mVideoService->setPlaybackMode(controller);
130 }
131 
132 std::vector<TimelineEvent> VideoServiceProxy::getPlaybackEvents()
133 {
134  return mVideoService->getPlaybackEvents();
135 }
136 
137 
138 
139 } //cx
cx::VideoService::connected
void connected(bool on)
cx::VideoServicePtr
boost::shared_ptr< class VideoService > VideoServicePtr
Definition: cxLogicManager.h:26
cx::VideoService
Provides access to all video sources in the system, and connection stuff for the sources.
Definition: cxVideoService.h:75
cx::VideoService::connectionMethodChanged
void connectionMethodChanged()
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::VideoServiceProxy::getVideoSources
virtual std::vector< VideoSourcePtr > getVideoSources()
Definition: cxVideoServiceProxy.cpp:97
cx::ServiceTrackerListener
Helper class for listening to services being added, modified and removed.
Definition: cxServiceTrackerListener.h:53
cx::VideoServiceProxy::getStreamerServices
virtual QList< StreamerServicePtr > getStreamerServices()
Definition: cxVideoServiceProxy.cpp:82
cx::VideoServiceProxy::setConnectionMethod
virtual void setConnectionMethod(QString connectionMethod)
Definition: cxVideoServiceProxy.cpp:102
cxStreamerService.h
cx::VideoService::getNullObject
static VideoServicePtr getNullObject()
Definition: cxVideoService.cpp:19
cx::PlaybackTimePtr
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
Definition: cxTrackingSystemBronchoscopyService.h:42
cx::VideoSourcePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
Definition: cxForwardDeclarations.h:109
cx::VideoServiceProxy::getStreamerService
virtual StreamerServicePtr getStreamerService(QString uid)
Definition: cxVideoServiceProxy.cpp:77
cx::VideoService::fps
void fps(int)
cx::VideoServiceProxy::openConnection
virtual void openConnection()
Definition: cxVideoServiceProxy.cpp:112
cx::VideoServiceProxy::VideoServiceProxy
VideoServiceProxy(ctkPluginContext *pluginContext)
Definition: cxVideoServiceProxy.cpp:29
cxNullDeleter.h
cx::StreamerServicePtr
boost::shared_ptr< class StreamerService > StreamerServicePtr
Definition: cxPlusConnectWidget.h:26
cx::VideoServiceProxy::getPlaybackEvents
virtual std::vector< TimelineEvent > getPlaybackEvents()
Definition: cxVideoServiceProxy.cpp:132
cx::VideoServiceProxy::setActiveVideoSource
virtual void setActiveVideoSource(QString uid)
Definition: cxVideoServiceProxy.cpp:87
cx::VideoServiceProxy::create
static VideoServicePtr create(ctkPluginContext *pluginContext)
Definition: cxVideoServiceProxy.cpp:24
cx::VideoServiceProxy::isConnected
virtual bool isConnected() const
Definition: cxVideoServiceProxy.cpp:122
cx::VideoServiceProxy::isNull
bool isNull()
Definition: cxVideoServiceProxy.cpp:72
cx::VideoServiceProxy::closeConnection
virtual void closeConnection()
Definition: cxVideoServiceProxy.cpp:117
cxVideoServiceProxy.h
cx::VideoService::activeVideoSourceChanged
void activeVideoSourceChanged()
cx::VideoServiceProxy::getActiveVideoSource
virtual VideoSourcePtr getActiveVideoSource()
Definition: cxVideoServiceProxy.cpp:92
cx::VideoServiceProxy::setPlaybackMode
virtual void setPlaybackMode(PlaybackTimePtr controller)
Definition: cxVideoServiceProxy.cpp:127
cx::VideoServiceProxy::getConnectionMethod
virtual QString getConnectionMethod()
Definition: cxVideoServiceProxy.cpp:107