opensurgsim
TestDevice.h
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_UNITTESTS_TESTDEVICE_H
17 #define SURGSIM_INPUT_UNITTESTS_TESTDEVICE_H
18 
19 #include "SurgSim/Input/CommonDevice.h"
20 #include "SurgSim/Input/InputConsumerInterface.h"
21 #include "SurgSim/Input/OutputProducerInterface.h"
22 #include "SurgSim/DataStructures/DataGroup.h"
23 #include "SurgSim/DataStructures/DataGroupBuilder.h"
24 
30 
31 
32 class TestDevice : public CommonDevice
33 {
34 public:
35  explicit TestDevice(const std::string& uniqueName);
36 
37  bool initialize() override;
38 
39  bool isInitialized() const override;
40 
41  void pushInput() override;
42 
43  // Send some data down the stream
44  void pushInput(const std::string& data);
45 
46  bool pullOutput() override;
47 
48  const DataGroup& getOutputData() const;
49 
51  static DataGroup buildInputData();
52  DataGroup buildOutputData();
53 
54  std::string lastPulledData;
55 
58 
59 private:
60  bool finalize() override;
61 };
62 
63 
65 {
66 public:
68  m_numTimesReceivedInput(0)
69  {
70  }
71 
72  virtual void initializeInput(const std::string& device, const DataGroup& initialInput)
73  {
74  }
75  virtual void handleInput(const std::string& device, const DataGroup& inputData);
76 
77  int m_numTimesReceivedInput;
78  DataGroup m_lastReceivedInput;
79 };
80 
82 {
83 public:
85  m_numTimesRequestedOutput(0),
86  m_refuseToProduce(false)
87  {
88  DataGroupBuilder builder;
89  builder.addInteger("value");
90  m_nextSentOutput = builder.createData();
91  m_nextSentOutput.integers().set("value", 123);
92  }
93 
94  virtual bool requestOutput(const std::string& device, DataGroup* outputData);
95 
96  int m_numTimesRequestedOutput;
97  bool m_refuseToProduce;
98  DataGroup m_nextSentOutput;
99 };
100 
101 #endif // SURGSIM_INPUT_UNITTESTS_TESTDEVICE_H
void pushInput() override
Push application input to consumers.
Definition: TestDevice.cpp:46
Definition: TestDevice.h:81
Interface for a producer that generates device output updates (forces, status LED state...
Definition: OutputProducerInterface.h:33
void addInteger(const std::string &name)
A shortcut for adding a named integer entry.
Definition: DataGroupBuilder.cpp:158
Definition: TestDevice.h:64
NamedData< IntegerType > & integers()
Return the integer data structure.
Definition: DataGroup.cpp:111
bool pullOutput() override
Pull application output from a producer.
Definition: TestDevice.cpp:58
bool set(int index, const T &value)
Record the data for an entry specified by an index.
Definition: NamedData-inl.h:220
DataGroup createData() const
Produces a DataGroup object with an immutable set of names and indices.
Definition: DataGroupBuilder.cpp:28
Interface for a consumer that monitors device and signal state updates (pose, buttons, etc).
Definition: InputConsumerInterface.h:33
A collection of NamedData objects.
Definition: DataGroup.h:68
A class that implements some common management code on top of the DeviceInterface.
Definition: CommonDevice.h:35
bool initialize() override
Fully initialize the device.
Definition: TestDevice.cpp:25
Definition: TestDevice.h:32
bool m_initialized
true if initialized and not finalized.
Definition: TestDevice.h:57
A class that allows you to build a DataGroup structure.
Definition: DataGroupBuilder.h:38
bool isInitialized() const override
Definition: TestDevice.cpp:40
static DataGroup buildInputData()
Builds the data layout for the application input (i.e. device output).
Definition: TestDevice.cpp:71
virtual void initializeInput(const std::string &device, const DataGroup &initialInput)
Set the initial input data group.
Definition: TestDevice.h:72