PriorKnowledge.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::PriorKnowledge
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#include "PriorKnowledge.h"
24
25#include <IceUtil/UUID.h>
26
27#include <SimoxUtility/algorithm/string/string_tools.h>
28
29#include <ArmarXCore/interface/core/Log.h>
30
38
39
40#define PRIOR_SEGMENT_NAME_CLASSES "classes"
41#define PRIOR_SEGMENT_NAME_RELATIONS "relations"
42#define PRIOR_SEGMENT_NAME_GRAPH "graphs"
43
44namespace memoryx
45{
46 void
48 {
49 usingProxy("CommonStorage");
50
51 const std::string clsCollNamesStr = getProperty<std::string>("ClassCollections").getValue();
52 classCollNames = simox::alg::split(clsCollNamesStr, ",");
53
54 const std::string relCollNamesStr =
55 getProperty<std::string>("RelationCollections").getValue();
56 relationCollNames = simox::alg::split(relCollNamesStr, ",");
57
58 const std::string graphCollNamesStr =
59 getProperty<std::string>("GraphCollections").getValue();
60 graphCollNames = simox::alg::split(graphCollNamesStr, ",");
61 }
62
63 void
65 {
66 ARMARX_INFO << "Starting MemoryX::PriorKnowledge";
67
68 const Ice::CommunicatorPtr ic = getIceManager()->getCommunicator();
69
71
72 CollectionInterfacePrx writeClassColl = dataBasePrx->requestCollection(classCollNames[0]);
73 PersistentObjectClassSegmentPtr classesSegment =
74 new PersistentObjectClassSegment(writeClassColl, ic);
77
78 if (relationCollNames.size() > 0 && !relationCollNames[0].empty())
79 {
80 CollectionInterfacePrx writeRelationColl =
81 dataBasePrx->requestCollection(relationCollNames[0]);
82 PersistentRelationSegmentPtr relationsSegment =
83 new PersistentRelationSegment(writeRelationColl, ic);
86 }
87
88 if (graphCollNames.size() > 0 && !graphCollNames[0].empty())
89 {
90 ARMARX_INFO << "Adding segments: " << graphCollNames;
91 CollectionInterfacePrx graphClassColl =
92 dataBasePrx->requestCollection(graphCollNames[0]);
93 GraphMemorySegmentPtr graphSegment{new GraphMemorySegment{graphClassColl, ic}};
96 }
97 }
98
99 PersistentObjectClassSegmentBasePrx
100 PriorKnowledge::getObjectClassesSegment(const ::Ice::Current& c) const
101 {
102 return PersistentObjectClassSegmentBasePrx::uncheckedCast(
104 }
105
106 PersistentRelationSegmentBasePrx
107 PriorKnowledge::getRelationsSegment(const ::Ice::Current& c) const
108 {
109 return PersistentRelationSegmentBasePrx::uncheckedCast(
111 }
112
113 GraphMemorySegmentBasePrx
114 PriorKnowledge::getGraphSegment(const ::Ice::Current& c) const
115 {
116 return GraphMemorySegmentBasePrx::uncheckedCast(getSegment(PRIOR_SEGMENT_NAME_GRAPH, c));
117 }
118
119 bool
120 PriorKnowledge::hasGraphSegment(const Ice::Current& c) const
121 {
123 }
124
125 CommonStorageInterfacePrx
126 PriorKnowledge::getCommonStorage(const ::Ice::Current&) const
127 {
128 return dataBasePrx;
129 }
130
131 bool
132 PriorKnowledge::isPriorCollection(const ::std::string& collNS, const ::Ice::Current&)
133 {
134 const size_t found = collNS.find_first_of('.');
135 if (found == std::string::npos)
136 {
137 return false;
138 }
139 std::string postfix = collNS.substr(found + 1, std::string::npos);
140 return simox::alg::starts_with(postfix, PRIOR_COLLECTION_PREFIX);
141 }
142
143 void
144 PriorKnowledge::clear(const ::Ice::Current&)
145 {
146 throw armarx::NotImplementedYetException();
147 }
148
149 void
150 PriorKnowledge::setSegmentReadCollections(const PersistentEntitySegmentBasePtr& segmentPrx,
151 const NameList& collNameList)
152 {
153 ARMARX_INFO << "Setting read collections";
154 segmentPrx->clearReadCollections();
155
156 for (memoryx::NameList::const_iterator it = collNameList.begin(); it != collNameList.end();
157 ++it)
158 {
159 ARMARX_INFO << "Adding collection " << *it;
160 CollectionInterfacePrx readColl = dataBasePrx->requestCollection(*it);
161
162 if (!readColl)
163 {
164 ARMARX_ERROR << " Could not find collection with name " << *it << std::endl;
165 }
166 else
167 {
168 segmentPrx->addReadCollection(readColl);
169 }
170 }
171 }
172
173 std::string
174 PriorKnowledge::getMemoryName(const Ice::Current&) const
175 {
176 return getName();
177 }
178
179 AbstractMemorySegmentPrx
180 PriorKnowledge::addGenericSegment(const std::string& segmentName, const Ice::Current&)
181 {
183 dataBasePrx->requestCollection(segmentName), getIceManager()->getCommunicator());
184 return addSegment(segmentName, segment);
185 }
186} // namespace memoryx
#define PRIOR_SEGMENT_NAME_RELATIONS
#define PRIOR_SEGMENT_NAME_GRAPH
#define PRIOR_SEGMENT_NAME_CLASSES
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
The Graph Memory Segment contains directed graphs.
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.
void onInitComponent() override
Pure virtual hook for the subclass.
CommonStorageInterfacePrx dataBasePrx
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
PersistentRelationSegmentBasePrx getRelationsSegment(const ::Ice::Current &=Ice::emptyCurrent) const override
GraphMemorySegmentBasePrx getGraphSegment(const ::Ice::Current &c=Ice::emptyCurrent) const override
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &=Ice::emptyCurrent) const override
void setSegmentReadCollections(const PersistentEntitySegmentBasePtr &segmentPrx, const NameList &collNameList)
bool isPriorCollection(const ::std::string &collNS, const ::Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
Pure virtual hook for the subclass.
std::string getMemoryName(const Ice::Current &) const override
bool hasGraphSegment(const Ice::Current &c=Ice::emptyCurrent) const override
PersistentObjectClassSegmentBasePrx getObjectClassesSegment(const ::Ice::Current &=Ice::emptyCurrent) const override
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
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
VirtualRobot headers.
IceUtil::Handle< PersistentEntitySegment > PersistentEntitySegmentPtr
IceInternal::Handle< PersistentObjectClassSegment > PersistentObjectClassSegmentPtr
IceInternal::Handle< PersistentRelationSegment > PersistentRelationSegmentPtr
IceInternal::Handle< GraphMemorySegment > GraphMemorySegmentPtr