CommonDevice.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, 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 
25 
26 namespace SurgSim
27 {
28 namespace Input
29 {
30 
31 
35 {
36 public:
39  explicit CommonDevice(const std::string& name);
40 
47  CommonDevice(const std::string& name, const SurgSim::DataStructures::DataGroup& inputData);
48 
56 
58  virtual ~CommonDevice();
59 
61  virtual std::string getName() const override;
62 
66  void setNameForCallback(const std::string& name);
67 
72 
76  virtual bool addInputConsumer(std::shared_ptr<InputConsumerInterface> inputConsumer) override;
77 
81  virtual bool removeInputConsumer(std::shared_ptr<InputConsumerInterface> inputConsumer) override;
82 
86  virtual bool setOutputProducer(std::shared_ptr<OutputProducerInterface> outputProducer) override;
87 
91  virtual bool removeOutputProducer(std::shared_ptr<OutputProducerInterface> outputProducer) override;
92 
95  virtual bool hasOutputProducer() override;
96 
97 protected:
98 
100  virtual void pushInput();
101 
103  virtual bool pullOutput();
104 
110 
117 
118 private:
119  struct State;
120 
121  const std::string m_name;
122 
125 
128 
131 
143  std::unique_ptr<State> m_state;
144 };
145 
146 
147 }; // namespace Input
148 }; // namespace SurgSim
149 
150 #endif // SURGSIM_INPUT_COMMONDEVICE_H
Definition: DriveElementFromInputBehavior.cpp:27
virtual ~CommonDevice()
Destructor.
Definition: CommonDevice.cpp:72
std::string getNameForCallback() const
Get the name used for calling the input consumers and output producer.
Definition: CommonDevice.cpp:86
virtual bool pullOutput()
Pull application output from a producer.
Definition: CommonDevice.cpp:181
virtual bool hasOutputProducer() override
Getter for whether or not this device is connected with an OutputProducerInterface.
Definition: CommonDevice.cpp:165
virtual std::string getName() const override
Return a (hopefully unique) device name.
Definition: CommonDevice.cpp:76
std::string m_nameForCallback
The name used for the callbacks, defaults to the device name.
Definition: CommonDevice.h:124
const SurgSim::DataStructures::DataGroup & getOutputData() const
Getter for the output data DataGroup.
Definition: CommonDevice.cpp:208
SurgSim::DataStructures::DataGroup m_outputData
The data the output producer (if any) is providing to the device.
Definition: CommonDevice.h:130
virtual bool removeInputConsumer(std::shared_ptr< InputConsumerInterface > inputConsumer) override
Disconnect this device from an InputConsumerInterface, which will no longer receive data from this de...
Definition: CommonDevice.cpp:112
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
Definition: CommonDevice.cpp:29
SurgSim::DataStructures::DataGroup & getInputData()
Getter for the input data DataGroup.
Definition: CommonDevice.cpp:203
A collection of NamedData objects.
Definition: DataGroup.h:66
virtual bool removeOutputProducer(std::shared_ptr< OutputProducerInterface > outputProducer) override
Disconnect this device from an OutputProducerInterface, which will no longer send data to this device...
Definition: CommonDevice.cpp:148
void setNameForCallback(const std::string &name)
Set the name used for calling the input consumers and output producer.
Definition: CommonDevice.cpp:81
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:34
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:39
virtual bool addInputConsumer(std::shared_ptr< InputConsumerInterface > inputConsumer) override
Connect this device to an InputConsumerInterface, which will receive the data that comes from this de...
Definition: CommonDevice.cpp:91
virtual bool setOutputProducer(std::shared_ptr< OutputProducerInterface > outputProducer) override
Connect this device to an OutputProducerInterface, which will send data to this device.
Definition: CommonDevice.cpp:132
std::unique_ptr< State > m_state
Struct to hide some of the private member variables, PImpl (Pointer to Implementation).
Definition: CommonDevice.h:143
const std::string m_name
Definition: CommonDevice.h:119
CommonDevice(const std::string &name)
Constructor.
Definition: CommonDevice.cpp:48
SurgSim::DataStructures::DataGroup m_inputData
The data the device is providing to its input consumers.
Definition: CommonDevice.h:127
virtual void pushInput()
Push application input to consumers.
Definition: CommonDevice.cpp:170