AbstractWorkingMemory.h
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 MemoryX::WorkingMemory
17 * @author ALexey Kozlov ( kozlov at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
26 
29 #include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
30 
31 #include <MemoryX/interface/components/CommonStorageInterface.h>
32 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
33 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
34 
38 
39 namespace memoryx
40 {
41 
44  {
45  public:
48  {
49  defineOptionalProperty<bool>("UsePriorMemory", true, "Switch prior knowledge on/off.");
50 
51  defineOptionalProperty<std::string>("PriorMemoryName", "PriorKnowledge", "Name of PriorKnowledge Ice component");
52 
53  defineOptionalProperty<bool>("UseLongtermMemory", true, "Switch longterm memory on/off.");
54 
55  defineOptionalProperty<std::string>("LongtermMemoryName", "LongtermMemory", "Name of LongtermMemory Ice component");
56 
57  defineOptionalProperty<bool>("PublishUpdates", true, "Publish scene updates (ObjectCreated/Updated/Removed) on IceStrom topic");
58 
59  defineOptionalProperty<std::string>("UpdatesTopicName", "WorkingMemoryUpdates", "Name of IceStrom topic to publish scene updates on");
60 
61  defineOptionalProperty<std::string>("SnapshotToLoad", "", "Name of Snapshot that should be loaded on start up. Leave empty for none.");
62  }
63  };
64 
66  {
67  WorkingMemoryUpdaterBasePrx proxy;
68  WorkingMemoryUpdaterBasePtr pointer;
69  };
70 
71  using MemoryUpdaterMap = std::map<std::string, MemoryUpdaterEntry>;
72 
74  virtual public AbstractWorkingMemoryInterface,
75  virtual public SegmentedMemory,
76  virtual public armarx::Component
77  {
78  public:
79  // inherited from Component
80  std::string getDefaultName() const override
81  {
82  return "AbstractWorkingMemory";
83  }
84  void onInitComponent() override;
85  void onConnectComponent() override;
86 
87  // TODO: exit or destructor: clean all segments and updaters in order to resolve cyclic pointer dependencies
88 
89  /**
90  * @see PropertyUser::createPropertyDefinitions()
91  */
93  {
96  getConfigIdentifier()));
97  }
98 
100  {
101  return Component::getObjectAdapter();
102  }
103 
104  // implementation of WorkingMemoryInterface
105  AbstractMemorySegmentPrx addSegment(const std::string& segmentName, const AbstractMemorySegmentPtr& segment, const ::Ice::Current& = Ice::emptyCurrent) override;
106 
107  WorkingMemoryUpdaterBasePrx registerUpdater(const std::string& updaterName, const WorkingMemoryUpdaterBasePtr& updater, const ::Ice::Current& = Ice::emptyCurrent) override;
108  WorkingMemoryUpdaterBasePrx getUpdater(const std::string& updaterName, const ::Ice::Current& = Ice::emptyCurrent) override;
109  void unregisterUpdater(const std::string& updaterName, const ::Ice::Current& = Ice::emptyCurrent) override;
110 
111  /*!
112  * \brief getListenerTopicName The topic name.
113  * \return
114  */
115  std::string getListenerTopicName()
116  {
117  return updatesTopicName;
118  }
119 
120  AbstractMemorySegmentPrx addGenericSegment(const std::string& segmentName, const Ice::Current&) override
121  {
122  WorkingMemoryEntitySegmentBasePtr segment = new WorkingMemoryEntitySegment<Entity>();
123  return addSegment(segmentName, segment);
124  }
125 
126  // misc
127  void clear(const ::Ice::Current& = Ice::emptyCurrent) override;
128  void print(const ::Ice::Current& = Ice::emptyCurrent) const override;
129 
130  protected:
131  // subclass hooks
132  virtual void onInitWorkingMemory() = 0;
133  virtual void onConnectWorkingMemory() = 0;
134 
135  CommonStorageInterfacePrx dataBasePrx;
136  PriorKnowledgeInterfacePrx priorKnowledgePrx;
137  LongtermMemoryInterfacePrx longtermMemoryPrx;
138  WorkingMemoryListenerInterfacePrx listenerPrx;
140 
142  mutable std::shared_mutex updaterMutex;
143 
148 
149  std::string priorMemoryName;
150  std::string longtermMemoryName;
151  std::string updatesTopicName;
152  };
153 
155 
156 }
memoryx::MemoryUpdaterEntry::proxy
WorkingMemoryUpdaterBasePrx proxy
Definition: AbstractWorkingMemory.h:67
memoryx::MemoryUpdaterEntry::pointer
WorkingMemoryUpdaterBasePtr pointer
Definition: AbstractWorkingMemory.h:68
SegmentedMemory.h
rapidxml::print
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Prints XML to given output iterator.
Definition: rapidxml_print.hpp:507
memoryx::MemoryUpdaterEntry
Definition: AbstractWorkingMemory.h:65
memoryx::AbstractWorkingMemory::useCommonStorage
bool useCommonStorage
Definition: AbstractWorkingMemory.h:146
memoryx::AbstractWorkingMemory::addGenericSegment
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
Definition: AbstractWorkingMemory.h:120
MongoDBRef.h
memoryx::AbstractWorkingMemory::priorMemoryName
std::string priorMemoryName
Definition: AbstractWorkingMemory.h:149
memoryx::AbstractWorkingMemory::dataBasePrx
CommonStorageInterfacePrx dataBasePrx
Definition: AbstractWorkingMemory.h:135
memoryx::AbstractWorkingMemoryPropertyDefinitions::AbstractWorkingMemoryPropertyDefinitions
AbstractWorkingMemoryPropertyDefinitions(std::string prefix)
Definition: AbstractWorkingMemory.h:46
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
MongoSerializer.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::AbstractWorkingMemory::getListenerTopicName
std::string getListenerTopicName()
getListenerTopicName The topic name.
Definition: AbstractWorkingMemory.h:115
memoryx::SegmentedMemory
The SegmentedMemory class provides an interface for organizing memories with segmented data structure...
Definition: SegmentedMemory.h:45
IceInternal::Handle< ::Ice::ObjectAdapter >
memoryx::MemoryUpdaterMap
std::map< std::string, MemoryUpdaterEntry > MemoryUpdaterMap
Definition: AbstractWorkingMemory.h:71
memoryx::WorkingMemoryEntitySegment
Definition: WorkingMemoryEntitySegment.h:44
memoryx::AbstractWorkingMemory::getObjectAdapter
Ice::ObjectAdapterPtr getObjectAdapter() const override
Definition: AbstractWorkingMemory.h:99
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::AbstractWorkingMemory::priorKnowledgePrx
PriorKnowledgeInterfacePrx priorKnowledgePrx
Definition: AbstractWorkingMemory.h:136
memoryx::AbstractWorkingMemory::longtermMemoryPrx
LongtermMemoryInterfacePrx longtermMemoryPrx
Definition: AbstractWorkingMemory.h:137
memoryx::AbstractWorkingMemory::longtermMemoryName
std::string longtermMemoryName
Definition: AbstractWorkingMemory.h:150
memoryx::AbstractWorkingMemoryPropertyDefinitions
Definition: AbstractWorkingMemory.h:42
WorkingMemoryEntitySegment.h
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
memoryx::AbstractWorkingMemory::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: AbstractWorkingMemory.h:92
memoryx::AbstractWorkingMemory::publishUpdates
bool publishUpdates
Definition: AbstractWorkingMemory.h:147
memoryx::AbstractWorkingMemory::updaters
MemoryUpdaterMap updaters
Definition: AbstractWorkingMemory.h:141
memoryx::AbstractWorkingMemory::listenerPrx
WorkingMemoryListenerInterfacePrx listenerPrx
Definition: AbstractWorkingMemory.h:138
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
memoryx::AbstractWorkingMemory
Definition: AbstractWorkingMemory.h:73
memoryx::AbstractWorkingMemory::useLongtermMemory
bool useLongtermMemory
Definition: AbstractWorkingMemory.h:145
memoryx::AbstractWorkingMemory::dbSerializer
MongoSerializerPtr dbSerializer
Definition: AbstractWorkingMemory.h:139
memoryx::AbstractWorkingMemory::usePriorMemory
bool usePriorMemory
Definition: AbstractWorkingMemory.h:144
memoryx::AbstractWorkingMemory::updatesTopicName
std::string updatesTopicName
Definition: AbstractWorkingMemory.h:151
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
memoryx::AbstractWorkingMemory::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: AbstractWorkingMemory.h:80
memoryx::AbstractWorkingMemory::updaterMutex
std::shared_mutex updaterMutex
Definition: AbstractWorkingMemory.h:142
ImportExportComponent.h