SkillsMemory.cpp
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::SkillsMemory
17  * @author Rainer Kartmann ( rainer dot kartmann 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 #include "SkillsMemory.h"
24 
25 #include <SimoxUtility/algorithm/string.h>
26 
32 
38 
39 namespace armarx
40 {
41 
43  ReadWritePluginUser(),
46  statechartListenerProviderSegment(iceAdapter()),
47  executableSkillCoreSegment(iceAdapter()),
48  skillEventCoreSegment(iceAdapter()),
49  skillExecutionRequestCoreSegment(iceAdapter())
50  {
51  }
52 
55  {
58 
59  const std::string prefix = "mem.";
60  statechartListenerProviderSegment.defineProperties(defs, prefix + "statechartlistener.");
61  executableSkillCoreSegment.defineProperties(defs, prefix + "executableskill.");
62  skillExecutionRequestCoreSegment.defineProperties(defs, prefix + "executionrequest.");
63  skillEventCoreSegment.defineProperties(defs, prefix + "event.");
64 
65  setMemoryName(MemoryName);
66  return defs;
67  }
68 
69  std::string
71  {
72  return "SkillMemory";
73  }
74 
75  void
77  {
78  statechartListenerProviderSegment.init();
79  executableSkillCoreSegment.init();
80  skillExecutionRequestCoreSegment.init();
81  skillEventCoreSegment.init();
82  }
83 
84  void
86  {
87  }
88 
89  void
91  {
92  }
93 
94  void
96  {
97  }
98 
99  armem::data::CommitResult
100  SkillsMemory::commit(const armem::data::Commit& commit, const Ice::Current& current)
101  {
102  // This function is overloaded to check for skill executions
103  // First pass arg to parent func to ensure that data is written into memory and that clients are notified
104  armem::data::CommitResult result = ReadWritePluginUser::commit(commit);
105 
106  skills::callback::dti::SkillProviderCallbackInterfacePrx myPrx;
107  getProxy(myPrx, -1);
108 
109  for (const auto& up : commit.updates)
110  {
111  if (up.entityID.coreSegmentName ==
113  {
114  for (const auto& instance : up.instancesData)
115  {
116  ARMARX_CHECK_NOT_NULL(instance);
117 
119  skillExecutionRequestCoreSegment.convertCommit(instance);
121  }
122  }
123  }
124 
125  return result;
126  }
127 
128  void
129  SkillsMemory::addProvider(const skills::manager::dto::ProviderInfo& info,
130  const Ice::Current& current)
131  {
132  ARMARX_INFO << "Adding provider to skill memory: " << info.providerId.providerName;
134 
135  // log skills to memory
136  auto p = skills::ProviderInfo::FromIce(info);
137  executableSkillCoreSegment.addSkillProvider(p);
138  }
139 
140  void
141  SkillsMemory::removeProvider(const skills::manager::dto::ProviderID& provider,
142  const Ice::Current& current)
143  {
144  executableSkillCoreSegment.removeSkillProvider(provider.providerName);
145 
146  // remove skills from memory
148  }
149 
150  skills::manager::dto::SkillStatusUpdate
151  SkillsMemory::executeSkill(const skills::manager::dto::SkillExecutionRequest& info,
152  const Ice::Current& current)
153  {
155  skillExecutionRequestCoreSegment.addSkillExecutionRequest(e);
156 
157  return SkillManagerComponentPluginUser::executeSkill(info, current);
158  }
159 
160  skills::manager::dto::SkillExecutionID
161  SkillsMemory::executeSkillAsync(const skills::manager::dto::SkillExecutionRequest& info,
162  const Ice::Current& current)
163  {
165  skillExecutionRequestCoreSegment.addSkillExecutionRequest(e);
166 
168  }
169 
170  void
171  SkillsMemory::updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate& update,
172  const skills::callback::dto::ProviderID& providerId,
173  const Ice::Current& current)
174  {
175  auto p = skills::ProviderID::FromIce(providerId);
177  skillEventCoreSegment.addSkillUpdateEvent(u);
178  }
179 
180  IceUtil::Optional<skills::manager::dto::SkillStatusUpdate>
181  SkillsMemory::getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID& executionId,
182  const Ice::Current& current)
183  {
184  auto eid = skills::SkillExecutionID::FromIce(executionId);
185  auto op = this->skillEventCoreSegment.getSkillStatusUpdate(eid);
186  if (op.has_value())
187  {
188  return op->toManagerIce();
189  }
190  return {};
191  }
192 
193  skills::manager::dto::SkillStatusUpdateMap
194  SkillsMemory::getSkillExecutionStatuses(const Ice::Current& current)
195  {
196  skills::manager::dto::SkillStatusUpdateMap ret;
197  auto updates = this->skillEventCoreSegment.getSkillStatusUpdates();
198  for (const auto& [k, v] : updates)
199  {
200  ret.insert({k.toManagerIce(), v.toManagerIce()});
201  }
202  return ret;
203  }
204 
205  /*
206  * Statechart stuff
207  */
208  void
210  const ProfilerStatechartTransitionWithParameters& x,
211  const Ice::Current&)
212  {
213  statechartListenerProviderSegment.reportStatechartTransitionWithParameters(x);
214  }
215 
216  void
218  const ProfilerStatechartTransitionWithParametersList& x,
219  const Ice::Current&)
220  {
221  statechartListenerProviderSegment.reportStatechartTransitionWithParametersList(x);
222  }
223 } // namespace armarx
armarx::skills::segment::StatechartListenerProviderSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: StatechartListenerSegment.cpp:13
armarx::SkillsMemory::removeProvider
void removeProvider(const skills::manager::dto::ProviderID &provider, const Ice::Current &current) override
Definition: SkillsMemory.cpp:141
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::SkillsMemory::onExitComponent
void onExitComponent() override
Definition: SkillsMemory.cpp:95
armarx::SkillsMemory::addProvider
void addProvider(const skills::manager::dto::ProviderInfo &info, const Ice::Current &current) override
Definition: SkillsMemory.cpp:129
armarx::skills::SkillStatusUpdate::FromIce
static SkillStatusUpdate FromIce(const provider::dto::SkillStatusUpdate &update, const std::optional< skills::ProviderID > &providerId=std::nullopt)
Definition: SkillStatusUpdate.cpp:367
armarx::SkillsMemory::getSkillExecutionStatus
IceUtil::Optional< skills::manager::dto::SkillStatusUpdate > getSkillExecutionStatus(const skills::manager::dto::SkillExecutionID &executionId, const Ice::Current &current) override
Definition: SkillsMemory.cpp:181
armarx::SkillManagerComponentPluginUser::executeSkill
skills::manager::dto::SkillStatusUpdate executeSkill(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
Definition: SkillManagerComponentPlugin.cpp:609
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::init
void init()
Definition: ExecutableSkillLibrarySegment.cpp:30
ArmarXManager.h
armarx::SkillsMemory::onDisconnectComponent
void onDisconnectComponent() override
Definition: SkillsMemory.cpp:90
armarx::SkillsMemory::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SkillsMemory.cpp:54
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::removeSkillProvider
void removeSkillProvider(const std::string &providerName)
Definition: ExecutableSkillLibrarySegment.cpp:62
armarx::skills::segment::SkillExecutionRequestCoreSegment::convertCommit
skills::SkillExecutionRequest convertCommit(const aron::data::dto::DictPtr &commitData)
Definition: SkillExecutionRequestSegment.cpp:34
armarx::skills::SkillExecutionRequest::FromIce
static SkillExecutionRequest FromIce(const manager::dto::SkillExecutionRequest &)
Definition: SkillExecutionRequest.cpp:29
armarx::SkillsMemory::getDefaultName
std::string getDefaultName() const override
Definition: SkillsMemory.cpp:70
armarx::SkillsMemory::onConnectComponent
void onConnectComponent() override
Definition: SkillsMemory.cpp:85
armarx::armem::server::plugins::ReadWritePluginUser::setMemoryName
void setMemoryName(const std::string &memoryName)
Definition: ReadWritePluginUser.cpp:25
armarx::skills::segment::SkillEventCoreSegment::init
void init()
Definition: SkillEventSegment.cpp:28
armarx::skills::ProviderInfo::FromIce
static ProviderInfo FromIce(const manager::dto::ProviderInfo &)
Definition: ProviderInfo.cpp:22
armarx::skills::segment::StatechartListenerProviderSegment::init
void init()
Definition: StatechartListenerSegment.cpp:25
armarx::SkillsMemory::reportStatechartTransitionWithParametersList
void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList &, const Ice::Current &) override
Definition: SkillsMemory.cpp:217
armarx::SkillsMemory::commit
armem::data::CommitResult commit(const armem::data::Commit &commit, const Ice::Current &) override
Definition: SkillsMemory.cpp:100
armarx::SkillManagerComponentPluginUser::executeSkillAsync
skills::manager::dto::SkillExecutionID executeSkillAsync(const skills::manager::dto::SkillExecutionRequest &skillExecutionRequest, const Ice::Current &current) override
Definition: SkillManagerComponentPlugin.cpp:618
armarx::skills::segment::SkillExecutionRequestCoreSegment::init
void init()
Definition: SkillExecutionRequestSegment.cpp:28
armarx::skills::segment::SkillExecutionRequestCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: SkillExecutionRequestSegment.cpp:20
armarx::skills::SkillExecutionRequest
Definition: SkillExecutionRequest.h:21
armarx::skills::segment::StatechartListenerProviderSegment::reportStatechartTransitionWithParametersList
void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList &)
Definition: StatechartListenerSegment.cpp:53
memory_definitions.h
armarx::SkillsMemory::reportStatechartTransitionWithParameters
void reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters &, const Ice::Current &) override
Definition: SkillsMemory.cpp:209
armarx::SkillsMemory::updateStatusForSkill
void updateStatusForSkill(const skills::provider::dto::SkillStatusUpdate &update, const skills::callback::dto::ProviderID &id, const Ice::Current &current) override
Definition: SkillsMemory.cpp:171
SkillsMemory.h
aron_conversions.h
armarx::skills::segment::SkillExecutionRequestCoreSegment::CoreSegmentName
static constexpr const char * CoreSegmentName
Definition: SkillExecutionRequestSegment.h:22
error.h
armarx::SkillsMemory::executeSkillAsync
skills::manager::dto::SkillExecutionID executeSkillAsync(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
Definition: SkillsMemory.cpp:161
armarx::SkillsMemory::SkillsMemory
SkillsMemory()
Definition: SkillsMemory.cpp:42
ArmarXObjectScheduler.h
armarx::SkillManagerComponentPluginUser
Definition: SkillManagerComponentPlugin.h:82
armarx::SkillManagerComponentPluginUser::removeProvider
void removeProvider(const skills::manager::dto::ProviderID &provider, const Ice::Current &current) override
Definition: SkillManagerComponentPlugin.cpp:600
armarx::SkillsMemory::onInitComponent
void onInitComponent() override
Definition: SkillsMemory.cpp:76
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::skills::SkillExecutionRequest::toManagerIce
manager::dto::SkillExecutionRequest toManagerIce() const
Definition: SkillExecutionRequest.cpp:8
MemoryToIceAdapter.h
memory_definitions.h
ExpressionException.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdates
std::map< skills::SkillExecutionID, skills::SkillStatusUpdate > getSkillStatusUpdates()
Definition: SkillEventSegment.cpp:57
armarx::SkillManagerComponentPluginUser::addProvider
void addProvider(const skills::manager::dto::ProviderInfo &providerInfo, const Ice::Current &current) override
Definition: SkillManagerComponentPlugin.cpp:592
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::skills::segment::SkillEventCoreSegment::addSkillUpdateEvent
void addSkillUpdateEvent(const skills::SkillStatusUpdate &update)
Definition: SkillEventSegment.cpp:34
armarx::skills::SkillExecutionID::FromIce
static SkillExecutionID FromIce(const skills::manager::dto::SkillExecutionID &)
Definition: SkillExecutionID.cpp:29
armarx::StatechartListenerComponentPluginUser
Definition: StatechartListenerComponentPlugin.h:26
armarx::SkillsMemory::getSkillExecutionStatuses
skills::manager::dto::SkillStatusUpdateMap getSkillExecutionStatuses(const Ice::Current &current) override
Definition: SkillsMemory.cpp:194
Logging.h
armarx::ManagedIceObject::getProxy
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Definition: ManagedIceObject.cpp:393
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: ExecutableSkillLibrarySegment.cpp:22
armarx::SkillsMemory::executeSkill
skills::manager::dto::SkillStatusUpdate executeSkill(const skills::manager::dto::SkillExecutionRequest &info, const Ice::Current &current) override
Definition: SkillsMemory.cpp:151
armarx::skills::segment::SkillEventCoreSegment::defineProperties
void defineProperties(PropertyDefinitionsPtr defs, const std::string &prefix)
Definition: SkillEventSegment.cpp:21
armarx::skills::segment::SkillEventCoreSegment::getSkillStatusUpdate
std::optional< skills::SkillStatusUpdate > getSkillStatusUpdate(const skills::SkillExecutionID &id)
Definition: SkillEventSegment.cpp:90
armarx::skills::segment::SkillExecutionRequestCoreSegment::addSkillExecutionRequest
void addSkillExecutionRequest(const skills::SkillExecutionRequest &info)
Definition: SkillExecutionRequestSegment.cpp:51
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::skills::ProviderID::FromIce
static ProviderID FromIce(const manager::dto::ProviderID &)
Definition: ProviderID.cpp:32
armarx::skills::segment::ExecutableSkillLibraryCoreSegment::addSkillProvider
void addSkillProvider(const skills::ProviderInfo &info)
Definition: ExecutableSkillLibrarySegment.cpp:36