FilteredDevice.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_DEVICES_DEVICEFILTERS_FILTEREDDEVICE_H
17 #define SURGSIM_DEVICES_DEVICEFILTERS_FILTEREDDEVICE_H
18 
19 #include <boost/thread/shared_mutex.hpp>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
25 
26 namespace SurgSim
27 {
28 namespace Input
29 {
30 class InputConsumerInterface;
31 class OutputProducerInterface;
32 }
33 
34 namespace Devices
35 {
36 class DeviceFilter;
37 
40 {
41 public:
44  explicit FilteredDevice(const std::string& name);
45 
47 
49  virtual ~FilteredDevice();
50 
51  std::string getName() const override;
52 
53  bool initialize() override;
54 
55  bool isInitialized() const override;
56 
57  bool addInputConsumer(std::shared_ptr<Input::InputConsumerInterface> inputConsumer) override;
58  bool removeInputConsumer(std::shared_ptr<Input::InputConsumerInterface> inputConsumer) override;
59  void clearInputConsumers() override;
60  bool setOutputProducer(std::shared_ptr<Input::OutputProducerInterface> outputProducer) override;
61  bool removeOutputProducer(std::shared_ptr<Input::OutputProducerInterface> outputProducer) override;
62  bool hasOutputProducer() override;
63  void clearOutputProducer() override;
64 
67  void setDevice(std::shared_ptr<Input::DeviceInterface> device);
68 
73  void addFilter(std::shared_ptr<DeviceFilter> filter);
74 
76  const std::vector<std::shared_ptr<Input::DeviceInterface>>& getDevices() const;
77 
81  bool setDevices(const std::vector<std::shared_ptr<Input::DeviceInterface>>& devices);
82 
83 private:
84  bool finalize() override;
85 
87  void doFinalize();
88 
91 
94 
98  std::vector<std::shared_ptr<Input::DeviceInterface>> m_devices;
99 
101  boost::shared_mutex m_deviceMutex;
102 
104  std::shared_ptr<Framework::Logger> m_logger;
105 };
106 
107 }; // namespace Devices
108 }; // namespace SurgSim
109 
110 #endif // SURGSIM_DEVICES_DEVICEFILTERS_FILTEREDDEVICE_H
SurgSim::Devices::FilteredDevice::finalize
bool finalize() override
Finalize (de-initialize) the device.
Definition: FilteredDevice.cpp:101
SurgSim::Devices::FilteredDevice::clearOutputProducer
void clearOutputProducer() override
Removes any OutputProducer.
Definition: FilteredDevice.cpp:206
SurgSim::Devices::FilteredDevice::removeInputConsumer
bool removeInputConsumer(std::shared_ptr< Input::InputConsumerInterface > inputConsumer) override
Removes an input consumer previously added via addInputConsumer.
Definition: FilteredDevice.cpp:138
SurgSim::Devices::FilteredDevice::removeOutputProducer
bool removeOutputProducer(std::shared_ptr< Input::OutputProducerInterface > outputProducer) override
Removes an output producer previously added via setOutputProducer.
Definition: FilteredDevice.cpp:182
SurgSim::Devices::FilteredDevice::m_initialized
bool m_initialized
true if initialized and not finalized.
Definition: FilteredDevice.h:93
SurgSim::Devices::FilteredDevice::setDevice
void setDevice(std::shared_ptr< Input::DeviceInterface > device)
Sets the raw/base device.
Definition: FilteredDevice.cpp:216
SurgSim::Devices::FilteredDevice::addFilter
void addFilter(std::shared_ptr< DeviceFilter > filter)
Adds a DeviceFilter.
Definition: FilteredDevice.cpp:224
SurgSim::Devices::FilteredDevice::clearInputConsumers
void clearInputConsumers() override
Removes all InputConsumers.
Definition: FilteredDevice.cpp:155
SurgSim::Devices::FilteredDevice::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Devices::FilteredDevice)
SurgSim::Devices::FilteredDevice
A DeviceInterface connected in series with one or more DeviceFilters. Useful for serialization.
Definition: FilteredDevice.h:40
SurgSim::Devices::FilteredDevice::isInitialized
bool isInitialized() const override
Definition: FilteredDevice.cpp:96
SurgSim::Devices::FilteredDevice::~FilteredDevice
virtual ~FilteredDevice()
Destructor.
Definition: FilteredDevice.cpp:41
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Devices::FilteredDevice::m_devices
std::vector< std::shared_ptr< Input::DeviceInterface > > m_devices
The devices.
Definition: FilteredDevice.h:98
SurgSim::Devices::FilteredDevice::doFinalize
void doFinalize()
Implements the finalize functionality.
Definition: FilteredDevice.cpp:110
DeviceInterface.h
SurgSim::Devices::FilteredDevice::setOutputProducer
bool setOutputProducer(std::shared_ptr< Input::OutputProducerInterface > outputProducer) override
Sets an output producer that will be asked for application output state when the device needs it.
Definition: FilteredDevice.cpp:165
SurgSim::Devices::FilteredDevice::m_logger
std::shared_ptr< Framework::Logger > m_logger
The logger.
Definition: FilteredDevice.h:104
SurgSim::Input::DeviceInterface
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:42
SurgSim::Devices::FilteredDevice::getDevices
const std::vector< std::shared_ptr< Input::DeviceInterface > > & getDevices() const
Definition: FilteredDevice.cpp:232
SurgSim::Devices::FilteredDevice::hasOutputProducer
bool hasOutputProducer() override
Query if this object has output producer.
Definition: FilteredDevice.cpp:199
SurgSim::Devices::FilteredDevice::setDevices
bool setDevices(const std::vector< std::shared_ptr< Input::DeviceInterface >> &devices)
Sets the devices.
Definition: FilteredDevice.cpp:238
SurgSim::Devices::FilteredDevice::initialize
bool initialize() override
Fully initialize the device.
Definition: FilteredDevice.cpp:54
SurgSim::Devices::FilteredDevice::m_deviceMutex
boost::shared_mutex m_deviceMutex
The mutex to protect access to the devices.
Definition: FilteredDevice.h:101
SurgSim::Devices::FilteredDevice::getName
std::string getName() const override
Return a (hopefully unique) device name.
Definition: FilteredDevice.cpp:49
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Devices::FilteredDevice::m_name
std::string m_name
The name of this device.
Definition: FilteredDevice.h:90
SurgSim::Devices::FilteredDevice::addInputConsumer
bool addInputConsumer(std::shared_ptr< Input::InputConsumerInterface > inputConsumer) override
Adds an input consumer that will be notified when the application input state is updated.
Definition: FilteredDevice.cpp:121
SurgSim::Devices::FilteredDevice::FilteredDevice
FilteredDevice(const std::string &name)
Constructor.
Definition: FilteredDevice.cpp:33