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
27
37#include <MemoryX/interface/core/EntityBase.h>
38#include <MemoryX/interface/memorytypes/MemoryEntities.h>
39
40namespace memoryx
41{
42 std::string
44 {
45 return "LongtermMemory";
46 }
47
48 void
50 {
51 usingProxy("PriorKnowledge");
52
53 const std::string clsCollNamesStr = getProperty<std::string>("ClassCollections").getValue();
54 classCollNames = armarx::Split(clsCollNamesStr, ",");
55 }
56
57 void
59 {
60 ARMARX_INFO << "connecting long term memory";
61 priorKnowledgePrx = getProxy<PriorKnowledgeInterfacePrx>("PriorKnowledge");
62 const std::string snaplistCollectionName =
63 getProperty<std::string>("SnapshotListCollection").getValue();
64 const std::string oacCollectionName = getProperty<std::string>("OacCollection").getValue();
65 const std::string kbmCollectionName = getProperty<std::string>("KbmCollection").getValue();
66 const std::string dmpCollectionName = getProperty<std::string>("DmpCollection").getValue();
67 const std::string profilerCollectionName =
68 getProperty<std::string>("ProfilerDataCollection").getValue();
69 const std::string resourceProfileCollectionName =
70 getProperty<std::string>("ResourceProfileCollection").getValue();
71 const std::string predictionDataCollectionName =
72 getProperty<std::string>("PredictionDataCollection").getValue();
73 const std::string selfLocalisationCollectionName =
74 getProperty<std::string>("SelfLocalisationCollection").getValue();
75
76 databaseInterfacePrx = storagePrx->requestDatabase(dbName);
77
78 CollectionInterfacePrx snapshotListCollection =
79 databaseInterfacePrx->requestCollection(snaplistCollectionName);
80 CollectionInterfacePrx oacCollection =
81 databaseInterfacePrx->requestCollection(oacCollectionName);
82 CollectionInterfacePrx kbmCollection =
83 databaseInterfacePrx->requestCollection(kbmCollectionName);
84 CollectionInterfacePrx dmpCollection =
85 databaseInterfacePrx->requestCollection(dmpCollectionName);
86
87 WorkingMemorySnapshotListSegmentPtr snapshotListSegment =
88 new WorkingMemorySnapshotListSegment(databaseInterfacePrx, snapshotListCollection, ic);
89 addSegment(LTM::SegmentNames::SNAPSHOTS, snapshotListSegment);
90
91 OacMemorySegmentPtr oacSegment =
92 new OacMemorySegment(priorKnowledgePrx->getObjectClassesSegment(), oacCollection, ic);
93 addSegment(LTM::SegmentNames::OACS, oacSegment);
94
95 PersistentEntitySegmentBasePtr kbmSegment = new KBMSegment(kbmCollection, ic);
96 addSegment(LTM::SegmentNames::KBM, kbmSegment);
97
98 CollectionInterfacePrx profilerCollection =
99 databaseInterfacePrx->requestCollection(profilerCollectionName);
100 addSegment(LTM::SegmentNames::PROFILER,
101 new PersistentProfilerDataSegment(profilerCollection, ic));
102
103 CollectionInterfacePrx resourceProfileCollection =
104 databaseInterfacePrx->requestCollection(resourceProfileCollectionName);
105 addSegment(LTM::SegmentNames::RESOURCE_PROFILES,
106 new PersistentResourceProfileSegment(resourceProfileCollection, ic));
107
108 CollectionInterfacePrx predictionDataCollection =
109 databaseInterfacePrx->requestCollection(predictionDataCollectionName);
110 addSegment(LTM::SegmentNames::PREDICTION_DATA,
111 new PersistentPredictionDataSegment(predictionDataCollection, ic));
112
113 CollectionInterfacePrx classColl = storagePrx->requestCollection(classCollNames[0]);
114 PersistentObjectClassSegmentPtr classesSegment =
115 new PersistentObjectClassSegment(classColl, ic);
116 addSegment(LTM::SegmentNames::OBJECTCLASSES, classesSegment);
117
118 PersistentDMPDataSegmentPtr dmpSegment = new PersistentDMPDataSegment(dmpCollection, ic);
119 addSegment(LTM::SegmentNames::DMP, dmpSegment);
120
121 CollectionInterfacePrx selfLocalisationCollection =
122 databaseInterfacePrx->requestCollection(selfLocalisationCollectionName);
123 PersistentEntitySegmentPtr selfLocalisationSegment =
124 new PersistentEntitySegment(selfLocalisationCollection, ic);
125 addSegment(LTM::SegmentNames::SELF_LOCALISATION, selfLocalisationSegment);
126
127 ARMARX_INFO << "successfully connected long term memory";
128 }
129
130 WorkingMemorySnapshotListSegmentBasePrx
132 {
133 return WorkingMemorySnapshotListSegmentBasePrx::uncheckedCast(
134 getSegment(LTM::SegmentNames::SNAPSHOTS, c));
135 }
136
137 PersistentObjectInstanceSegmentBasePrx
138 LongtermMemory::getCustomInstancesSegment(const std::string& segmentName,
139 bool createIfMissing,
140 const ::Ice::Current& c)
141 {
142 if (hasSegment(segmentName))
143 {
144 return PersistentObjectInstanceSegmentBasePrx::uncheckedCast(
145 getSegment(segmentName, c));
146 }
147 else if (createIfMissing)
148 {
150 databaseInterfacePrx->requestCollection(segmentName), ic);
151 return PersistentObjectInstanceSegmentBasePrx::uncheckedCast(
152 addSegment(segmentName, customSegment, c));
153 }
154 else
155 {
156 return PersistentObjectInstanceSegmentBasePrx();
157 }
158 }
159
160 void
162 const std::string& snapshotName,
163 const AbstractWorkingMemoryInterfacePrx& workingMemory,
164 const ::Ice::Current&)
165 {
166 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
168
169 if (snapshotListSegment)
170 {
171 snapshotListSegment->loadSnapshot(snapshotName, workingMemory);
172 }
173 }
174
175 bool
177 const std::string& snapshotName,
178 const AbstractWorkingMemoryInterfacePrx& workingMemory,
179 const ::Ice::Current&)
180 {
181 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
183
184 if (snapshotListSegment)
185 {
186 return snapshotListSegment->createSnapshot(snapshotName, workingMemory);
187 }
188 else
189 {
190 return false;
191 }
192 }
193
194 WorkingMemorySnapshotInterfacePrx
195 LongtermMemory::openWorkingMemorySnapshot(const std::string& snapshotName,
196 const ::Ice::Current&)
197 {
198 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
200
201 if (snapshotListSegment)
202 {
203 return snapshotListSegment->openSnapshot(snapshotName);
204 }
205 else
206 {
207 return WorkingMemorySnapshotInterfacePrx();
208 }
209 }
210
211 bool
212 LongtermMemory::removeWorkingMemorySnapshot(const std::string& snapshotName,
213 const ::Ice::Current&)
214 {
215 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
217
218 if (snapshotListSegment)
219 {
220 return snapshotListSegment->removeSnapshot(snapshotName);
221 }
222 else
223 {
224 return false;
225 }
226 }
227
228 NameList
229 LongtermMemory::getSnapshotNames(const ::Ice::Current& c)
230 {
231 WorkingMemorySnapshotListSegmentBasePrx snapshotListSegment =
233
234 if (snapshotListSegment)
235 {
236 return snapshotListSegment->getSnapshotNames();
237 }
238 else
239 {
240 throw SnapshotNotFoundException("Snapshot segment not found!", "");
241 }
242 }
243
244 std::string
245 LongtermMemory::getMemoryName(const Ice::Current&) const
246 {
247 return getName();
248 }
249
250 PersistentProfilerDataSegmentBasePrx
252 {
253 return PersistentProfilerDataSegmentBasePrx::uncheckedCast(
254 getSegment(LTM::SegmentNames::PROFILER, c));
255 }
256
257 PersistentPredictionDataSegmentBasePrx
259 {
260 return PersistentPredictionDataSegmentBasePrx::uncheckedCast(
261 getSegment(LTM::SegmentNames::PREDICTION_DATA, c));
262 }
263
264 PersistentResourceProfileSegmentBasePrx
266 {
267 return PersistentResourceProfileSegmentBasePrx::uncheckedCast(
268 getSegment(LTM::SegmentNames::RESOURCE_PROFILES, c));
269 }
270
271 OacMemorySegmentBasePrx
272 LongtermMemory::getOacSegment(const ::Ice::Current& c)
273 {
274 return OacMemorySegmentBasePrx::uncheckedCast(getSegment(LTM::SegmentNames::OACS, c));
275 }
276
277 KBMSegmentBasePrx
278 LongtermMemory::getKBMSegment(const Ice::Current& c)
279 {
280 return KBMSegmentBasePrx::uncheckedCast(getSegment(LTM::SegmentNames::KBM, c));
281 }
282
283 CommonStorageInterfacePrx
284 LongtermMemory::getCommonStorage(const ::Ice::Current&) const
285 {
286 return storagePrx;
287 }
288
289 PersistentObjectClassSegmentBasePrx
290 LongtermMemory::getObjectClassesSegment(const ::Ice::Current& c) const
291 {
292 return PersistentObjectClassSegmentBasePrx::uncheckedCast(
293 getSegment(LTM::SegmentNames::OBJECTCLASSES, c));
294 }
295
296 PersistentDMPDataSegmentBasePrx
297 LongtermMemory::getDMPSegment(const Ice::Current& c)
298 {
299 return PersistentDMPDataSegmentBasePrx::uncheckedCast(
300 getSegment(LTM::SegmentNames::DMP, c));
301 }
302
303 PersistentEntitySegmentBasePrx
305 {
306 return PersistentEntitySegmentBasePrx::uncheckedCast(
307 getSegment(LTM::SegmentNames::SELF_LOCALISATION, c));
308 }
309
310 AbstractMemorySegmentPrx
311 memoryx::LongtermMemory::addGenericSegment(const std::string& segmentName, const Ice::Current&)
312 {
314 new PersistentEntitySegment(databaseInterfacePrx->requestCollection(segmentName),
316 return addSegment(segmentName, segment);
317 }
318} // namespace memoryx
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
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
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