InputComponent.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, 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_INPUTCOMPONENT_H
#define SURGSIM_INPUT_INPUTCOMPONENT_H
#include <atomic>
#include <memory>
#include <string>
#include "SurgSim/DataStructures/DataGroup.h"
#include "SurgSim/Framework/LockedContainer.h"
#include "SurgSim/Framework/Representation.h"
#include "SurgSim/Input/InputConsumerInterface.h"
namespace SurgSim
{
namespace Input
{
class DeviceInterface;
SURGSIM_STATIC_REGISTRATION(InputComponent);
class InputComponent : public SurgSim::Framework::Representation, public InputConsumerInterface
{
public:
explicit InputComponent(const std::string& name);
virtual ~InputComponent();
SURGSIM_CLASSNAME(SurgSim::Input::InputComponent);
void setDeviceName(const std::string& deviceName);
std::string getDeviceName() const;
void getData(SurgSim::DataStructures::DataGroup* dataGroup);
bool doInitialize() override;
bool doWakeUp() override;
void initializeInput(const std::string& device, const SurgSim::DataStructures::DataGroup& initialData) override;
void handleInput(const std::string& device, const SurgSim::DataStructures::DataGroup& inputData) override;
private:
std::string m_deviceName;
SurgSim::Framework::LockedContainer<SurgSim::DataStructures::DataGroup> m_lastInput;
std::atomic<bool> m_hasInput;
};
}; // namespace Input
}; // namespace SurgSim
#endif
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Input::InputComponent::getDeviceName
std::string getDeviceName() const
Gets device name.
Definition: InputComponent.cpp:44
DataGroup.h
SurgSim::Input::InputComponent::InputComponent
InputComponent(const std::string &name)
Constructor.
Definition: InputComponent.cpp:27
SurgSim::Input::InputComponent::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Input::InputComponent)
SurgSim::Input::InputComponent::initializeInput
void initializeInput(const std::string &device, const SurgSim::DataStructures::DataGroup &initialData) override
Set the initial input data group.
Definition: InputComponent.cpp:67
SurgSim::Input::InputComponent::m_hasInput
std::atomic< bool > m_hasInput
Definition: InputComponent.h:78
SurgSim::Input::InputComponent::getData
void getData(SurgSim::DataStructures::DataGroup *dataGroup)
Gets the input data.
Definition: InputComponent.cpp:49
LockedContainer.h
Representation.h
SurgSim::Input::InputComponent
InputComponents connect devices to SceneElements, facilitating data transfer from a device to SceneEl...
Definition: InputComponent.h:38
SurgSim::Input::InputComponent::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: InputComponent.cpp:57
SurgSim::Input::InputConsumerInterface
Interface for a consumer that monitors device and signal state updates (pose, buttons, etc).
Definition: InputConsumerInterface.h:33
SurgSim::Input::InputComponent::m_deviceName
std::string m_deviceName
Name of the device to which this input component connects.
Definition: InputComponent.h:73
InputConsumerInterface.h
SurgSim::Input::InputComponent::handleInput
void handleInput(const std::string &device, const SurgSim::DataStructures::DataGroup &inputData) override
Notifies the consumer that the application input coming from the device has been updated.
Definition: InputComponent.cpp:74
SurgSim::DataStructures::DataGroup
A collection of NamedData objects.
Definition: DataGroup.h:68
SurgSim::Framework::LockedContainer< SurgSim::DataStructures::DataGroup >
SurgSim::Framework::Representation
Representations are manifestations of a SceneElement.
Definition: Representation.h:33
SurgSim::Input::InputComponent::m_lastInput
SurgSim::Framework::LockedContainer< SurgSim::DataStructures::DataGroup > m_lastInput
Thread safe container of most recent input data.
Definition: InputComponent.h:76
SurgSim::Input::InputComponent::setDeviceName
void setDeviceName(const std::string &deviceName)
Set name of the device this input component connects to.
Definition: InputComponent.cpp:39
SurgSim::Input::InputComponent::~InputComponent
virtual ~InputComponent()
Destructor.
Definition: InputComponent.cpp:35
SurgSim::Input::InputComponent::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: InputComponent.cpp:62