LiteralImpl.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5*
6* ArmarX is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* ArmarX is distributed in the hope that it will be useful, but
11* WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* @package ArmarX::Core
19* @author Kai Welke (welke _at_ kit _dot_ edu)
20* @date 2012
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24
25#include <cstdarg>
26#include <mutex>
27
28#include <Ice/Ice.h>
29
32
33template class ::IceInternal::Handle<::armarx::LiteralImpl>;
34
35namespace armarx
36{
38 {
39 CheckIdentifier checkIdentifier;
40 Ice::ObjectPrx myProxy;
42 std::mutex accessLock;
43 };
44
45 // list of parameters version
47 {
48 this->type = eLiteral;
49 impl->installed = false;
50 }
51
55
56 LiteralImpl::LiteralImpl(const std::string& dataFieldIdentifierStr,
57 const std::string& checkName,
58 const ParameterList& checkParameters) :
60 {
61 init(dataFieldIdentifierStr, checkName, checkParameters);
62 }
63
65 const std::string& checkName,
66 const ParameterList& checkParameters) :
68 {
69 init(dataFieldIdentifier.getIdentifierStr(), checkName, checkParameters);
70 }
71
73 const std::string& checkName,
74 const ParameterList& checkParameters) :
76 {
77 init(dataFieldIdentifier->getIdentifierStr(), checkName, checkParameters);
78 }
79
80 LiteralImpl::LiteralImpl(const DatafieldRefBasePtr& dataFieldIdentifier,
81 const std::string& checkName,
82 const ParameterList& checkParameters) :
84 {
85 DatafieldRefPtr ref = DatafieldRefPtr::dynamicCast(dataFieldIdentifier);
86 init(ref->getDataFieldIdentifier()->getIdentifierStr(), checkName, checkParameters);
87 }
88
89 void
93
94 CheckConfiguration
96 {
97 return checkConfig;
98 }
99
100 void
101 LiteralImpl::setValue(bool value, const Ice::Current& c)
102 {
103 this->value = value;
104 update();
105 }
106
107 void
110 const VariantBasePtr& data,
111 const Ice::Current& c)
112 {
113 this->value = value;
114 DataFieldIdentifierPtr dataId = DataFieldIdentifierPtr::dynamicCast(id);
115 datafieldValues = StringVariantBaseMap{{dataId->getIdentifierStr(), data}};
117 }
118
119 Ice::ObjectPtr
121 {
122 LiteralImplPtr literal = new LiteralImpl();
123 literal->type = this->type;
124 literal->impl->installed = this->impl->installed;
125 literal->impl->checkIdentifier = this->impl->checkIdentifier;
126 literal->checkConfig = this->checkConfig;
127 literal->impl->myProxy = this->impl->myProxy;
128
129 return literal;
130 }
131
132 void
133 LiteralImpl::output(std::ostream& out) const
134 {
135 DataFieldIdentifierPtr dataFieldIdentifier =
136 DataFieldIdentifierPtr::dynamicCast(checkConfig.dataFieldIdentifier);
137
138 out << checkConfig.checkName << "(";
139
140 if (dataFieldIdentifier)
141 {
142 out << dataFieldIdentifier;
143 }
144 else
145 {
146 out << "NULL";
147 }
148
149
150 ParameterList::const_iterator iter = checkConfig.checkParameters.begin();
151
152 while (iter != checkConfig.checkParameters.end())
153 {
154 if (iter == checkConfig.checkParameters.begin())
155 {
156 out << ", ";
157 }
158
159 VariantPtr var = VariantPtr::dynamicCast(*iter);
160
161 if (var)
162 {
163 out << var;
164 }
165 else
166 {
167 out << "NULL";
168 }
169
170 iter++;
171
172 if (iter != checkConfig.checkParameters.end())
173 {
174 out << ",";
175 }
176 }
177
178 out << ")";
179 }
180
181 void
182 LiteralImpl::init(const std::string& dataFieldIdentifierStr,
183 const std::string& checkName,
184 const ParameterList& checkParameters)
185 {
186 type = eLiteral;
187
188 DataFieldIdentifierPtr dataFieldIdentifier =
189 new DataFieldIdentifier(dataFieldIdentifierStr);
190 this->checkConfig.dataFieldIdentifier = dataFieldIdentifier;
191 this->checkConfig.checkName = checkName;
192
193 ParameterList::const_iterator iter = checkParameters.begin();
194
195 while (iter != checkParameters.end())
196 {
197 this->checkConfig.checkParameters.push_back(
198 VariantPtr(new Variant(*VariantPtr::dynamicCast(*iter))));
199 iter++;
200 }
201 }
202
203 void
204 LiteralImpl::installCheck(const Ice::ObjectAdapterPtr& adapter,
205 const ObserverInterfacePrx& proxy)
206 {
207 std::unique_lock lock(impl->accessLock);
208
209 if (impl->installed)
210 {
211 return;
212 }
213
214 // register object
215 impl->myProxy = adapter->addWithUUID(this);
216 checkConfig.listener = LiteralImplBasePrx::uncheckedCast(impl->myProxy);
217
218 // add object to ice
219 impl->checkIdentifier = proxy->installCheck(checkConfig);
220
221 impl->installed = true;
222 }
223
224 void
225 LiteralImpl::removeCheck(const Ice::ObjectAdapterPtr& adapter,
226 const ObserverInterfacePrx& proxy)
227 {
228 std::unique_lock lock(impl->accessLock);
229
230 if (!impl->installed)
231 {
232 return;
233 }
234
235 // remove check
236 proxy->removeCheck(impl->checkIdentifier);
237
238 // unregister object
239 adapter->remove(impl->myProxy->ice_getIdentity());
240
241 impl->installed = false;
242 }
243} // namespace armarx
constexpr T c
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
std::string getIdentifierStr() const
Retrieve data field identifier string.
void output(std::ostream &out) const override
output to stream.
CheckConfiguration getCheckConfiguration(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve check configuration.
LiteralImpl()
Creates an empty LiteralImpl.
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
void init(const std::string &dataFieldIdentifierStr, const std::string &checkName, const ParameterList &checkParameters)
void setValueAndData(bool value, const ::armarx::DataFieldIdentifierBasePtr &id, const ::armarx::VariantBasePtr &data, const Ice::Current &c=Ice::emptyCurrent) override
void setValue(bool value, const Ice::Current &c=Ice::emptyCurrent) override
Set value of LiteralImpl.
void update(const Ice::Current &c=Ice::emptyCurrent) override
Updates the parent in the expression tree.
Definition TermImpl.cpp:76
void updateWithData(const Ice::Current &c=Ice::emptyCurrent) override
Definition TermImpl.cpp:85
The Variant class is described here: Variants.
Definition Variant.h:224
::IceInternal::Handle<::Ice::ObjectAdapter > ObjectAdapterPtr
Definition IceManager.h:52
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceInternal::Handle< DataFieldIdentifierBase > DataFieldIdentifierBasePtr
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.
IceInternal::Handle< LiteralImpl > LiteralImplPtr
Typedef of LiteralImplPtr as IceInternal::Handle<LiteralImpl> for convenience.
CheckIdentifier checkIdentifier