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 
27 
28 #include <Ice/Ice.h>
29 
30 #include <cstdarg>
31 #include <mutex>
32 
33 template class ::IceInternal::Handle<::armarx::LiteralImpl>;
34 
35 namespace armarx
36 {
38  {
39  CheckIdentifier checkIdentifier;
40  Ice::ObjectPrx myProxy;
41  bool installed;
42  std::mutex accessLock;
43  };
44 
45  // list of parameters version
46  LiteralImpl::LiteralImpl()
47  : impl(new Impl)
48  {
49  this->type = eLiteral;
50  impl->installed = false;
51  }
52 
54  {
55 
56  }
57 
58  LiteralImpl::LiteralImpl(const std::string& dataFieldIdentifierStr, const std::string& checkName, const ParameterList& checkParameters)
59  : LiteralImpl()
60  {
61  init(dataFieldIdentifierStr, checkName, checkParameters);
62  }
63 
64  LiteralImpl::LiteralImpl(const DataFieldIdentifier& dataFieldIdentifier, const std::string& checkName, const ParameterList& checkParameters)
65  : LiteralImpl()
66  {
67  init(dataFieldIdentifier.getIdentifierStr(), checkName, checkParameters);
68  }
69 
70  LiteralImpl::LiteralImpl(const DataFieldIdentifierPtr& dataFieldIdentifier, const std::string& checkName, const ParameterList& checkParameters)
71  : LiteralImpl()
72  {
73  init(dataFieldIdentifier->getIdentifierStr(), checkName, checkParameters);
74  }
75 
76  LiteralImpl::LiteralImpl(const DatafieldRefBasePtr& dataFieldIdentifier, const std::string& checkName, const ParameterList& checkParameters)
77  : LiteralImpl()
78  {
79  DatafieldRefPtr ref = DatafieldRefPtr::dynamicCast(dataFieldIdentifier);
80  init(ref->getDataFieldIdentifier()->getIdentifierStr(), checkName, checkParameters);
81  }
82 
84  {
85 
86  }
87 
88  CheckConfiguration LiteralImpl::getCheckConfiguration(const Ice::Current& c)
89  {
90  return checkConfig;
91  }
92 
93  void LiteralImpl::setValue(bool value, const Ice::Current& c)
94  {
95  this->value = value;
96  update();
97  }
98 
99  void LiteralImpl::setValueAndData(bool value, const DataFieldIdentifierBasePtr& id, const VariantBasePtr& data, const Ice::Current& c)
100  {
101  this->value = value;
102  DataFieldIdentifierPtr dataId = DataFieldIdentifierPtr::dynamicCast(id);
103  datafieldValues = StringVariantBaseMap {{dataId->getIdentifierStr(), data}};
104  updateWithData();
105  }
106 
108  {
109  LiteralImplPtr literal = new LiteralImpl();
110  literal->type = this->type;
111  literal->impl->installed = this->impl->installed;
112  literal->impl->checkIdentifier = this->impl->checkIdentifier;
113  literal->checkConfig = this->checkConfig;
114  literal->impl->myProxy = this->impl->myProxy;
115 
116  return literal;
117  }
118 
119  void LiteralImpl::output(std::ostream& out) const
120  {
121  DataFieldIdentifierPtr dataFieldIdentifier = DataFieldIdentifierPtr::dynamicCast(checkConfig.dataFieldIdentifier);
122 
123  out << checkConfig.checkName << "(";
124 
125  if (dataFieldIdentifier)
126  {
127  out << dataFieldIdentifier;
128  }
129  else
130  {
131  out << "NULL";
132  }
133 
134 
135  ParameterList::const_iterator iter = checkConfig.checkParameters.begin();
136 
137  while (iter != checkConfig.checkParameters.end())
138  {
139  if (iter == checkConfig.checkParameters.begin())
140  {
141  out << ", ";
142  }
143 
144  VariantPtr var = VariantPtr::dynamicCast(*iter);
145 
146  if (var)
147  {
148  out << var;
149  }
150  else
151  {
152  out << "NULL";
153  }
154 
155  iter++;
156 
157  if (iter != checkConfig.checkParameters.end())
158  {
159  out << ",";
160  }
161  }
162 
163  out << ")";
164  }
165 
166  void LiteralImpl::init(const std::string& dataFieldIdentifierStr, const std::string& checkName, const ParameterList& checkParameters)
167  {
168  type = eLiteral;
169 
170  DataFieldIdentifierPtr dataFieldIdentifier = new DataFieldIdentifier(dataFieldIdentifierStr);
171  this->checkConfig.dataFieldIdentifier = dataFieldIdentifier;
172  this->checkConfig.checkName = checkName;
173 
174  ParameterList::const_iterator iter = checkParameters.begin();
175 
176  while (iter != checkParameters.end())
177  {
178  this->checkConfig.checkParameters.push_back(VariantPtr(new Variant(*VariantPtr::dynamicCast(*iter))));
179  iter++;
180  }
181  }
182 
183  void LiteralImpl::installCheck(const Ice::ObjectAdapterPtr& adapter, const ObserverInterfacePrx& proxy)
184  {
185  std::unique_lock lock(impl->accessLock);
186 
187  if (impl->installed)
188  {
189  return;
190  }
191 
192  // register object
193  impl->myProxy = adapter->addWithUUID(this);
194  checkConfig.listener = LiteralImplBasePrx::uncheckedCast(impl->myProxy);
195 
196  // add object to ice
197  impl->checkIdentifier = proxy->installCheck(checkConfig);
198 
199  impl->installed = true;
200  }
201 
202  void LiteralImpl::removeCheck(const Ice::ObjectAdapterPtr& adapter, const ObserverInterfacePrx& proxy)
203  {
204  std::unique_lock lock(impl->accessLock);
205 
206  if (!impl->installed)
207  {
208  return;
209  }
210 
211  // remove check
212  proxy->removeCheck(impl->checkIdentifier);
213 
214  // unregister object
215  adapter->remove(impl->myProxy->ice_getIdentity());
216 
217  impl->installed = false;
218  }
219 }
LiteralImpl.h
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::LiteralImpl::Impl::myProxy
Ice::ObjectPrx myProxy
Definition: LiteralImpl.cpp:40
armarx::LiteralImpl::getCheckConfiguration
CheckConfiguration getCheckConfiguration(const Ice::Current &c=Ice::emptyCurrent) override
Retrieve check configuration.
Definition: LiteralImpl.cpp:88
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::LiteralImpl::init
void init(const std::string &dataFieldIdentifierStr, const std::string &checkName, const ParameterList &checkParameters)
Definition: LiteralImpl.cpp:166
armarx::TermImpl::updateWithData
void updateWithData(const Ice::Current &c=Ice::emptyCurrent) override
Definition: TermImpl.cpp:77
armarx::LiteralImpl
LiteralImpls are the basic elements for defining conditional expressions.
Definition: LiteralImpl.h:59
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::LiteralImpl::ice_clone
Ice::ObjectPtr ice_clone() const override
Reimplementation of the ice_clone method.
Definition: LiteralImpl.cpp:107
armarx::LiteralImpl::setValue
void setValue(bool value, const Ice::Current &c=Ice::emptyCurrent) override
Set value of LiteralImpl.
Definition: LiteralImpl.cpp:93
armarx::LiteralImpl::Impl::installed
bool installed
Definition: LiteralImpl.cpp:41
IceInternal::Handle< DataFieldIdentifier >
DatafieldRef.h
armarx::LiteralImpl::Impl::accessLock
std::mutex accessLock
Definition: LiteralImpl.cpp:42
armarx::VariantPtr
IceInternal::Handle< Variant > VariantPtr
Definition: Variant.h:42
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::LiteralImpl::LiteralImpl
LiteralImpl()
Creates an empty LiteralImpl.
Definition: LiteralImpl.cpp:46
armarx::LiteralImpl::output
void output(std::ostream &out) const override
output to stream.
Definition: LiteralImpl.cpp:119
armarx::LiteralImpl::setValueAndData
void setValueAndData(bool value, const ::armarx::DataFieldIdentifierBasePtr &id, const ::armarx::VariantBasePtr &data, const Ice::Current &c=Ice::emptyCurrent) override
Definition: LiteralImpl.cpp:99
armarx::DataFieldIdentifier::getIdentifierStr
std::string getIdentifierStr() const
Retrieve data field identifier string.
Definition: DataFieldIdentifier.cpp:56
armarx::LiteralImpl::Impl::checkIdentifier
CheckIdentifier checkIdentifier
Definition: LiteralImpl.cpp:39
armarx::LiteralImpl::createInstance
void createInstance()
Definition: LiteralImpl.cpp:83
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::LiteralImpl::Impl
Definition: LiteralImpl.cpp:37
armarx::LiteralImpl::~LiteralImpl
~LiteralImpl()
Definition: LiteralImpl.cpp:53
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TermImpl::update
void update(const Ice::Current &c=Ice::emptyCurrent) override
Updates the parent in the expression tree.
Definition: TermImpl.cpp:69
armarx::DataFieldIdentifier
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
Definition: DataFieldIdentifier.h:48