RequestedObjects.cpp
Go to the documentation of this file.
1 #include "RequestedObjects.h"
2 
5 
7 
8 namespace armarx::objpose
9 {
11  {
12  }
13 
14  void RequestedObjects::requestObjects(const std::vector<armarx::data::ObjectID>& objectIDs, long relativeTimeOutMS)
15  {
16  requestObjects(::armarx::fromIce(objectIDs), relativeTimeOutMS);
17  }
18 
19  void RequestedObjects::requestObjects(const std::vector<armarx::ObjectID>& objectIDs, long relativeTimeOutMS)
20  {
21  requestObjects(objectIDs, IceUtil::Time::milliSeconds(relativeTimeOutMS));
22  }
23 
25  const std::vector<armarx::ObjectID>& objectIDs, IceUtil::Time relativeTimeout)
26  {
27  if (relativeTimeout.toMilliSeconds() < 0)
28  {
29  for (const auto& id : objectIDs)
30  {
31  infiniteRequests.push_back(id);
32  }
33  }
34  else
35  {
36  IceUtil::Time absoluteTimeout = TimeUtil::GetTime() + relativeTimeout;
37  Request req;
38  req.objectIDs = objectIDs;
39  currentRequests[absoluteTimeout].push_back(req);
40  }
41  }
42 
44  {
46  }
47 
49  {
50  // Remove requests with timeout.
51  while (currentRequests.size() > 0 && currentRequests.begin()->first <= now)
52  {
53  currentRequests.erase(currentRequests.begin());
54  }
55 
56  std::set<armarx::ObjectID> current;
57  current.insert(infiniteRequests.begin(), infiniteRequests.end());
58 
59  // Process current requests.
60  for (const auto& [timeout, requests] : currentRequests)
61  {
62  ARMARX_CHECK_LESS(now, timeout);
63  for (const auto& request : requests)
64  {
65  current.insert(request.objectIDs.begin(), request.objectIDs.end());
66  }
67  }
68 
69  Update update;
70  update.current = { current.begin(), current.end() };
71 
72  // added = current - last
73  std::set_difference(update.current.begin(), update.current.end(),
74  lastCurrent.begin(), lastCurrent.end(),
75  std::inserter(update.added, update.added.begin()));
76  // removed = last - current
77  std::set_difference(lastCurrent.begin(), lastCurrent.end(),
78  update.current.begin(), update.current.end(),
79  std::inserter(update.removed, update.removed.begin()));
80 
81  this->lastCurrent = update.current;
82  return update;
83  }
84 
85 }
86 
armarx::objpose::RequestedObjects::requestObjects
void requestObjects(const std::vector< armarx::data::ObjectID > &objectIDs, long relativeTimeOutMS)
Definition: RequestedObjects.cpp:14
ice_conversions.h
ARMARX_CHECK_LESS
#define ARMARX_CHECK_LESS(lhs, rhs)
This macro evaluates whether lhs is less (<) than rhs and if it turns out to be false it will throw a...
Definition: ExpressionException.h:102
armarx::objpose::RequestedObjects::infiniteRequests
std::vector< armarx::ObjectID > infiniteRequests
Definition: RequestedObjects.h:52
armarx::objpose::RequestedObjects::currentRequests
std::map< IceUtil::Time, std::vector< Request > > currentRequests
Map from (absolute timeout) to (request)
Definition: RequestedObjects.h:51
armarx::objpose::RequestedObjects::Request::objectIDs
std::vector< armarx::ObjectID > objectIDs
Definition: RequestedObjects.h:24
armarx::objpose::RequestedObjects::updateRequestedObjects
Update updateRequestedObjects()
Definition: RequestedObjects.cpp:43
armarx::objpose::RequestedObjects::RequestedObjects
RequestedObjects()
Definition: RequestedObjects.cpp:10
armarx::objpose
This file is part of ArmarX.
Definition: objpose.h:7
armarx::objpose::RequestedObjects::Request
Definition: RequestedObjects.h:22
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
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::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:26
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
ExpressionException.h
TimeUtil.h
armarx::objpose::RequestedObjects::Update
Definition: RequestedObjects.h:27
RequestedObjects.h