Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxAcquisitionServiceProxy.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 
34 
35 #include <boost/bind.hpp>
36 #include <ctkPluginContext.h>
37 #include "cxNullDeleter.h"
38 #include "cxLogger.h"
39 
40 namespace cx
41 {
42 
43 //AcquisitionServicePtr AcquisitionServiceProxy::create(ctkPluginContext *pluginContext)
44 //{
45 // return AcquisitionServicePtr(new AcquisitionServiceProxy(pluginContext));
46 //}
47 
49  mPluginContext(context),
50  mAcquisitionService(AcquisitionService::getNullObject())
51 {
52  this->initServiceListener();
53 }
54 
55 void AcquisitionServiceProxy::initServiceListener()
56 {
57  mServiceListener.reset(new ServiceTrackerListener<AcquisitionService>(
58  mPluginContext,
59  boost::bind(&AcquisitionServiceProxy::onServiceAdded, this, _1),
60  boost::function<void (AcquisitionService*)>(),
61  boost::bind(&AcquisitionServiceProxy::onServiceRemoved, this, _1)
62  ));
63  mServiceListener->open();
64 }
65 void AcquisitionServiceProxy::onServiceAdded(AcquisitionService* service)
66 {
67  mAcquisitionService.reset(service, null_deleter());
68 
75 
78 
79  if(mAcquisitionService->isNull())
80  reportWarning("AcquisitionServiceProxy::onServiceAdded mAcquisitionService->isNull()");
81 
82  emit stateChanged();
83  emit usReadinessChanged();
85 }
86 
87 void AcquisitionServiceProxy::onServiceRemoved(AcquisitionService *service)
88 {
89  disconnect(service, &AcquisitionService::started, this, &AcquisitionService::started);
95 
98 
99  mAcquisitionService = AcquisitionService::getNullObject();
100 
101  emit stateChanged();
102  emit usReadinessChanged();
104 }
105 
107 {
108  return mAcquisitionService->isNull();
109 }
110 
112 {
113  return mAcquisitionService->getLatestSession();
114 }
115 
116 std::vector<RecordSessionPtr> AcquisitionServiceProxy::getSessions()
117 {
118  return mAcquisitionService->getSessions();
119 }
120 
122 {
123  return mAcquisitionService->isReady(context);
124 }
125 
127 {
128  return mAcquisitionService->getInfoText(context);
129 }
130 
132 {
133  return mAcquisitionService->getState();
134 }
135 
136 void AcquisitionServiceProxy::startRecord(TYPES context, QString category, RecordSessionPtr session)
137 {
138  mAcquisitionService->startRecord(context, category, session);
139 }
140 
142 {
143  mAcquisitionService->stopRecord();
144 }
145 
147 {
148  mAcquisitionService->cancelRecord();
149 }
150 
152 {
153  mAcquisitionService->startPostProcessing();
154 }
155 
157 {
158  mAcquisitionService->stopPostProcessing();
159 }
160 
162 {
163  return mAcquisitionService->getNumberOfSavingThreads();
164 }
165 
166 } //cx
Acqusition services abstract interface.
virtual RecordSessionPtr getLatestSession()
void saveDataCompleted(QString mhdFilename)
emitted when data has been saved to file
virtual void startRecord(TYPES context, QString category, RecordSessionPtr session)
virtual QString getInfoText(TYPES context) const
boost::shared_ptr< class RecordSession > RecordSessionPtr
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
virtual bool isReady(TYPES context) const
static AcquisitionServicePtr getNullObject()
Helper class for listening to services being added, modified and removed.
AcquisitionServiceProxy(ctkPluginContext *context)
void acquisitionDataReady()
emitted when data is acquired and sent to the reconstruction module
virtual std::vector< RecordSessionPtr > getSessions()