LongtermMemory.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 MemoryX::LongtermMemory
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// core
24#include "LongtermMemory.h"
25
28
38#include <MemoryX/interface/core/EntityBase.h>
39#include <MemoryX/interface/memorytypes/MemoryEntities.h>
40
41namespace memoryx
42{
43 std::string
45 {
46 return "LongtermMemory";
47 }
48
49 std::string
51 {
52 return "LongtermMemory";
53 }
54
55 void
57 {
58 usingProxy("PriorKnowledge");
59
60 const std::string clsCollNamesStr = getProperty<std::string>("ClassCollections").getValue();
61 classCollNames = armarx::Split(clsCollNamesStr, ",");
62 }
63
64 void
66 {
67 ARMARX_INFO << "connecting long term memory";
68 priorKnowledgePrx = getProxy<PriorKnowledgeInterfacePrx>("PriorKnowledge");
69 const std::string snaplistCollectionName =
70 getProperty<std::string>("SnapshotListCollection").getValue();
71 const std::string oacCollectionName = getProperty<std::string>("OacCollection").getValue();
72 const std::string kbmCollectionName = getProperty<std::string>("KbmCollection").getValue();
73 const std::string dmpCollectionName = getProperty<std::string>("DmpCollection").getValue();
74 const std::string profilerCollectionName =
75 getProperty<std::string>("ProfilerDataCollection").getValue();
76 const std::string resourceProfileCollectionName =
77 getProperty<std::string>("ResourceProfileCollection").getValue();
78 const std::string predictionDataCollectionName =
79 getProperty<std::string>("PredictionDataCollection").getValue();
80 const std::string selfLocalisationCollectionName =
81 getProperty<std::string>("SelfLocalisationCollection").getValue();
82
83 databaseInterfacePrx = storagePrx->requestDatabase(dbName);
84
85 CollectionInterfacePrx snapshotListCollection =
86 databaseInterfacePrx->requestCollection(snaplistCollectionName);
87 CollectionInterfacePrx oacCollection =
88 databaseInterfacePrx->requestCollection(oacCollectionName);
89 CollectionInterfacePrx kbmCollection =
90 databaseInterfacePrx->requestCollection(kbmCollectionName);
91 CollectionInterfacePrx dmpCollection =
92 databaseInterfacePrx->requestCollection(dmpCollectionName);
93
94 WorkingMemorySnapshotListSegmentPtr snapshotListSegment =
95 new WorkingMemorySnapshotListSegment(databaseInterfacePrx, snapshotListCollection, ic);
96 addSegment(LTM::SegmentNames::SNAPSHOTS, snapshotListSegment);
97
98 OacMemorySegmentPtr oacSegment =
99 new OacMemorySegment(priorKnowledgePrx->getObjectClassesSegment(), oacCollection, ic);
100 addSegment(LTM::SegmentNames::OACS, oacSegment);
101
102 PersistentEntitySegmentBasePtr kbmSegment = new KBMSegment(kbmCollection, ic);
103 addSegment(LTM::SegmentNames::KBM, kbmSegment);
104
105 CollectionInterfacePrx profilerCollection =
106 databaseInterfacePrx->requestCollection(profilerCollectionName);
107 addSegment(LTM::SegmentNames::PROFILER,
108 new PersistentProfilerDataSegment(profilerCollection, ic));
109
110 CollectionInterfacePrx resourceProfileCollection =
111 databaseInterfacePrx->requestCollection(resourceProfileCollectionName);
112 addSegment(LTM::SegmentNames::RESOURCE_PROFILES,
113 new PersistentResourceProfileSegment(resourceProfileCollection, ic));
114
115 CollectionInterfacePrx predictionDataCollection =
116 databaseInterfacePrx->requestCollection(predictionDataCollectionName);
117 addSegment(LTM::SegmentNames::PREDICTION_DATA,
118 new PersistentPredictionDataSegment(predictionDataCollection, ic));
119
120 CollectionInterfacePrx classColl = storagePrx->requestCollection(classCollNames[0]);
121 PersistentObjectClassSegmentPtr classesSegment =
122 new PersistentObjectClassSegment(classColl, ic);
123 addSegment(LTM::SegmentNames::OBJECTCLASSES, classesSegment);
124
125 PersistentDMPDataSegmentPtr dmpSegment = new PersistentDMPDataSegment(dmpCollection, ic);
126 addSegment(LTM::SegmentNames::DMP, dmpSegment);
127
128 CollectionInterfacePrx selfLocalisationCollection =
129 databaseInterfacePrx->requestCollection(selfLocalisationCollectionName);
130 PersistentEntitySegmentPtr selfLocalisationSegment =
131 new PersistentEntitySegment(selfLocalisationCollection, ic);
132 addSegment(LTM::SegmentNames::SELF_LOCALISATION, selfLocalisationSegment);
133
134 ARMARX_INFO << "successfully connected long term memory";
135 }
136
137 WorkingMemorySnapshotListSegmentBasePrx
139 {
140 return WorkingMemorySnapshotListSegmentBasePrx::uncheckedCast(
141 getSegment(LTM::SegmentNames::SNAPSHOTS, c));
142 }
143
144 PersistentObjectInstanceSegmentBasePrx
145 LongtermMemory::getCustomInstancesSegment(const std::string& segmentName,
146 bool createIfMissing,
147 const ::Ice::Current& c)
148 {
149 if (hasSegment(segmentName))
150 {
151 return PersistentObjectInstanceSegmentBasePrx::uncheckedCast(
152 getSegment(segmentName, c));
153 }
154 else if (createIfMissing)
155 {
157 databaseInterfacePrx->requestCollection(segmentName), ic);
158 return PersistentObjectInstanceSegmentBasePrx::uncheckedCast(
159 addSegment(segmentName, customSegment, c));
160 }
161 else
162 {
163 return PersistentObjectInstanceSegmentBasePrx();
164 }
165 }
166
167 void
169 const std::string& snapshotName,
170 const AbstractWorkingMemoryInterfacePrx& workingMemory,
171 const ::Ice::Current&)
172 {
173 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
175
176 if (snapshotListSegment)
177 {
178 snapshotListSegment->loadSnapshot(snapshotName, workingMemory);
179 }
180 }
181
182 bool
184 const std::string& snapshotName,
185 const AbstractWorkingMemoryInterfacePrx& workingMemory,
186 const ::Ice::Current&)
187 {
188 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
190
191 if (snapshotListSegment)
192 {
193 return snapshotListSegment->createSnapshot(snapshotName, workingMemory);
194 }
195 else
196 {
197 return false;
198 }
199 }
200
201 WorkingMemorySnapshotInterfacePrx
202 LongtermMemory::openWorkingMemorySnapshot(const std::string& snapshotName,
203 const ::Ice::Current&)
204 {
205 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
207
208 if (snapshotListSegment)
209 {
210 return snapshotListSegment->openSnapshot(snapshotName);
211 }
212 else
213 {
214 return WorkingMemorySnapshotInterfacePrx();
215 }
216 }
217
218 bool
219 LongtermMemory::removeWorkingMemorySnapshot(const std::string& snapshotName,
220 const ::Ice::Current&)
221 {
222 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
224
225 if (snapshotListSegment)
226 {
227 return snapshotListSegment->removeSnapshot(snapshotName);
228 }
229 else
230 {
231 return false;
232 }
233 }
234
235 NameList
236 LongtermMemory::getSnapshotNames(const ::Ice::Current& c)
237 {
238 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
240
241 if (snapshotListSegment)
242 {
243 return snapshotListSegment->getSnapshotNames();
244 }
245 else
246 {
247 throw SnapshotNotFoundException("Snapshot segment not found!", "");
248 }
249 }
250
251 std::string
252 LongtermMemory::getMemoryName(const Ice::Current&) const
253 {
254 return getName();
255 }
256
257 PersistentProfilerDataSegmentBasePrx
259 {
260 return PersistentProfilerDataSegmentBasePrx::uncheckedCast(
261 getSegment(LTM::SegmentNames::PROFILER, c));
262 }
263
264 PersistentPredictionDataSegmentBasePrx
266 {
267 return PersistentPredictionDataSegmentBasePrx::uncheckedCast(
268 getSegment(LTM::SegmentNames::PREDICTION_DATA, c));
269 }
270
271 PersistentResourceProfileSegmentBasePrx
273 {
274 return PersistentResourceProfileSegmentBasePrx::uncheckedCast(
275 getSegment(LTM::SegmentNames::RESOURCE_PROFILES, c));
276 }
277
278 OacMemorySegmentBasePrx
279 LongtermMemory::getOacSegment(const ::Ice::Current& c)
280 {
281 return OacMemorySegmentBasePrx::uncheckedCast(getSegment(LTM::SegmentNames::OACS, c));
282 }
283
284 KBMSegmentBasePrx
285 LongtermMemory::getKBMSegment(const Ice::Current& c)
286 {
287 return KBMSegmentBasePrx::uncheckedCast(getSegment(LTM::SegmentNames::KBM, c));
288 }
289
290 CommonStorageInterfacePrx
291 LongtermMemory::getCommonStorage(const ::Ice::Current&) const
292 {
293 return storagePrx;
294 }
295
296 PersistentObjectClassSegmentBasePrx
297 LongtermMemory::getObjectClassesSegment(const ::Ice::Current& c) const
298 {
299 return PersistentObjectClassSegmentBasePrx::uncheckedCast(
300 getSegment(LTM::SegmentNames::OBJECTCLASSES, c));
301 }
302
303 PersistentDMPDataSegmentBasePrx
304 LongtermMemory::getDMPSegment(const Ice::Current& c)
305 {
306 return PersistentDMPDataSegmentBasePrx::uncheckedCast(
307 getSegment(LTM::SegmentNames::DMP, c));
308 }
309
310 PersistentEntitySegmentBasePrx
312 {
313 return PersistentEntitySegmentBasePrx::uncheckedCast(
314 getSegment(LTM::SegmentNames::SELF_LOCALISATION, c));
315 }
316
317 AbstractMemorySegmentPrx
318 memoryx::LongtermMemory::addGenericSegment(const std::string& segmentName, const Ice::Current&)
319 {
321 new PersistentEntitySegment(databaseInterfacePrx->requestCollection(segmentName),
323 return addSegment(segmentName, segment);
324 }
325} // namespace memoryx
326
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
constexpr T c
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Ice::CommunicatorPtr getCommunicator() const
CommonStorageInterfacePrx storagePrx
The LongtermMemory class provides persistent data that has been learned or copied as a snapshot from ...
NameList getSnapshotNames(const ::Ice::Current &=Ice::emptyCurrent) override
PersistentObjectInstanceSegmentBasePrx getCustomInstancesSegment(const std::string &segmentName, bool createIfMissing, const ::Ice::Current &c=Ice::emptyCurrent) override
void loadWorkingMemorySnapshot(const std::string &snapshotName, const AbstractWorkingMemoryInterfacePrx &workingMemory, const ::Ice::Current &=Ice::emptyCurrent) override
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
OacMemorySegmentBasePrx getOacSegment(const ::Ice::Current &=Ice::emptyCurrent) override
bool removeWorkingMemorySnapshot(const std::string &snapshotName, const ::Ice::Current &=Ice::emptyCurrent) override
bool saveWorkingMemorySnapshot(const std::string &snapshotName, const AbstractWorkingMemoryInterfacePrx &workingMemory, const ::Ice::Current &=Ice::emptyCurrent) override
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &c=Ice::emptyCurrent) const override
PersistentProfilerDataSegmentBasePrx getProfilerDataSegment(const Ice::Current &c=Ice::emptyCurrent) override
KBMSegmentBasePrx getKBMSegment(const Ice::Current &) override
void onConnectLongtermMemory() override
PersistentDMPDataSegmentBasePrx getDMPSegment(const ::Ice::Current &=Ice::emptyCurrent) override
std::string getMemoryName(const Ice::Current &=Ice::emptyCurrent) const override
PersistentEntitySegmentBasePrx getSelfLocalisationSegment(const Ice::Current &c=Ice::emptyCurrent) override
PersistentResourceProfileSegmentBasePrx getResourceProfileSegment(const Ice::Current &c=Ice::emptyCurrent) override
static std::string GetDefaultName()
WorkingMemorySnapshotListSegmentBasePrx getWorkingMemorySnapshotListSegment(const ::Ice::Current &=Ice::emptyCurrent) override
void onInitLongtermMemory() override
PersistentPredictionDataSegmentBasePrx getPredictionDataSegment(const Ice::Current &c=Ice::emptyCurrent) override
PersistentObjectClassSegmentBasePrx getObjectClassesSegment(const ::Ice::Current &c=Ice::emptyCurrent) const override
WorkingMemorySnapshotInterfacePrx openWorkingMemorySnapshot(const std::string &snapshotName, const ::Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
The persistent object class segment is a specialized segment of the SegmentedMemory.
AbstractMemorySegmentPrx addSegment(const std::string &segmentName, const AbstractMemorySegmentPtr &segment, const ::Ice::Current &=Ice::emptyCurrent) override
AbstractMemorySegmentPrx getSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
bool hasSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
VirtualRobot headers.
IceInternal::Handle< PersistentObjectInstanceSegment > PersistentObjectInstanceSegmentPtr
IceUtil::Handle< PersistentEntitySegment > PersistentEntitySegmentPtr
IceInternal::Handle< PersistentObjectClassSegment > PersistentObjectClassSegmentPtr
IceInternal::Handle< PersistentDMPDataSegment > PersistentDMPDataSegmentPtr
IceUtil::Handle< WorkingMemorySnapshotListSegment > WorkingMemorySnapshotListSegmentPtr
IceInternal::Handle< OacMemorySegment > OacMemorySegmentPtr