25#include <Ice/ObjectAdapter.h>
35#include <MemoryX/interface/memorytypes/MemorySegments.h>
46 virtual public WorkingMemoryEntitySegmentBase,
54 this->objectTypeId = T::ice_staticId();
70 const ::Ice::Current&
c = Ice::emptyCurrent)
override
74 throw armarx::LocalException(
"FusionMethod Ptr null");
87 throw InvalidEntityException(
"entity is null");
91 if (!entity->ice_isA(objectTypeId))
93 throw InvalidEntityException(
"invalid object id");
97 EntityBasePtr newEntity = entity;
99 for (FusionMethodList::iterator it = fusionMethods.begin(); it != fusionMethods.end();
102 newEntity = (*it)->initEntity(newEntity);
118 std::string
id = newEntity->getId();
129 newEntity->setId(
id);
135 const int intId = std::stoi(
id);
142 catch (std::exception
const&)
152 listenerProxy->reportEntityCreated(
segmentName, newEntity);
172 addEntity(
const EntityBasePtr& entity, const ::Ice::Current&
c = Ice::emptyCurrent)
override
176 std::scoped_lock<std::mutex> lock(
mutex);
181 addEntityList(
const EntityBaseList& entityList, const ::Ice::Current&
c)
override
183 EntityIdList entityIds(entityList.size(),
"");
185 for (
size_t i = 0; i < entityList.size(); i++)
191 catch (
const memoryx::InvalidEntityException& e)
202 const EntityBasePtr& newEntity,
203 const ::Ice::Current&
c = Ice::emptyCurrent)
override
205 std::scoped_lock<std::mutex> lock(
mutex);
220 EntityIdList entityIds(entityList.size(),
"");
222 for (
size_t i = 0; i < entityList.size(); i++)
226 entityIds[i] =
upsertEntity(entityList[i]->getId(), entityList[i],
c);
228 catch (
const memoryx::InvalidEntityException& e)
239 const EntityBasePtr& newEntity,
240 const ::Ice::Current&
c = Ice::emptyCurrent)
override
242 std::scoped_lock<std::mutex> lock(
mutex);
247 return oldEntity->getId();
257 const EntityBasePtr& update,
258 const ::Ice::Current&
c = Ice::emptyCurrent)
override
265 const EntityBasePtr& update,
266 const Ice::StringSeq& deactivatedFusionMethods,
267 const ::Ice::Current&
c = Ice::emptyCurrent)
269 std::scoped_lock<std::mutex> lock(
mutex);
276 const EntityBasePtr& update,
277 const Ice::StringSeq& deactivatedFusionMethods)
284 throw InvalidEntityException();
292 throw EntityNotFoundException();
296 if (update->getName() != oldEntity->getName())
298 ARMARX_FATAL_S <<
"Entity names do not match: New name = '" << update->getName()
299 <<
"', Old name = '" << oldEntity->getName()
300 <<
"', Entity id = " << entityId;
301 throw InvalidEntityException();
305 update->setId(entityId);
308 EntityBasePtr newEntity = update;
311 for (FusionMethodList::iterator it = fusionMethods.begin(); it != fusionMethods.end();
314 if (std::find(deactivatedFusionMethods.begin(),
315 deactivatedFusionMethods.end(),
316 (*it)->getMethodName()) == deactivatedFusionMethods.end())
318 newEntity = (*it)->fuseEntity(oldEntity, newEntity);
327 listenerProxy->reportEntityUpdated(
329 EntityPtr::dynamicCast(oldEntity->ice_clone()),
330 EntityPtr::dynamicCast(newEntity->ice_clone()));
336 removeEntity(const ::std::string&
id, const ::Ice::Current&
c = Ice::emptyCurrent)
override
338 std::scoped_lock<std::mutex> lock(
mutex);
339 IdEntityMap::iterator it =
entityMap.find(
id);
343 throw EntityNotFoundException();
346 EntityBasePtr entity = it->second;
351 listenerProxy->reportEntityRemoved(
segmentName, entity);
363 const EntityAttributeBasePtr& attribute,
364 const ::Ice::Current&
c)
override
366 std::scoped_lock<std::mutex> lock(
mutex);
367 IdEntityMap::iterator it =
entityMap.find(entityId);
371 throw EntityNotFoundException();
374 it->second->putAttribute(attribute);
379 const EntityAttributeList& attributeMap,
380 const ::Ice::Current&
c)
override
382 std::scoped_lock<std::mutex> lock(
mutex);
383 IdEntityMap::iterator it =
entityMap.find(entityId);
387 throw EntityNotFoundException();
390 for (
auto attribute : attributeMap)
392 it->second->putAttribute(attribute);
397 clear(const ::Ice::Current&
c = Ice::emptyCurrent)
override
400 std::scoped_lock<std::mutex> lock(
mutex);
404 EntityBasePtr entity = entityMapIter->second;
408 listenerProxy->reportEntityRemoved(
segmentName, entity);
411 entityMapIter =
entityMap.erase(entityMapIter);
424 size(const ::Ice::Current&
c = Ice::emptyCurrent)
const override
426 std::scoped_lock<std::mutex> lock(
mutex);
431 hasEntityById(
const std::string& entityId, const ::Ice::Current&
c)
const override
433 std::scoped_lock<std::mutex> lock(
mutex);
441 IdEntityMap::const_iterator it =
entityMap.find(entityId);
449 std::scoped_lock<std::mutex> lock(
mutex);
453 if (entity.second && entity.second->getName() == entityName)
465 std::scoped_lock<std::mutex> lock(
mutex);
472 std::scoped_lock<std::mutex> lock(
mutex);
473 IdEntityMap::const_iterator it =
entityMap.find(
id);
478 return EntityBasePtr::dynamicCast(it->second->ice_clone());
484 return EntityBasePtr();
491 std::scoped_lock<std::mutex> lock(
mutex);
502 if (it->second->getName() == name)
504 return EntityBasePtr::dynamicCast(it->second);
508 std::string entities;
512 entities += e.second->getName() +
" ";
515 ARMARX_INFO_S <<
"Could not find entity named " << name <<
" in entity list { "
517 return EntityBasePtr();
524 std::scoped_lock<std::mutex> lock(
mutex);
529 if (it->second->getName() == name)
531 return EntityBasePtr::dynamicCast(it->second->ice_clone());
537 std::string entities;
541 entities += e.second->getName() +
" ";
544 ARMARX_INFO_S <<
"Could not find entity named " << name <<
" in entity list { "
546 return EntityBasePtr();
551 const ::std::string& attrValue,
552 const ::Ice::Current&
c)
const override
554 NameList attrValueList;
555 attrValueList.push_back(attrValue);
562 NameList attrValueList;
563 attrValueList.push_back(attrValue);
569 const NameList& attrValueList)
const
571 EntityBaseList result;
573 std::scoped_lock<std::mutex> lock(
mutex);
576 const EntityAttributeBasePtr attr = it->second->getAttribute(attrName);
580 for (NameList::const_iterator itVal = attrValueList.begin();
581 itVal != attrValueList.end();
586 result.push_back(EntityBasePtr::dynamicCast(it->second));
598 const NameList& attrValueList,
599 const ::Ice::Current&
c)
const override
601 EntityBaseList result;
603 std::scoped_lock<std::mutex> lock(
mutex);
607 const EntityAttributeBasePtr attr = it->second->getAttribute(attrName);
611 for (NameList::const_iterator itVal = attrValueList.begin();
612 itVal != attrValueList.end();
618 result.push_back(EntityBasePtr::dynamicCast(it->second->ice_clone()));
632 std::scoped_lock<std::mutex> lock(
mutex);
635 result.push_back(it->first);
644 EntityBaseList result;
645 std::scoped_lock<std::mutex> lock(
mutex);
650 result.push_back(EntityBasePtr::dynamicCast(entry.second->ice_clone()));
660 std::scoped_lock<std::mutex> lock(
mutex);
664 result.insert({entry.first, EntityBasePtr::dynamicCast(entry.second->ice_clone())});
671 print(const ::Ice::Current&
c = Ice::emptyCurrent)
const override
673 std::scoped_lock<std::mutex> lock(
mutex);
677 ARMARX_INFO_S << EntityPtr::dynamicCast(it->second) << std::endl;
691 WorkingMemoryListenerInterfacePrx
694 return this->listenerProxy;
705 const ::Ice::Current&
c = Ice::emptyCurrent)
override
707 this->listenerProxy = listenerProxy;
713 const ::Ice::Current&
c = Ice::emptyCurrent)
override
741 EntityMemorySegmentInterfacePrx::uncheckedCast(
c.adapter->createProxy(
c.id));
743 std::string memName = mem->getMemoryName();
744 auto memoryProxy = MemoryInterfacePrx::checkedCast(
745 c.adapter->getCommunicator()->stringToProxy(memName));
773 std::string memName = mem->getMemoryName();
775 EntityMemorySegmentInterfacePrx::uncheckedCast(
c.adapter->createProxy(
c.id));
776 auto memoryProxy = MemoryInterfacePrx::checkedCast(
777 c.adapter->getCommunicator()->stringToProxy(memName));
796 IdEntityMap::const_iterator it =
entityMap.find(
id);
800 return EntityBasePtr::dynamicCast(it->second);
805 return EntityBasePtr();
#define ARMARXCOMPONENT_IMPORT_EXPORT
The Variant class is described here: Variants.
The EntityRef class is used to store references to Entities as values in other Entity instances.
SegmentUtilImplementations()
friend class SegmentedMemory
void addFusionMethod(const ::memoryx::EntityFusionMethodBasePtr &fusionMethod, const ::Ice::Current &c=Ice::emptyCurrent) override
MemoryInterfacePtr parentMemory
void setEntityAttributes(const std::string &entityId, const EntityAttributeList &attributeMap, const ::Ice::Current &c) override
EntityFusionMethodPtr fusionMethod
std::string upsertEntityByName(const std::string &entityName, const EntityBasePtr &newEntity, const ::Ice::Current &c=Ice::emptyCurrent) override
bool hasEntityByName(const std::string &entityName, const ::Ice::Current &c) const override
void clear(const ::Ice::Current &c=Ice::emptyCurrent) override
std::string addEntity(const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
addEntity addes an entity to this segment. The registered fusion methods are applied in order to fuse...
IdEntityMap getIdEntityMap(const Ice::Current &c=Ice::emptyCurrent) const override
void setSegmentName(const std::string &segmentName, const ::Ice::Current &c=Ice::emptyCurrent) override
void removeEntity(const ::std::string &id, const ::Ice::Current &c=Ice::emptyCurrent) override
EntityBaseList getEntitiesByAttrValueList(const ::std::string &attrName, const NameList &attrValueList, const ::Ice::Current &c) const override
EntityRefBasePtr getEntityRefById(const std::string &id, const Ice::Current &c) const override
EntityBasePtr getEntityByName(const ::std::string &name, const ::Ice::Current &c) const override
std::string upsertEntity(const std::string &entityId, const EntityBasePtr &newEntity, const ::Ice::Current &c=Ice::emptyCurrent) override
std::string getSegmentName(const ::Ice::Current &c=Ice::emptyCurrent) const override
EntityBasePtr getEntityByIdUnsafe(const ::std::string &id) const
bool hasEntityByIdThreadUnsafe(const std::string &entityId) const
WorkingMemoryListenerInterfacePrx getListenerProxy(const ::Ice::Current &c=Ice::emptyCurrent) override
getListener The topic on which changes are reported.
void updateEntity(const std::string &entityId, const EntityBasePtr &update, const Ice::StringSeq &deactivatedFusionMethods, const ::Ice::Current &c=Ice::emptyCurrent)
void removeAllEntities(const ::Ice::Current &c=Ice::emptyCurrent) override
Ice::Identity getIceId(const ::Ice::Current &c) const override
EntityBaseList getEntitiesByAttrValue(const ::std::string &attrName, const ::std::string &attrValue, const ::Ice::Current &c) const override
void fuseEntity(const EntityBasePtr &entity)
EntityBasePtr getEntityByNameThreadUnsafe(const ::std::string &name) const
void updateEntity(const std::string &entityId, const EntityBasePtr &update, const ::Ice::Current &c=Ice::emptyCurrent) override
EntityBasePtr getEntityById(const ::std::string &id, const ::Ice::Current &c) const override
EntityIdList getAllEntityIds(const Ice::Current &c=Ice::emptyCurrent) const override
EntityBasePtr getEntityByName(const ::std::string &name) const
EntityIdList addEntityList(const EntityBaseList &entityList, const ::Ice::Current &c) override
bool hasEntityById(const std::string &entityId, const ::Ice::Current &c) const override
WorkingMemoryEntitySegment()
void updateEntityThreadUnsafe(const std::string &entityId, const EntityBasePtr &update, const Ice::StringSeq &deactivatedFusionMethods)
void setEntityAttribute(const std::string &entityId, const EntityAttributeBasePtr &attribute, const ::Ice::Current &c) override
EntityBasePtr getEntityById(const ::std::string &id) const
EntityBaseList getEntitiesByAttrValue(const ::std::string &attrName, const ::std::string &attrValue) const
Ice::Int size(const ::Ice::Current &c=Ice::emptyCurrent) const override
void setParentMemory(const MemoryInterfacePtr &memory, const ::Ice::Current &c) override
EntityRefBasePtr getEntityRefByName(const std::string &name, const Ice::Current &c) const override
EntityBaseList getAllEntities(const Ice::Current &c=Ice::emptyCurrent) const override
std::string getObjectTypeId(const ::Ice::Current &c=Ice::emptyCurrent) const override
getObjectTypeId returns the ice_staticId() of the entities stored inside this WorkingMemorySegment
EntityIdList upsertEntityList(const EntityBaseList &entityList, const ::Ice::Current &c) override
std::string addEntityThreadUnsafe(const EntityBasePtr &newEntity)
adds the entity to the segment.
EntityBaseList getEntitiesByAttrValueList(const ::std::string &attrName, const NameList &attrValueList) const
void print(const ::Ice::Current &c=Ice::emptyCurrent) const override
void setListenerProxy(const WorkingMemoryListenerInterfacePrx &listenerProxy, const ::Ice::Current &c=Ice::emptyCurrent) override
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_FATAL_S
The logging level for unexpected behaviour, that will lead to a seriously malfunctioning program and ...
IceInternal::Handle< EntityRef > EntityRefPtr
IceInternal::Handle< EntityFusionMethod > EntityFusionMethodPtr
IceInternal::Handle< SegmentedMemory > SegmentedMemoryPtr