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 
27 
32 #include <MemoryX/interface/components/CommonStorageInterface.h>
33 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
34 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
35 #include <MemoryX/interface/workingmemory/AbstractWorkingMemoryInterface.h>
36 
37 namespace memoryx
38 {
39 
41  {
42  public:
45  {
46  defineOptionalProperty<bool>("UsePriorMemory", true, "Switch prior knowledge on/off.");
47 
48  defineOptionalProperty<std::string>(
49  "PriorMemoryName", "PriorKnowledge", "Name of PriorKnowledge Ice component");
50 
51  defineOptionalProperty<bool>(
52  "UseLongtermMemory", true, "Switch longterm memory on/off.");
53 
54  defineOptionalProperty<std::string>(
55  "LongtermMemoryName", "LongtermMemory", "Name of LongtermMemory Ice component");
56 
57  defineOptionalProperty<bool>(
58  "PublishUpdates",
59  true,
60  "Publish scene updates (ObjectCreated/Updated/Removed) on IceStrom topic");
61 
62  defineOptionalProperty<std::string>(
63  "UpdatesTopicName",
64  "WorkingMemoryUpdates",
65  "Name of IceStrom topic to publish scene updates on");
66 
67  defineOptionalProperty<std::string>(
68  "SnapshotToLoad",
69  "",
70  "Name of Snapshot that should be loaded on start up. Leave empty for none.");
71  }
72  };
73 
75  {
76  WorkingMemoryUpdaterBasePrx proxy;
77  WorkingMemoryUpdaterBasePtr pointer;
78  };
79 
80  using MemoryUpdaterMap = std::map<std::string, MemoryUpdaterEntry>;
81 
83  virtual public AbstractWorkingMemoryInterface,
84  virtual public SegmentedMemory,
85  virtual public armarx::Component
86  {
87  public:
88  // inherited from Component
89  std::string
90  getDefaultName() const override
91  {
92  return "AbstractWorkingMemory";
93  }
94 
95  void onInitComponent() override;
96  void onConnectComponent() override;
97 
98  // TODO: exit or destructor: clean all segments and updaters in order to resolve cyclic pointer dependencies
99 
100  /**
101  * @see PropertyUser::createPropertyDefinitions()
102  */
105  {
107  new AbstractWorkingMemoryPropertyDefinitions(getConfigIdentifier()));
108  }
109 
111  getObjectAdapter() const override
112  {
113  return Component::getObjectAdapter();
114  }
115 
116  // implementation of WorkingMemoryInterface
117  AbstractMemorySegmentPrx addSegment(const std::string& segmentName,
118  const AbstractMemorySegmentPtr& segment,
119  const ::Ice::Current& = Ice::emptyCurrent) override;
120 
121  WorkingMemoryUpdaterBasePrx
122  registerUpdater(const std::string& updaterName,
123  const WorkingMemoryUpdaterBasePtr& updater,
124  const ::Ice::Current& = Ice::emptyCurrent) override;
125  WorkingMemoryUpdaterBasePrx getUpdater(const std::string& updaterName,
126  const ::Ice::Current& = Ice::emptyCurrent) override;
127  void unregisterUpdater(const std::string& updaterName,
128  const ::Ice::Current& = Ice::emptyCurrent) override;
129 
130  /*!
131  * \brief getListenerTopicName The topic name.
132  * \return
133  */
134  std::string
136  {
137  return updatesTopicName;
138  }
139 
140  AbstractMemorySegmentPrx
141  addGenericSegment(const std::string& segmentName, const Ice::Current&) override
142  {
143  WorkingMemoryEntitySegmentBasePtr segment = new WorkingMemoryEntitySegment<Entity>();
144  return addSegment(segmentName, segment);
145  }
146 
147  // misc
148  void clear(const ::Ice::Current& = Ice::emptyCurrent) override;
149  void print(const ::Ice::Current& = Ice::emptyCurrent) const override;
150 
151  protected:
152  // subclass hooks
153  virtual void onInitWorkingMemory() = 0;
154  virtual void onConnectWorkingMemory() = 0;
155 
156  CommonStorageInterfacePrx dataBasePrx;
157  PriorKnowledgeInterfacePrx priorKnowledgePrx;
158  LongtermMemoryInterfacePrx longtermMemoryPrx;
159  WorkingMemoryListenerInterfacePrx listenerPrx;
161 
163  mutable std::shared_mutex updaterMutex;
164 
169 
170  std::string priorMemoryName;
171  std::string longtermMemoryName;
172  std::string updatesTopicName;
173  };
174 
176 
177 } // namespace memoryx
memoryx::MemoryUpdaterEntry::proxy
WorkingMemoryUpdaterBasePrx proxy
Definition: AbstractWorkingMemory.h:76
memoryx::MemoryUpdaterEntry::pointer
WorkingMemoryUpdaterBasePtr pointer
Definition: AbstractWorkingMemory.h:77
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:537
memoryx::MemoryUpdaterEntry
Definition: AbstractWorkingMemory.h:74
memoryx::AbstractWorkingMemory::useCommonStorage
bool useCommonStorage
Definition: AbstractWorkingMemory.h:167
memoryx::AbstractWorkingMemory::addGenericSegment
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
Definition: AbstractWorkingMemory.h:141
MongoDBRef.h
memoryx::AbstractWorkingMemory::priorMemoryName
std::string priorMemoryName
Definition: AbstractWorkingMemory.h:170
memoryx::AbstractWorkingMemory::dataBasePrx
CommonStorageInterfacePrx dataBasePrx
Definition: AbstractWorkingMemory.h:156
memoryx::AbstractWorkingMemoryPropertyDefinitions::AbstractWorkingMemoryPropertyDefinitions
AbstractWorkingMemoryPropertyDefinitions(std::string prefix)
Definition: AbstractWorkingMemory.h:43
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
MongoSerializer.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::AbstractWorkingMemory::getListenerTopicName
std::string getListenerTopicName()
getListenerTopicName The topic name.
Definition: AbstractWorkingMemory.h:135
memoryx::SegmentedMemory
The SegmentedMemory class provides an interface for organizing memories with segmented data structure...
Definition: SegmentedMemory.h:46
IceInternal::Handle<::Ice::ObjectAdapter >
memoryx::MemoryUpdaterMap
std::map< std::string, MemoryUpdaterEntry > MemoryUpdaterMap
Definition: AbstractWorkingMemory.h:80
memoryx::WorkingMemoryEntitySegment
Definition: WorkingMemoryEntitySegment.h:45
memoryx::AbstractWorkingMemory::getObjectAdapter
Ice::ObjectAdapterPtr getObjectAdapter() const override
Definition: AbstractWorkingMemory.h:111
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::AbstractWorkingMemory::priorKnowledgePrx
PriorKnowledgeInterfacePrx priorKnowledgePrx
Definition: AbstractWorkingMemory.h:157
memoryx::AbstractWorkingMemory::longtermMemoryPrx
LongtermMemoryInterfacePrx longtermMemoryPrx
Definition: AbstractWorkingMemory.h:158
memoryx::AbstractWorkingMemory::longtermMemoryName
std::string longtermMemoryName
Definition: AbstractWorkingMemory.h:171
memoryx::AbstractWorkingMemoryPropertyDefinitions
Definition: AbstractWorkingMemory.h:40
WorkingMemoryEntitySegment.h
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
memoryx::AbstractWorkingMemory::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: AbstractWorkingMemory.h:104
memoryx::AbstractWorkingMemory::publishUpdates
bool publishUpdates
Definition: AbstractWorkingMemory.h:168
memoryx::AbstractWorkingMemory::updaters
MemoryUpdaterMap updaters
Definition: AbstractWorkingMemory.h:162
memoryx::AbstractWorkingMemory::listenerPrx
WorkingMemoryListenerInterfacePrx listenerPrx
Definition: AbstractWorkingMemory.h:159
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
memoryx::AbstractWorkingMemory
Definition: AbstractWorkingMemory.h:82
memoryx::AbstractWorkingMemory::useLongtermMemory
bool useLongtermMemory
Definition: AbstractWorkingMemory.h:166
memoryx::AbstractWorkingMemory::dbSerializer
MongoSerializerPtr dbSerializer
Definition: AbstractWorkingMemory.h:160
memoryx::AbstractWorkingMemory::usePriorMemory
bool usePriorMemory
Definition: AbstractWorkingMemory.h:165
memoryx::AbstractWorkingMemory::updatesTopicName
std::string updatesTopicName
Definition: AbstractWorkingMemory.h:172
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
memoryx::AbstractWorkingMemory::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: AbstractWorkingMemory.h:90
memoryx::AbstractWorkingMemory::updaterMutex
std::shared_mutex updaterMutex
Definition: AbstractWorkingMemory.h:163
ImportExportComponent.h