opensurgsim
CommonDevice.h
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 
22 #include "SurgSim/Input/DeviceInterface.h"
23 #include "SurgSim/DataStructures/DataGroup.h"
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 
73  std::string getNameForCallback() const;
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 
116  std::string m_nameForCallback;
117 
119  DataStructures::DataGroup m_inputData;
120 
122  DataStructures::DataGroup m_outputData;
123 
125  std::vector<std::weak_ptr<InputConsumerInterface>> m_inputConsumerList;
126 
128  std::weak_ptr<OutputProducerInterface> m_outputProducer;
129 
131  boost::mutex m_consumerProducerMutex;
132 
133 };
134 
135 
136 }; // namespace Input
137 }; // namespace SurgSim
138 
139 #endif // SURGSIM_INPUT_COMMONDEVICE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual ~CommonDevice()
Destructor.
Definition: CommonDevice.cpp:53
virtual bool pullOutput()
Pull application output from a producer.
Definition: CommonDevice.cpp:191
bool hasOutputProducer() override
Query if this object has output producer.
Definition: CommonDevice.cpp:171
std::string getName() const override
Return a (hopefully unique) device name.
Definition: CommonDevice.cpp:59
bool removeInputConsumer(std::shared_ptr< InputConsumerInterface > inputConsumer) override
Removes an input consumer previously added via addInputConsumer.
Definition: CommonDevice.cpp:106
void clearOutputProducer() override
Removes any OutputProducer.
Definition: CommonDevice.cpp:164
std::string getClassName() const override
The class name for this class.
Definition: CommonDevice.cpp:64
std::string getNameForCallback() const
Get the name used for calling the input consumers and output producer.
Definition: CommonDevice.cpp:78
A collection of NamedData objects.
Definition: DataGroup.h:68
bool removeOutputProducer(std::shared_ptr< OutputProducerInterface > outputProducer) override
Removes an output producer previously added via setOutputProducer.
Definition: CommonDevice.cpp:148
DataStructures::DataGroup & getInputData()
Getter for the input data DataGroup.
Definition: CommonDevice.cpp:214
void clearInputConsumers() override
Removes all InputConsumers.
Definition: CommonDevice.cpp:126
void setNameForCallback(const std::string &name)
Set the name used for calling the input consumers and output producer.
Definition: CommonDevice.cpp:73
const DataStructures::DataGroup & getOutputData() const
Getter for the output data DataGroup.
Definition: CommonDevice.cpp:219
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:35
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:41
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
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
CommonDevice(const std::string &name)
Constructor.
Definition: CommonDevice.cpp:32
virtual void pushInput()
Push application input to consumers.
Definition: CommonDevice.cpp:176