DeleteObjectInstancesFromMemory.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 RobotSkillTemplates::MemoryXUtility
17  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
28 
30 
31 //#include <ArmarXCore/core/time/TimeUtil.h>
32 //#include <ArmarXCore/observers/variant/DatafieldRef.h>
33 
34 using namespace armarx;
35 using namespace MemoryXUtility;
36 
37 // DO NOT EDIT NEXT LINE
38 DeleteObjectInstancesFromMemory::SubClassRegistry DeleteObjectInstancesFromMemory::Registry(DeleteObjectInstancesFromMemory::GetName(), &DeleteObjectInstancesFromMemory::CreateInstance);
39 
40 
41 
43 {
44  // put your user code for the enter-point here
45  // execution time should be short (<100ms)
46 
47 
48 }
49 
51 {
52  // put your user code for the execution-phase here
53  // runs in seperate thread, thus can do complex operations
54  // should check constantly whether isRunningTaskStopped() returns true
55 
56  auto channels = getObjectMemoryObserver()->getAvailableChannels(false);
57 
58  for (auto& channel : channels)
59  {
60  if (channel.first.find("_query_") != std::string::npos)
61  {
62  ChannelRefPtr ref = new ChannelRef(getObjectMemoryObserver(), channel.first);
63  getObjectMemoryObserver()->releaseObjectClass(ref);
64  ARMARX_INFO << "Releasing channel for " << ref->getChannelName();
65  }
66  }
67  auto entities = getPriorKnowledge()->getObjectClassesSegment()->getAllEntities();
68  auto instanceSegment = getWorkingMemory()->getObjectInstancesSegment();
69  for (memoryx::EntityBasePtr base : entities)
70  {
71  memoryx::EntityPtr entity = memoryx::EntityPtr::dynamicCast(base);
72  auto var = entity->getAttributeValue("recognitionMethod");
73  if (var && !var->getString().empty() && var->getString() != "<none>")
74  {
75  auto objInstances = instanceSegment->getObjectInstancesByClass(entity->getName());
76  ARMARX_INFO << "Checking instances of class: " << entity->getName() << " got " << objInstances.size() << " instances";
77  for (auto& obj : objInstances)
78  {
79  instanceSegment->removeEntity(obj->getId());
80  ARMARX_INFO << "Removing instance " << obj->getName() << " with id " << obj->getId();
81  }
82  }
83  }
84  emitSuccess();
85 
86  // // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
87  // while (!isRunningTaskStopped()) // stop run function if returning true
88  // {
89  // // do your calculations
90  // }
91 }
92 
93 //void DeleteObjectInstancesFromMemory::onBreak()
94 //{
95 // // put your user code for the breaking point here
96 // // execution time should be short (<100ms)
97 //}
98 
100 {
101  // put your user code for the exit point here
102  // execution time should be short (<100ms)
103 }
104 
105 
106 // DO NOT EDIT NEXT FUNCTION
108 {
110 }
111 
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DeleteObjectInstancesFromMemory.cpp:107
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::Registry
static SubClassRegistry Registry
Definition: DeleteObjectInstancesFromMemory.h:45
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::onExit
void onExit() override
Definition: DeleteObjectInstancesFromMemory.cpp:99
IceInternal::Handle< ChannelRef >
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:162
MemoryXCoreObjectFactories.h
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::onEnter
void onEnter() override
Definition: DeleteObjectInstancesFromMemory.cpp:42
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::run
void run() override
Definition: DeleteObjectInstancesFromMemory.cpp:50
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
Entity.h
MemoryXTypesObjectFactories.h
armarx::MemoryXUtility::DeleteObjectInstancesFromMemory::DeleteObjectInstancesFromMemory
DeleteObjectInstancesFromMemory(const XMLStateConstructorParams &stateData)
Definition: DeleteObjectInstancesFromMemory.h:32
DeleteObjectInstancesFromMemory.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ChannelRef.h