CommonDevice.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2015, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_INPUT_COMMONDEVICE_H
#define SURGSIM_INPUT_COMMONDEVICE_H
#include <memory>
#include <string>
#include "SurgSim/Input/DeviceInterface.h"
#include "SurgSim/DataStructures/DataGroup.h"
namespace SurgSim
{
namespace Input
{
class InputConsumerInterface;
class OutputProducerInterface;
class CommonDevice : public DeviceInterface
{
public:
explicit CommonDevice(const std::string& name);
CommonDevice(const std::string& name, const DataStructures::DataGroup& inputData);
CommonDevice(const std::string& name, DataStructures::DataGroup&& inputData);
virtual ~CommonDevice();
std::string getName() const override;
std::string getClassName() const override;
void setNameForCallback(const std::string& name);
std::string getNameForCallback() const;
bool addInputConsumer(std::shared_ptr<InputConsumerInterface> inputConsumer) override;
bool removeInputConsumer(std::shared_ptr<InputConsumerInterface> inputConsumer) override;
void clearInputConsumers() override;
bool setOutputProducer(std::shared_ptr<OutputProducerInterface> outputProducer) override;
bool removeOutputProducer(std::shared_ptr<OutputProducerInterface> outputProducer) override;
bool hasOutputProducer() override;
void clearOutputProducer() override;
protected:
virtual void pushInput();
virtual bool pullOutput();
DataStructures::DataGroup& getInputData();
const DataStructures::DataGroup& getOutputData() const;
private:
struct State;
const std::string m_name;
std::string m_nameForCallback;
DataStructures::DataGroup m_inputData;
DataStructures::DataGroup m_outputData;
std::vector<std::weak_ptr<InputConsumerInterface>> m_inputConsumerList;
std::weak_ptr<OutputProducerInterface> m_outputProducer;
boost::mutex m_consumerProducerMutex;
};
}; // namespace Input
}; // namespace SurgSim
#endif // SURGSIM_INPUT_COMMONDEVICE_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Input::CommonDevice::~CommonDevice
virtual ~CommonDevice()
Destructor.
Definition: CommonDevice.cpp:53
DataGroup.h
SurgSim::Input::CommonDevice::pullOutput
virtual bool pullOutput()
Pull application output from a producer.
Definition: CommonDevice.cpp:191
SurgSim::Input::CommonDevice::hasOutputProducer
bool hasOutputProducer() override
Query if this object has output producer.
Definition: CommonDevice.cpp:171
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::m_inputData
DataStructures::DataGroup m_inputData
The data the device is providing to its input consumers.
Definition: CommonDevice.h:119
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::getName
std::string getName() const override
Return a (hopefully unique) device name.
Definition: CommonDevice.cpp:59
SurgSim::Input::CommonDevice::m_nameForCallback
std::string m_nameForCallback
The name used for the callbacks, defaults to the device name.
Definition: CommonDevice.h:116
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::clearOutputProducer
void clearOutputProducer() override
Removes any OutputProducer.
Definition: CommonDevice.cpp:164
SurgSim::Input::CommonDevice::getClassName
std::string getClassName() const override
The class name for this class.
Definition: CommonDevice.cpp:64
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::DataStructures::DataGroup
A collection of NamedData objects.
Definition: DataGroup.h:68
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::getInputData
DataStructures::DataGroup & getInputData()
Getter for the input data DataGroup.
Definition: CommonDevice.cpp:214
SurgSim::Input::CommonDevice::clearInputConsumers
void clearInputConsumers() override
Removes all InputConsumers.
Definition: CommonDevice.cpp:126
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
SurgSim::Input::CommonDevice::getOutputData
const DataStructures::DataGroup & getOutputData() const
Getter for the output data DataGroup.
Definition: CommonDevice.cpp:219
SurgSim::Input::CommonDevice
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:35
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::DeviceInterface
Interface used to communicate with user-interface hardware devices.
Definition: DeviceInterface.h:41
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::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::m_name
const std::string m_name
Definition: CommonDevice.h:111
SurgSim::Input::CommonDevice::CommonDevice
CommonDevice(const std::string &name)
Constructor.
Definition: CommonDevice.cpp:32
SurgSim::Input::CommonDevice::pushInput
virtual void pushInput()
Push application input to consumers.
Definition: CommonDevice.cpp:176
SurgSim::Input::CommonDevice::m_outputProducer
std::weak_ptr< OutputProducerInterface > m_outputProducer
The output producer, if any.
Definition: CommonDevice.h:128
DeviceInterface.h