NorMIT-nav  16.5
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(uid);
101 }
102 
103 QList<StreamerServicePtr> VideoServiceProxy::getStreamerServices()
104 {
105  return mVideoService->getStreamerServices();
106 }
107 
109 {
110  mVideoService->setActiveVideoSource(uid);
111 }
112 
114 {
115  return mVideoService->getActiveVideoSource();
116 }
117 
118 std::vector<VideoSourcePtr> VideoServiceProxy::getVideoSources()
119 {
120  return mVideoService->getVideoSources();
121 }
122 
123 void VideoServiceProxy::setConnectionMethod(QString connectionMethod)
124 {
125  mVideoService->setConnectionMethod(connectionMethod);
126 }
127 
129 {
130  return mVideoService->getConnectionMethod();
131 }
132 
134 {
135  mVideoService->openConnection();
136 }
137 
139 {
140  mVideoService->closeConnection();
141 }
142 
144 {
145  return mVideoService->isConnected();
146 }
147 
149 {
150  mVideoService->setPlaybackMode(controller);
151 }
152 
153 std::vector<TimelineEvent> VideoServiceProxy::getPlaybackEvents()
154 {
155  return mVideoService->getPlaybackEvents();
156 }
157 
158 
159 
160 } //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 std::vector< VideoSourcePtr > getVideoSources()
boost::shared_ptr< class PlaybackTime > PlaybackTimePtr
virtual StreamerServicePtr getStreamerService(QString uid)
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual QList< StreamerServicePtr > getStreamerServices()
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)
boost::shared_ptr< class StreamerService > StreamerServicePtr
virtual bool isConnected() const
void activeVideoSourceChanged()
VideoServiceProxy(ctkPluginContext *pluginContext)