RequestObjects.cpp
Go to the documentation of this file.
1 #include "RequestObjects.h"
2 
3 //#include <ArmarXCore/core/time/TimeUtil.h>
4 //#include <ArmarXCore/observers/variant/DatafieldRef.h>
5 
9 
10 #include "ObjectMemoryGroupStatechartContext.generated.h"
11 
13 {
14  // DO NOT EDIT NEXT LINE
15  RequestObjects::SubClassRegistry RequestObjects::Registry(RequestObjects::GetName(),
17 
19  XMLStateTemplate<RequestObjects>(stateData),
20  RequestObjectsGeneratedBase<RequestObjects>(stateData)
21  {
22  }
23 
24  void
26  {
27 
28  // put your user code for the enter-point here
29  // execution time should be short (<100ms)
30  }
31 
32  void
34  {
35  if (not in.getEnable())
36  {
37  emitSuccess();
38  return;
39  }
40 
42 
43  const std::string provider = in.isProviderSet() ? in.getProvider() : "";
44 
45  const std::vector<std::string> objectIdsString = in.getObjectIds();
46  const armarx::Duration relativeTimeout =
47  armarx::Duration::MilliSeconds(in.getRelativeTimeoutMilliseconds());
48 
49  std::stringstream info;
50  std::stringstream warn;
51 
52  std::vector<armarx::ObjectID> objectIds;
53  for (const std::string& idString : objectIdsString)
54  {
55  try
56  {
58  objectIds.push_back(id);
59  info << "Requesting object " << id << "\n";
60  }
61  catch (const armarx::LocalException& e)
62  {
63  warn << "\nGiven object ID '" << idString
64  << "' could not parsed as ObjectID: " << e.what();
65  }
66  }
67 
68  auto context = getContext<ObjectMemoryGroupStatechartContext>();
69  armarx::armem::client::MemoryNameSystem mns(getMemoryNameSystem(), context);
70 
71  Reader reader;
72  reader.connect(mns);
73  objpose::ObjectPoseStorageInterfacePrx storage = reader.getObjectPoseStorage();
74 
75  armarx::objpose::observer::RequestObjectsInput input;
76  input.provider = provider;
77  for (const armarx::ObjectID& id : objectIds)
78  {
79  armarx::toIce(input.request.objectIDs.emplace_back(), id);
80  }
81  input.request.relativeTimeoutMS = relativeTimeout.toMilliSeconds();
82 
83 
84  objpose::observer::RequestObjectsOutput output;
85  try
86  {
87  output = storage->requestObjects(input);
88  }
89  catch (const Ice::Exception& e)
90  {
91  ARMARX_WARNING << "Failed to request object localization: " << e.what();
92  emitFailure();
93  return;
94  }
95 
96  for (const auto& [id, result] : output.results)
97  {
98  if (result.result.success)
99  {
100  info << "Requested object " << id << " via provider '" << result.providerName
101  << "'.\n";
102  }
103  else
104  {
105  warn << "\nFailed to request the object " << id << " for localization.";
106  }
107  }
108 
109  if (not info.str().empty())
110  {
111  ARMARX_INFO << info.str();
112  }
113  if (not warn.str().empty())
114  {
116  << "The following issues occurred whhen requesting objects for localization:"
117  << warn.str();
118  }
119 
120  emitSuccess();
121  }
122 
123  //void RequestObjects::onBreak()
124  //{
125  // // put your user code for the breaking point here
126  // // execution time should be short (<100ms)
127  //}
128 
129  void
131  {
132  // put your user code for the exit point here
133  // execution time should be short (<100ms)
134  }
135 
136  // DO NOT EDIT NEXT FUNCTION
139  {
140  return XMLStateFactoryBasePtr(new RequestObjects(stateData));
141  }
142 } // namespace armarx::ObjectMemoryGroup
armarx::ObjectMemoryGroup::RequestObjects::onEnter
void onEnter() override
Definition: RequestObjects.cpp:25
armarx::ObjectPoseStorageInterfacePrx
::IceInternal::ProxyHandle<::IceProxy::armarx::objpose::ObjectPoseStorageInterface > ObjectPoseStorageInterfacePrx
Definition: ObjectPoseClientWidget.h:51
ice_conversions.h
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:11
armarx::ObjectID::FromString
static ObjectID FromString(const std::string &idString)
Construct from a string produced by str(), e.g. ("mydataset/myobject", "mydataset/myclass/myinstance"...
Definition: ObjectID.cpp:31
armarx::ObjectMemoryGroup::RequestObjects::RequestObjects
RequestObjects(const XMLStateConstructorParams &stateData)
Definition: RequestObjects.cpp:18
armarx::ObjectMemoryGroup::RequestObjects::run
void run() override
Definition: RequestObjects.cpp:33
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::ObjectMemoryGroup::RequestObjects::onExit
void onExit() override
Definition: RequestObjects.cpp:130
armarx::ObjectMemoryGroup::RequestObjects::Registry
static SubClassRegistry Registry
Definition: RequestObjects.h:21
armarx::armem::obj::instance::Reader
Definition: ObjectReader.h:40
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
ObjectID.h
armarx::ObjectMemoryGroup::RequestObjects
Definition: RequestObjects.h:7
ObjectReader.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::armem::client::MemoryNameSystem
The memory name system (MNS) client.
Definition: MemoryNameSystem.h:69
armarx::core::time::Duration::toMilliSeconds
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Definition: Duration.cpp:69
armarx::ObjectMemoryGroup
Definition: ObjectMemoryGroupRemoteStateOfferer.cpp:3
RequestObjects.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::ObjectMemoryGroup::RequestObjects::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: RequestObjects.cpp:138
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55