StatechartListenerSegment.cpp
Go to the documentation of this file.
2 
3 #include <RobotAPI/libraries/armem_skills/aron/Statechart.aron.generated.h>
5 
7 {
9  Base(iceMemory, "StatechartListener", "Transitions", arondto::Statechart::Transition::ToAronType())
10  {
11  }
12 
14  {
15  // Statechart Logging
16  defs->optional(p.statechartCoreSegmentName, "StatechartCoreSegmentName", "Name of the core segment for statecharts.");
17  defs->optional(p.statechartTransitionsProviderSegmentName, "TransitionsProviderSegmentName", "Name of the provider segment for statechart transitions.");
18  defs->optional(p.statechartTransitionsTopicName, "tpc.sub.ProfilerListener", "Name of the ProfilerListenerInterface topics to subscribe.");
19 
20  this->setDefaultMaxHistorySize(10);
22  Base::defineProperties(defs, prefix);
23  }
24 
26  {
27  Base::init();
28  }
29 
30  void StatechartListenerProviderSegment::reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters& t)
31  {
32  const std::string& entityName = getStatechartName(t.targetStateIdentifier);
33  armem::Time transitionTime = armem::Time(armem::Duration::MicroSeconds(t.timestamp));
34 
36  update.entityID = segmentPtr->id().withEntityName(entityName);
37 
38  update.referencedTime = transitionTime;
39  skills::arondto::Statechart::Transition data;
40  armem::toAron(data, t);
41  update.instancesData.push_back(data.toAron());
42 
43  try
44  {
46  }
47  catch (const armem::error::ArMemError& e)
48  {
49  ARMARX_WARNING << e.what();
50  }
51  }
52 
53  void StatechartListenerProviderSegment::reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList& transitions)
54  {
55  for (const auto& t : transitions)
56  {
58  }
59  }
60 
61  std::string StatechartListenerProviderSegment::getStatechartName(std::string stateName)
62  {
63  const std::string delimiter = "->";
64  const int maxLevels = 2;
65 
66  size_t pos;
67  int levels = 0;
68  std::string statechartName;
69  while ((pos = stateName.find(delimiter)) != std::string::npos && levels < maxLevels)
70  {
71  if (levels != 0)
72  {
73  statechartName += delimiter;
74  }
75  statechartName += stateName.substr(0, pos);
76  stateName.erase(0, pos + delimiter.length());
77  levels++;
78  }
79 
80  return statechartName;
81  }
82 }
armarx::skills::segment::StatechartListenerProviderSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: StatechartListenerSegment.cpp:13
armarx::armem::server::segment::SpecializedProviderSegment::coreSegment
SpecializedCoreSegment coreSegment
Definition: SpecializedProviderSegment.h:55
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
armarx::armem::toAron
void toAron(arondto::MemoryID &dto, const MemoryID &bo)
Definition: aron_conversions.cpp:19
armarx::skills::segment::StatechartListenerProviderSegment::init
void init()
Definition: StatechartListenerSegment.cpp:25
armarx::armem::error::ArMemError
Base class for all exceptions thrown by the armem library.
Definition: ArMemError.h:18
armarx::armem::server::segment::SpecializedProviderSegment::setDefaultMaxHistorySize
void setDefaultMaxHistorySize(int64_t maxHistorySize)
Definition: SpecializedProviderSegment.cpp:85
armarx::skills::segment::StatechartListenerProviderSegment::reportStatechartTransitionWithParametersList
void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList &)
Definition: StatechartListenerSegment.cpp:53
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >::segmentPtr
server::wm::ProviderSegment * segmentPtr
Definition: SpecializedSegment.h:54
aron_conversions.h
armarx::skills::segment
Definition: ExecutableSkillLibrarySegment.cpp:13
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::Transition
Definition: Transition.h:36
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::armem::server::segment::SpecializedProviderSegment::init
virtual void init() override
Definition: SpecializedProviderSegment.cpp:56
armarx::skills::segment::StatechartListenerProviderSegment::reportStatechartTransitionWithParameters
void reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters &)
Definition: StatechartListenerSegment.cpp:30
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:420
armarx::armem::server::segment::SpecializedCoreSegment::setDefaultMaxHistorySize
void setDefaultMaxHistorySize(int64_t maxHistorySize)
Definition: SpecializedCoreSegment.cpp:75
IceUtil::Handle< class PropertyDefinitionContainer >
StatechartListenerSegment.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27
armarx::armem::base::ProviderSegmentBase::update
UpdateResult update(const EntityUpdate &update)
Updates an entity's history.
Definition: ProviderSegmentBase.h:252
armarx::skills::segment::StatechartListenerProviderSegment::StatechartListenerProviderSegment
StatechartListenerProviderSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: StatechartListenerSegment.cpp:8
armarx::armem::server::segment::SpecializedProviderSegment::defineProperties
virtual void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: SpecializedProviderSegment.cpp:40