24#include <Ice/Connection.h>
25#include <Ice/ObjectAdapter.h>
26#include <IceUtil/UUID.h>
71 EntityBasePtr entity = getEntityById(
id);
74 throw EntityNotFoundException();
77 json->setIceObject(
"entity", entity);
78 return json->asString(
true);
83 bool includeMetaEntities,
84 const Ice::Current&
c)
const
86 auto comp = [](
const EntityBasePtr& e1,
const EntityBasePtr& e2)
87 {
return e1->getId() < e2->getId(); };
89 std::set<EntityBasePtr,
decltype(comp)> result(comp);
90 std::set<EntityBasePtr,
decltype(comp)> searchList(comp);
91 EntityPtr root = EntityPtr::dynamicCast(getEntityById(
id,
c));
92 searchList.insert(root);
94 auto all = getAllEntities(
c);
95 std::string attribName =
"parentEntityRefs";
97 while (!searchList.empty())
99 EntityPtr curParent = EntityPtr::dynamicCast(*searchList.begin());
100 auto curParentRef = getEntityRefById(curParent->getId(),
c);
101 searchList.erase(searchList.begin());
102 for (EntityBasePtr& entity : all)
104 if (!entity->hasAttribute(attribName,
c))
108 auto attr = entity->getAttribute(attribName,
c);
109 for (
int i = 0; i < attr->size(); ++i)
112 armarx::VariantPtr::dynamicCast(attr->getValueAt(i,
c))->get<
EntityRef>();
113 if (ref->equals(curParentRef))
115 ARMARX_INFO_S << ref->entityName <<
" is parent of " << entity->getName();
116 if (result.count(entity) ==
119 searchList.insert(entity);
121 result.insert(entity);
127 if (!includeMetaEntities)
129 EntityBaseList filteredResult;
130 std::copy_if(result.begin(),
132 std::back_inserter(filteredResult),
133 [](
const EntityBasePtr& entity) { return !entity->isMetaEntity(); });
134 return filteredResult;
136 return EntityBaseList(result.begin(), result.end());
141 bool includeMetaEntities,
142 const Ice::Current&
c)
const
144 auto entity = getEntityByName(entityName);
151 return EntityBaseList();
162 lockToken = lock->token = IceUtil::generateUUID();
166 EntityMemorySegmentInterfacePrx::uncheckedCast(
c.adapter->createProxy(
c.id));
174 lock->keepAliveIntervalMs * 2,
194 throw InvalidLockTokenException();
215 throw InvalidLockTokenException();
228 const Ice::Current&
c)
234 throw InvalidLockTokenException();
261 <<
"' did not receive keep-alive in time ("
262 << age.toMilliSecondsDouble()
264 <<
" ) - unlocking segment";
295 segment->unlockSegmentWithToken(this->token);
321 segment->keepLockAlive(this->token);
The JSONObject class is used to represent and (de)serialize JSON objects.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
The EntityRef class is used to store references to Entities as values in other Entity instances.
armarx::PeriodicTask< SegmentLock >::pointer_type keepAliveTask
void ice_postUnmarshal() override
void unlock(const Ice::Current &c=Ice::emptyCurrent) override
SegmentLock(bool start_watchdog=false)
std::unique_lock< std::shared_mutex > ScopedUniqueLock
std::string getJSONEntityById(const std::string &id, const Ice::Current &) const override
SegmentUtilImplementations()
bool unlockSegmentWithToken(const std::string &token, const Ice::Current &c) override
std::unique_ptr< ScopedSharedLock > ScopedSharedLockPtr
bool unlockSegment(const SegmentLockBasePtr &lock, const Ice::Current &c) override
ScopedUniqueLockPtr writeLock
EntityBaseList getEntityWithChildrenByName(const std::string &, bool includeMetaEntities, const Ice::Current &c=Ice::emptyCurrent) const override
std::shared_mutex segmentMutex
IceUtil::Time keepAliveTimestamp
ScopedSharedLockPtr getReadLock(const Ice::Current &c) const
ScopedUniqueLockPtr getWriteLock(const Ice::Current &c) const
std::unique_lock< std::shared_mutex > ScopedSharedLock
bool keepLockAlive(const std::string &token, const Ice::Current &) override
std::mutex keepAliveTimestampMutex
armarx::PeriodicTask< SegmentUtilImplementations >::pointer_type keepAliveCheckTask
std::unique_ptr< ScopedSharedLock > ScopedUniqueLockPtr
EntityBaseList getEntityWithChildrenById(const std::string &id, bool includeMetaEntities, const Ice::Current &c=Ice::emptyCurrent) const override
SegmentLockBasePtr lockSegment(const Ice::Current &c) override
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
IceInternal::Handle< JSONObject > JSONObjectPtr
IceInternal::Handle< EntityRef > EntityRefPtr
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.