RobotUnitDataStreamingReceiver.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::RobotUnitDataStreamingReceiver
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <mutex>
26 #include <type_traits>
27 
29 
30 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
31 
33 {
34  TYPEDEF_PTRS_HANDLE(Receiver);
35 }
36 namespace armarx
37 {
38  TYPEDEF_PTRS_SHARED(RobotUnitDataStreamingReceiver);
39  /**
40  * @defgroup Library-RobotUnitDataStreamingReceiver RobotUnitDataStreamingReceiver
41  * @ingroup RobotAPI
42  * A description of the library RobotUnitDataStreamingReceiver.
43  *
44  * @class RobotUnitDataStreamingReceiver
45  * @ingroup Library-RobotUnitDataStreamingReceiver
46  * @brief Brief description of class RobotUnitDataStreamingReceiver.
47  *
48  * Detailed description of class RobotUnitDataStreamingReceiver.
49  */
51  {
52  public:
53  using clock_t = std::chrono::high_resolution_clock;
54  using timestep_t = RobotUnitDataStreaming::TimeStep;
55  using entry_t = RobotUnitDataStreaming::DataEntry;
56 
57  template<class T>
59  {
60  DataEntryReader() = default;
61  DataEntryReader(DataEntryReader&&) = default;
62  DataEntryReader(const DataEntryReader&) = default;
64  DataEntryReader& operator=(const DataEntryReader&) = default;
65 
66  DataEntryReader(const RobotUnitDataStreaming::DataEntry& k);
67 
68  DataEntryReader& operator=(const RobotUnitDataStreaming::DataEntry& k);
69 
70  void set(const RobotUnitDataStreaming::DataEntry& k);
71  T get(const RobotUnitDataStreaming::TimeStep& t) const;
72  T operator()(const RobotUnitDataStreaming::TimeStep& t) const;
73  private:
74  RobotUnitDataStreaming::DataEntry _key;
75  };
76 
78  const ManagedIceObjectPtr& obj,
79  const RobotUnitInterfacePrx& ru,
80  const RobotUnitDataStreaming::Config& cfg);
82 
83  std::deque<timestep_t>& getDataBuffer();
84  const RobotUnitDataStreaming::DataStreamingDescription& getDataDescription() const;
85  std::string getDataDescriptionString() const;
86 
87  template<class T>
88  DataEntryReader<T> getDataEntryReader(const std::string& name) const;
89 
90  template<class T>
91  void getDataEntryReader(DataEntryReader<T>& e, const std::string& name) const;
92  //statics
93  static void VisitEntry(auto&& f, const timestep_t& st, const entry_t& e);
94  template<class T>
95  static T GetAs(const timestep_t& st, const entry_t& e);
96 
97  template<class T>
98  static RobotUnitDataStreaming::DataEntryType ExpectedDataEntryType();
99  static void VisitEntries(auto&& f, const timestep_t& st, const auto& cont);
100  private:
101  ManagedIceObjectPtr _obj;
103  detail::RobotUnitDataStreamingReceiver::ReceiverPtr _receiver;
104  RobotUnitDataStreaming::ReceiverPrx _proxy;
105  RobotUnitDataStreaming::DataStreamingDescription _description;
106  std::map<std::uint64_t, RobotUnitDataStreaming::TimeStepSeq> _tmp_data_buffer;
107  std::uint64_t _tmp_data_buffer_seq_id = 0;
108  std::deque<RobotUnitDataStreaming::TimeStep> _data_buffer;
109  long _last_iteration_id = -1;
110 
111  };
112 }
113 //impl
114 namespace armarx
115 {
116  template<class T> inline
118  {
119  set(k);
120  }
121 
122  template<class T> inline
123  void
124  RobotUnitDataStreamingReceiver::DataEntryReader<T>::set(const RobotUnitDataStreaming::DataEntry& k)
125  {
126  ARMARX_CHECK_EQUAL(RobotUnitDataStreamingReceiver::ExpectedDataEntryType<T>(),
127  k.type) << "the key references a value of the wrong type!";
128  _key = k;
129  }
130 
131  template<class T> inline
133  RobotUnitDataStreamingReceiver::DataEntryReader<T>::operator=(const RobotUnitDataStreaming::DataEntry& k)
134  {
135  set(k);
136  return *this;
137  }
138 
139  template<class T> inline
140  T
141  RobotUnitDataStreamingReceiver::DataEntryReader<T>::get(const RobotUnitDataStreaming::TimeStep& t) const
142  {
143  return RobotUnitDataStreamingReceiver::GetAs<T>(t, _key);
144  }
145 
146  template<class T> inline
147  T
148  RobotUnitDataStreamingReceiver::DataEntryReader<T>::operator()(const RobotUnitDataStreaming::TimeStep& t) const
149  {
150  return get(t);
151  }
152 
153  template<class T> inline
154  void
156  {
157  e = _description.entries.at(name);
158  }
159  template<class T> inline
162  {
165  return r;
166  }
167 
168  inline void
170  {
171  using enum_t = RobotUnitDataStreaming::DataEntryType;
172  // *INDENT-OFF*
173  switch (e.type)
174  {
175  case enum_t::NodeTypeBool : f(st.bools .at(e.index)); break;
176  case enum_t::NodeTypeByte : f(st.bytes .at(e.index)); break;
177  case enum_t::NodeTypeShort : f(st.shorts .at(e.index)); break;
178  case enum_t::NodeTypeInt : f(st.ints .at(e.index)); break;
179  case enum_t::NodeTypeLong : f(st.longs .at(e.index)); break;
180  case enum_t::NodeTypeFloat : f(st.floats .at(e.index)); break;
181  case enum_t::NodeTypeDouble: f(st.doubles.at(e.index)); break;
182  };
183  // *INDENT-ON*
184  }
185 
186  template<class T> inline
187  T
189  {
190  using enum_t = RobotUnitDataStreaming::DataEntryType;
191  if constexpr(std::is_same_v<bool, T>)
192  {
193  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeBool);
194  return st.bools .at(e.index);
195  }
196  else if constexpr(std::is_same_v<Ice::Byte, T>)
197  {
198  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeByte);
199  return st.bytes .at(e.index);
200  }
201  else if constexpr(std::is_same_v<Ice::Short, T>)
202  {
203  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeShort);
204  return st.shorts .at(e.index);
205  }
206  else if constexpr(std::is_same_v<Ice::Int, T>)
207  {
208  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeInt);
209  return st.ints .at(e.index);
210  }
211  else if constexpr(std::is_same_v<Ice::Long, T>)
212  {
213  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeLong);
214  return st.longs .at(e.index);
215  }
216  else if constexpr(std::is_same_v<Ice::Float, T>)
217  {
218  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeFloat);
219  return st.floats .at(e.index);
220  }
221  else if constexpr(std::is_same_v<Ice::Double, T>)
222  {
223  ARMARX_CHECK_EQUAL(e.type, enum_t::NodeTypeDouble);
224  return st.doubles.at(e.index);
225  }
226  else
227  {
228  static_assert(!std::is_same_v<T, T>, "Type not supported!");
229  }
230  }
231 
232  template<class T> inline
233  RobotUnitDataStreaming::DataEntryType
235  {
236  using enum_t = RobotUnitDataStreaming::DataEntryType;
237  if constexpr(std::is_same_v<bool, T>)
238  {
239  return enum_t::NodeTypeBool;
240  }
241  else if constexpr(std::is_same_v<Ice::Byte, T>)
242  {
243  return enum_t::NodeTypeByte;
244  }
245  else if constexpr(std::is_same_v<Ice::Short, T>)
246  {
247  return enum_t::NodeTypeShort;
248  }
249  else if constexpr(std::is_same_v<Ice::Int, T>)
250  {
251  return enum_t::NodeTypeInt;
252  }
253  else if constexpr(std::is_same_v<Ice::Long, T>)
254  {
255  return enum_t::NodeTypeLong;
256  }
257  else if constexpr(std::is_same_v<Ice::Float, T>)
258  {
259  return enum_t::NodeTypeFloat;
260  }
261  else if constexpr(std::is_same_v<Ice::Double, T>)
262  {
263  return enum_t::NodeTypeDouble;
264  }
265  else
266  {
267  static_assert(!std::is_same_v<T, T>, "Type not supported!");
268  }
269  }
270 
271  inline void
272  RobotUnitDataStreamingReceiver::VisitEntries(auto&& f, const timestep_t& st, const auto& cont)
273  {
274  for (const entry_t& e : cont)
275  {
276  VisitEntry(f, st, e);
277  }
278  }
279 }
armarx::RobotUnitDataStreamingReceiver::getDataDescription
const RobotUnitDataStreaming::DataStreamingDescription & getDataDescription() const
Definition: RobotUnitDataStreamingReceiver.cpp:202
armarx::detail::RobotUnitDataStreamingReceiver
Definition: RobotUnitDataStreamingReceiver.cpp:30
armarx::RobotUnitDataStreamingReceiver::DataEntryReader::operator()
T operator()(const RobotUnitDataStreaming::TimeStep &t) const
Definition: RobotUnitDataStreamingReceiver.h:148
armarx::RobotUnitDataStreamingReceiver::DataEntryReader::operator=
DataEntryReader & operator=(DataEntryReader &&)=default
armarx::RobotUnitDataStreamingReceiver::DataEntryReader
Definition: RobotUnitDataStreamingReceiver.h:58
armarx::RobotUnitDataStreamingReceiver::getDataEntryReader
DataEntryReader< T > getDataEntryReader(const std::string &name) const
Definition: RobotUnitDataStreamingReceiver.h:161
armarx::RobotUnitDataStreamingReceiver
Brief description of class RobotUnitDataStreamingReceiver.
Definition: RobotUnitDataStreamingReceiver.h:50
armarx::RobotUnitDataStreamingReceiver::ExpectedDataEntryType
static RobotUnitDataStreaming::DataEntryType ExpectedDataEntryType()
Definition: RobotUnitDataStreamingReceiver.h:234
armarx::RobotUnitDataStreamingReceiver::entry_t
RobotUnitDataStreaming::DataEntry entry_t
Definition: RobotUnitDataStreamingReceiver.h:55
armarx::RobotUnitDataStreamingReceiver::GetAs
static T GetAs(const timestep_t &st, const entry_t &e)
Definition: RobotUnitDataStreamingReceiver.h:188
armarx::TYPEDEF_PTRS_SHARED
TYPEDEF_PTRS_SHARED(ControlDevice)
IceInternal::Handle< ManagedIceObject >
ManagedIceObject.h
armarx::RobotUnitDataStreamingReceiver::clock_t
std::chrono::high_resolution_clock clock_t
Definition: RobotUnitDataStreamingReceiver.h:53
armarx::detail::RobotUnitDataStreamingReceiver::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(Receiver)
armarx::RobotUnitDataStreamingReceiver::RobotUnitDataStreamingReceiver
RobotUnitDataStreamingReceiver(const ManagedIceObjectPtr &obj, const RobotUnitInterfacePrx &ru, const RobotUnitDataStreaming::Config &cfg)
Definition: RobotUnitDataStreamingReceiver.cpp:91
armarx::RobotUnitDataStreamingReceiver::VisitEntries
static void VisitEntries(auto &&f, const timestep_t &st, const auto &cont)
Definition: RobotUnitDataStreamingReceiver.h:272
armarx::RobotUnitDataStreamingReceiver::VisitEntry
static void VisitEntry(auto &&f, const timestep_t &st, const entry_t &e)
Definition: RobotUnitDataStreamingReceiver.h:169
armarx::RobotUnitDataStreamingReceiver::DataEntryReader::get
T get(const RobotUnitDataStreaming::TimeStep &t) const
Definition: RobotUnitDataStreamingReceiver.h:141
armarx::RobotUnitDataStreamingReceiver::~RobotUnitDataStreamingReceiver
~RobotUnitDataStreamingReceiver()
Definition: RobotUnitDataStreamingReceiver.cpp:111
set
set(LIBS ArmarXCoreInterfaces ${CMAKE_THREAD_LIBS_INIT} ${dl_LIBRARIES} ${rt_LIBRARIES} ${QT_LIBRARIES} ${Boost_LIBRARIES} BoostAssertionHandler ArmarXCPPUtility SimoxUtility) set(LIB_FILES ArmarXManager.cpp ArmarXMultipleObjectsScheduler.cpp ArmarXObjectScheduler.cpp ManagedIceObject.cpp ManagedIceObjectPlugin.cpp Component.cpp ComponentPlugin.cpp IceGridAdmin.cpp ArmarXObjectObserver.cpp IceManager.cpp PackagePath.cpp RemoteReferenceCount.cpp logging/LoggingUtil.cpp logging/Logging.cpp logging/LogSender.cpp logging/ArmarXLogBuf.cpp system/ArmarXDataPath.cpp system/DynamicLibrary.cpp system/ProcessWatcher.cpp system/FactoryCollectionBase.cpp system/cmake/CMakePackageFinder.cpp system/cmake/CMakePackageFinderCache.cpp system/cmake/ArmarXPackageToolInterface.cpp system/RemoteObjectNode.cpp services/sharedmemory/HardwareId.cpp services/tasks/RunningTask.cpp services/tasks/ThreadList.cpp services/tasks/ThreadPool.cpp services/profiler/Profiler.cpp services/profiler/FileLoggingStrategy.cpp services/profiler/IceLoggingStrategy.cpp application/Application.cpp application/ApplicationOptions.cpp application/ApplicationProcessFacet.cpp application/ApplicationNetworkStats.cpp application/properties/PropertyUser.cpp application/properties/Property.cpp application/properties/PropertyDefinition.cpp application/properties/PropertyDefinitionContainer.cpp application/properties/PropertyDefinitionHelpFormatter.cpp application/properties/PropertyDefinitionConfigFormatter.cpp application/properties/PropertyDefinitionBriefHelpFormatter.cpp application/properties/PropertyDefinitionXmlFormatter.cpp application/properties/PropertyDefinitionDoxygenFormatter.cpp application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.cpp application/properties/PropertyDefinitionContainerBriefHelpFormatter.cpp application/properties/IceProperties.cpp exceptions/Exception.cpp exceptions/local/UnexpectedEnumValueException.cpp util/FileSystemPathBuilder.cpp util/StringHelpers.cpp util/IceReportSkipper.cpp util/Throttler.cpp util/distributed/AMDCallbackCollection.cpp util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.cpp util/distributed/RemoteHandle/RemoteHandle.cpp util/distributed/RemoteHandle/RemoteHandleControlBlock.cpp time/ice_conversions.cpp time/json_conversions.cpp time/CallbackWaitLock.cpp time/Clock.cpp time/ClockType.cpp time/ClockTypeNames.cpp time/CycleUtil.cpp time/DateTime.cpp time/Duration.cpp time/Frequency.cpp time/LocalTimeServer.cpp time/Metronome.cpp time/ScopedStopWatch.cpp time/StopWatch.cpp time/Timer.cpp time/TimeKeeper.cpp time/TimeUtil.cpp csv/CsvWriter.cpp csv/CsvReader.cpp eigen/conversions.cpp eigen/ice_conversions.cpp) set(LIB_HEADERS ArmarXManager.h ArmarXDummyManager.h ArmarXMultipleObjectsScheduler.h ArmarXObjectObserver.h ArmarXObjectScheduler.h ArmarXFwd.h Component.h ComponentPlugin.h ComponentFactories.h CoreObjectFactories.h IceGridAdmin.h IceManager.h IceManagerImpl.h json_conversions.h ManagedIceObject.h ManagedIceObjectPlugin.h ManagedIceObjectImpl.h ManagedIceObjectDependency.h ManagedIceObjectRegistryInterface.h PackagePath.h RemoteReferenceCount.h system/ImportExport.h system/ImportExportComponent.h system/AbstractFactoryMethod.h system/FactoryCollectionBase.h system/Synchronization.h system/ArmarXDataPath.h system/DynamicLibrary.h system/ProcessWatcher.h system/ConditionSynchronization.h system/cmake/CMakePackageFinder.h system/cmake/CMakePackageFinderCache.h system/cmake/FindPackageX.cmake system/cmake/ArmarXPackageToolInterface.h system/RemoteObjectNode.h logging/LoggingUtil.h logging/LogSender.h logging/Logging.h logging/ArmarXLogBuf.h logging/SpamFilterData.h services/tasks/RunningTask.h services/tasks/PeriodicTask.h services/tasks/ThreadList.h services/tasks/TaskUtil.h services/tasks/ThreadPool.h services/sharedmemory/SharedMemoryProvider.h services/sharedmemory/SharedMemoryConsumer.h services/sharedmemory/IceSharedMemoryProvider.h services/sharedmemory/IceSharedMemoryConsumer.h services/sharedmemory/HardwareIdentifierProvider.h services/sharedmemory/HardwareId.h services/sharedmemory/exceptions/SharedMemoryExceptions.h services/profiler/Profiler.h services/profiler/LoggingStrategy.h services/profiler/FileLoggingStrategy.h services/profiler/IceLoggingStrategy.h application/Application.h application/ApplicationOptions.h application/ApplicationProcessFacet.h application/ApplicationNetworkStats.h application/properties/forward_declarations.h application/properties/Properties.h application/properties/Property.h application/properties/PluginEigen.h application/properties/PluginEnumNames.h application/properties/PluginCfgStruct.h application/properties/PluginAll.h application/properties/PropertyUser.h application/properties/PropertyDefinition.h application/properties/PropertyDefinition.hpp application/properties/PropertyDefinitionInterface.h application/properties/PropertyDefinitionContainer.h application/properties/PropertyDefinitionFormatter.h application/properties/PropertyDefinitionContainerFormatter.h application/properties/PropertyDefinitionConfigFormatter.h application/properties/PropertyDefinitionHelpFormatter.h application/properties/PropertyDefinitionBriefHelpFormatter.h application/properties/PropertyDefinitionXmlFormatter.h application/properties/PropertyDefinitionDoxygenFormatter.h application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.h application/properties/PropertyDefinitionContainerBriefHelpFormatter.h application/properties/ProxyPropertyDefinition.h application/properties/IceProperties.h exceptions/Exception.h exceptions/LocalException.h exceptions/local/DynamicLibraryException.h exceptions/local/ExpressionException.h exceptions/local/FileIOException.h exceptions/local/InvalidPropertyValueException.h exceptions/local/MissingRequiredPropertyException.h exceptions/local/PropertyInheritanceCycleException.h exceptions/local/ProxyNotInitializedException.h exceptions/local/UnexpectedEnumValueException.h exceptions/local/UnmappedValueException.h exceptions/local/ValueRangeExceededException.h exceptions/user/NotImplementedYetException.h rapidxml/rapidxml.hpp rapidxml/rapidxml_print.hpp rapidxml/rapidxml_iterators.hpp rapidxml/rapidxml_utils.hpp rapidxml/wrapper/RapidXmlReader.h rapidxml/wrapper/RapidXmlWriter.h rapidxml/wrapper/DefaultRapidXmlReader.h rapidxml/wrapper/MultiNodeRapidXMLReader.h util/IceBlobToObject.h util/ObjectToIceBlob.h util/FileSystemPathBuilder.h util/FiniteStateMachine.h util/StringHelpers.h util/StringHelperTemplates.h util/algorithm.h util/OnScopeExit.h util/Predicates.h util/Preprocessor.h util/PropagateConst.h util/Registrar.h util/TemplateMetaProgramming.h util/TripleBuffer.h util/IceReportSkipper.h util/Throttler.h util/distributed/AMDCallbackCollection.h util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h util/distributed/RemoteHandle/RemoteHandle.h util/distributed/RemoteHandle/RemoteHandleControlBlock.h util/SimpleStatemachine.h time.h time_minimal.h time/forward_declarations.h time/ice_conversions.h time/json_conversions.h time/CallbackWaitLock.h time/Clock.h time/ClockType.h time/ClockTypeNames.h time/CycleUtil.h time/DateTime.h time/Duration.h time/Frequency.h time/LocalTimeServer.h time/Metronome.h time/ScopedStopWatch.h time/StopWatch.h time/Timer.h time/TimeUtil.h time/TimeKeeper.h csv/CsvWriter.h csv/CsvReader.h eigen/conversions.h eigen/ice_conversions.h ice_conversions.h ice_conversions/ice_conversions_boost_templates.h ice_conversions/ice_conversions_templates.h ice_conversions/ice_conversions_templates.tpp $
Definition: CMakeLists.txt:12
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx::RobotUnitDataStreamingReceiver::getDataDescriptionString
std::string getDataDescriptionString() const
Definition: RobotUnitDataStreamingReceiver.cpp:208
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::RobotUnitDataStreamingReceiver::DataEntryReader::set
void set(const RobotUnitDataStreaming::DataEntry &k)
Definition: RobotUnitDataStreamingReceiver.h:124
armarx::RobotUnitDataStreamingReceiver::timestep_t
RobotUnitDataStreaming::TimeStep timestep_t
Definition: RobotUnitDataStreamingReceiver.h:54
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotUnitDataStreamingReceiver::getDataBuffer
std::deque< timestep_t > & getDataBuffer()
Definition: RobotUnitDataStreamingReceiver.cpp:141
armarx::RobotUnitDataStreamingReceiver::DataEntryReader::DataEntryReader
DataEntryReader()=default