CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxVideoServiceProxy.h"
34 
35 #include <boost/bind.hpp>
36 #include <ctkPluginContext.h>
37 #include "cxNullDeleter.h"
38 
39 #include "cxStreamerService.h"
40 //#include "cxTypeConversions.h"
41 
42 namespace cx
43 {
44 
45 VideoServicePtr VideoServiceProxy::create(ctkPluginContext *pluginContext)
46 {
47  return VideoServicePtr(new VideoServiceProxy(pluginContext));
48 }
49 
50 VideoServiceProxy::VideoServiceProxy(ctkPluginContext *pluginContext) :
51  mPluginContext(pluginContext),
52  mVideoService(VideoService::getNullObject())
53 {
54  this->initServiceListener();
55 }
56 
57 void VideoServiceProxy::initServiceListener()
58 {
59  mVideoServiceListener.reset(new ServiceTrackerListener<VideoService>(
60  mPluginContext,
61  boost::bind(&VideoServiceProxy::onVideoServiceAdded, this, _1),
62  boost::function<void (VideoService*)>(),
63  boost::bind(&VideoServiceProxy::onVideoServiceRemoved, this, _1)
64  ));
65  mVideoServiceListener->open();
66 }
67 
68 void VideoServiceProxy::onVideoServiceAdded(VideoService* service)
69 {
70  mVideoService.reset(service, null_deleter());
71 
72  connect(service, &VideoService::connected, this, &VideoService::connected);
73 // connect(service, &VideoService::connectionMethodChanged, this, &VideoService::connectionMethodChanged);
75  connect(service, &VideoService::fps, this, &VideoService::fps);
76 
78 }
79 
80 void VideoServiceProxy::onVideoServiceRemoved(VideoService *service)
81 {
82  disconnect(service, &VideoService::connected, this, &VideoService::connected);
83 // disconnect(service, &VideoService::connectionMethodChanged, this, &VideoService::connectionMethodChanged);
85  disconnect(service, &VideoService::fps, this, &VideoService::fps);
86 
87  mVideoService = VideoService::getNullObject();
88 
89  emit connected(false);
91 }
92 
94 {
95  return mVideoService->isNull();
96 }
97 
99 {
100  return mVideoService->getStreamerService(service);
101 }
102 
103 QList<StreamerService*> VideoServiceProxy::getStreamerServices()
104 {
105  return mVideoService->getStreamerServices();
106 }
107 
108 
109 
111 {
112  mVideoService->setActiveVideoSource(uid);
113 }
114 
116 {
117  return mVideoService->getActiveVideoSource();
118 }
119 
120 std::vector<VideoSourcePtr> VideoServiceProxy::getVideoSources()
121 {
122  return mVideoService->getVideoSources();
123 }
124 
125 void VideoServiceProxy::setConnectionMethod(QString connectionMethod)
126 {
127  mVideoService->setConnectionMethod(connectionMethod);
128 }
129 
131 {
132  return mVideoService->getConnectionMethod();
133 }
134 
136 {
137  mVideoService->openConnection();
138 }
139 
141 {
142  mVideoService->closeConnection();
143 }
144 
146 {
147  return mVideoService->isConnected();
148 }
149 
151 {
152  mVideoService->setPlaybackMode(controller);
153 }
154 
155 std::vector<TimelineEvent> VideoServiceProxy::getPlaybackEvents()
156 {
157  return mVideoService->getPlaybackEvents();
158 }
159 
160 
161 
162 } //cx
boost::shared_ptr< class VideoService > VideoServicePtr
virtual VideoSourcePtr getActiveVideoSource()
void connected(bool on)
virtual QString getConnectionMethod()
virtual void setPlaybackMode(PlaybackTimePtr controller)
virtual std::vector< TimelineEvent > getPlaybackEvents()
static VideoServicePtr create(ctkPluginContext *pluginContext)
virtual QList< StreamerService * > getStreamerServices()
virtual std::vector< VideoSourcePtr > getVideoSources()
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual StreamerService * getStreamerService(QString service)
static VideoServicePtr getNullObject()
Helper class for listening to services being added, modified and removed.
Provides access to all video sources in the system, and connection stuff for the sources.
virtual void setConnectionMethod(QString connectionMethod)
virtual void setActiveVideoSource(QString uid)
virtual bool isConnected() const
Abstract class. Interface to Streamers.
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
void activeVideoSourceChanged()
VideoServiceProxy(ctkPluginContext *pluginContext)