CommonDevice.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2015, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_INPUT_COMMONDEVICE_H
17 #define SURGSIM_INPUT_COMMONDEVICE_H
18 
19 #include <memory>
20 #include <string>
21 
24 
25 namespace SurgSim
26 {
27 namespace Input
28 {
29 
30 class InputConsumerInterface;
31 class OutputProducerInterface;
32 
36 {
37 public:
40  explicit CommonDevice(const std::string& name);
41 
48  CommonDevice(const std::string& name, const DataStructures::DataGroup& inputData);
49 
56  CommonDevice(const std::string& name, DataStructures::DataGroup&& inputData);
57 
59  virtual ~CommonDevice();
60 
61  std::string getName() const override;
62 
63  std::string getClassName() const override;
64 
68  void setNameForCallback(const std::string& name);
69 
74 
75  bool addInputConsumer(std::shared_ptr<InputConsumerInterface> inputConsumer) override;
76 
77  bool removeInputConsumer(std::shared_ptr<InputConsumerInterface> inputConsumer) override;
78 
79  void clearInputConsumers() override;
80 
81  bool setOutputProducer(std::shared_ptr<OutputProducerInterface> outputProducer) override;
82 
83  bool removeOutputProducer(std::shared_ptr<OutputProducerInterface> outputProducer) override;
84 
85  bool hasOutputProducer() override;
86 
87  void clearOutputProducer() override;
88 
89 protected:
90 
92  virtual void pushInput();
93 
95  virtual bool pullOutput();
96 
102 
109 
110 private:
111  struct State;
112 
113  const std::string m_name;
114 
117 
120 
123 
125  std::vector<std::weak_ptr<InputConsumerInterface>> m_inputConsumerList;
126 
128  std::weak_ptr<OutputProducerInterface> m_outputProducer;
129 
132 
133 };
134 
135 
136 }; // namespace Input
137 }; // namespace SurgSim
138 
139 #endif // SURGSIM_INPUT_COMMONDEVICE_H
SurgSim::Input::CommonDevice::setOutputProducer
bool setOutputProducer(std::shared_ptr< OutputProducerInterface > outputProducer) override
Sets an output producer that will be asked for application output state when the device needs it.
Definition: CommonDevice.cpp:132
SurgSim::Input::CommonDevice::getOutputData
const DataStructures::DataGroup & getOutputData() const
Getter for the output data DataGroup.
Definition: CommonDevice.cpp:219
SurgSim::Input::CommonDevice::~CommonDevice
virtual ~CommonDevice()
Destructor.
Definition: CommonDevice.cpp:53
SurgSim::Input::CommonDevice::hasOutputProducer
bool hasOutputProducer() override
Query if this object has output producer.
Definition: CommonDevice.cpp:171
SurgSim::Input::CommonDevice::getName
std::string getName() const override
Return a (hopefully unique) device name.
Definition: CommonDevice.cpp:59
SurgSim::Input::CommonDevice::m_name
const std::string m_name
Definition: CommonDevice.h:111
SurgSim::Input::CommonDevice::getNameForCallback
std::string getNameForCallback() const
Get the name used for calling the input consumers and output producer.
Definition: CommonDevice.cpp:78
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Input::CommonDevice
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:35
SurgSim::Input::CommonDevice::m_inputData
DataStructures::DataGroup m_inputData
The data the device is providing to its input consumers.
Definition: CommonDevice.h:119
SurgSim::DataStructures::DataGroup
A collection of NamedData objects.
Definition: DataGroup.h:68
DeviceInterface.h
SurgSim::Input::CommonDevice::m_inputConsumerList
std::vector< std::weak_ptr< InputConsumerInterface > > m_inputConsumerList
The list of input consumers.
Definition: CommonDevice.h:125
SurgSim::Input::CommonDevice::clearInputConsumers
void clearInputConsumers() override
Removes all InputConsumers.
Definition: CommonDevice.cpp:126
SurgSim::Input::CommonDevice::getInputData
DataStructures::DataGroup & getInputData()
Getter for the input data DataGroup.
Definition: CommonDevice.cpp:214
SurgSim::Input::DeviceInterface
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:41
SurgSim::Input::CommonDevice::m_outputData
DataStructures::DataGroup m_outputData
The data the output producer (if any) is providing to the device.
Definition: CommonDevice.h:122
SurgSim::Input::CommonDevice::m_consumerProducerMutex
boost::mutex m_consumerProducerMutex
The mutex that protects the consumers and the producer.
Definition: CommonDevice.h:131
SurgSim::Input::CommonDevice::clearOutputProducer
void clearOutputProducer() override
Removes any OutputProducer.
Definition: CommonDevice.cpp:164
SurgSim::Input::CommonDevice::pushInput
virtual void pushInput()
Push application input to consumers.
Definition: CommonDevice.cpp:176
SurgSim::Input::CommonDevice::getClassName
std::string getClassName() const override
The class name for this class.
Definition: CommonDevice.cpp:64
SurgSim::Input::CommonDevice::removeOutputProducer
bool removeOutputProducer(std::shared_ptr< OutputProducerInterface > outputProducer) override
Removes an output producer previously added via setOutputProducer.
Definition: CommonDevice.cpp:148
SurgSim::Input::CommonDevice::pullOutput
virtual bool pullOutput()
Pull application output from a producer.
Definition: CommonDevice.cpp:191
SurgSim::Input::CommonDevice::removeInputConsumer
bool removeInputConsumer(std::shared_ptr< InputConsumerInterface > inputConsumer) override
Removes an input consumer previously added via addInputConsumer.
Definition: CommonDevice.cpp:106
SurgSim::Input::CommonDevice::m_outputProducer
std::weak_ptr< OutputProducerInterface > m_outputProducer
The output producer, if any.
Definition: CommonDevice.h:128
DataGroup.h
SurgSim::Input::CommonDevice::addInputConsumer
bool addInputConsumer(std::shared_ptr< InputConsumerInterface > inputConsumer) override
Adds an input consumer that will be notified when the application input state is updated.
Definition: CommonDevice.cpp:83
SurgSim::Input::CommonDevice::setNameForCallback
void setNameForCallback(const std::string &name)
Set the name used for calling the input consumers and output producer.
Definition: CommonDevice.cpp:73
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Input::CommonDevice::CommonDevice
CommonDevice(const std::string &name)
Constructor.
Definition: CommonDevice.cpp:32
SurgSim::Input::CommonDevice::m_nameForCallback
std::string m_nameForCallback
The name used for the callbacks, defaults to the device name.
Definition: CommonDevice.h:116