DatafieldRef.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@kit.edu)
20 * @date 2012 Kai Welke
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #include "DatafieldRef.h"
26 
27 #include <algorithm>
28 
29 #include <IceUtil/Exception.h>
30 
36 
37 template class ::IceInternal::Handle<::armarx::DatafieldRef>;
38 
39 namespace armarx
40 {
41  using namespace armarx::exceptions::local;
42 
43  // *******************************************************
44  // Construction / destruction
45  // *******************************************************
47  {
48  }
49 
51  const std::string& channelName,
52  const std::string& datafieldName,
53  bool performValidation)
54  {
55  channelRef = new ChannelRef(observer, channelName);
56  this->datafieldName = datafieldName;
57 
58  if (performValidation)
59  if (!validate())
60  {
61  ARMARX_WARNING_S << "Could not validate ChannelRef for "
62  << getDataFieldIdentifier()->getIdentifierStr();
63  }
64  }
65 
66  DatafieldRef::DatafieldRef(ObserverInterfacePrx observerPrx,
67  const std::string& channelName,
68  const std::string& datafieldName,
69  bool performValidation)
70  {
71  channelRef = new ChannelRef(observerPrx, channelName);
72  this->datafieldName = datafieldName;
73 
74  if (performValidation)
75  if (!validate())
76  {
77  ARMARX_WARNING_S << "Could not validate ChannelRef for "
78  << getDataFieldIdentifier()->getIdentifierStr();
79  }
80  }
81 
83  const std::string& datafieldName,
84  bool performValidation)
85  {
86  if (!channelRef)
87  {
88  throw exceptions::local::eNullPointerException("ChannelRef must not be NULL");
89  }
90 
91  this->channelRef = channelRef;
92  this->datafieldName = datafieldName;
93 
94  if (performValidation)
95  if (!validate())
96  {
97  ARMARX_WARNING_S << "Could not validate ChannelRef for "
98  << getDataFieldIdentifier()->getIdentifierStr();
99  }
100  }
101 
104  {
105  return this->clone();
106  }
107 
108  // *******************************************************
109  // Datafield access
110  // *******************************************************
113  {
114  if (!id)
115  {
116  id = getChannelRef()->getDataFieldIdentifier(datafieldName);
117  }
118 
119  return id;
120  }
121 
124  {
125  return getChannelRef()->getDataField(datafieldName);
126  }
127 
130  {
131  return ChannelRefPtr::dynamicCast(channelRef);
132  }
133 
134  // *******************************************************
135  // Inherited from VariantDataClass
136  // *******************************************************
137  VariantDataClassPtr
138  DatafieldRef::clone(const Ice::Current& c) const
139  {
140  DatafieldRefPtr dfr = new DatafieldRef(*this);
141 
142  return dfr;
143  }
144 
145  std::string
146  DatafieldRef::output(const Ice::Current& c) const
147  {
148  std::stringstream s;
149  s << "Reference to datafield "
150  << DataFieldIdentifierPtr::dynamicCast(getDataFieldIdentifier())->getIdentifierStr();
151 
152  return s.str();
153  }
154 
156  DatafieldRef::getType(const Ice::Current& c) const
157  {
159  }
160 
161  bool
162  DatafieldRef::validate(const Ice::Current& c)
163  {
164 
165  if (!getChannelRef())
166  {
167  return false;
168  }
169 
170  if (!getChannelRef()->hasDatafield(datafieldName))
171  {
172  return false;
173  }
174 
175  if (!getChannelRef()->getDataField(datafieldName)->getInitialized())
176  {
177  return false;
178  }
179 
180  return true;
181  }
182 
183  void
184  DatafieldRef::serialize(const ObjectSerializerBasePtr& serializer, const ::Ice::Current&) const
185  {
186  AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
187 
188  channelRef->serialize(serializer);
189  obj->setString("datafieldName", datafieldName);
190  }
191 
192  void
193  DatafieldRef::deserialize(const ObjectSerializerBasePtr& serializer, const ::Ice::Current& c)
194  {
195  AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
196 
197  channelRef->deserialize(serializer, c);
198  datafieldName = obj->getString("datafieldName");
199  }
200 } // namespace armarx
armarx::DatafieldRef::deserialize
void deserialize(const ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DatafieldRef.cpp:193
armarx::DatafieldRef::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:146
armarx::Observer
Baseclass for all ArmarX Observers.
Definition: Observer.h:84
armarx::DatafieldRef::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:156
armarx::DatafieldRef::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:138
AbstractObjectSerializer.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::exceptions::local::eNullPointerException
Definition: Exception.h:49
armarx::DatafieldRef::serialize
void serialize(const ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:184
IceInternal::Handle< ChannelRef >
DatafieldRef.h
armarx::exceptions::local
Definition: DynamicLibraryException.h:31
armarx::DatafieldRef::getDataFieldIdentifier
DataFieldIdentifierPtr getDataFieldIdentifier() const
Definition: DatafieldRef.cpp:112
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:169
armarx::DatafieldRef::getDataField
TimedVariantPtr getDataField() const
Retrieves the value of the datafield from the Observer.
Definition: DatafieldRef.cpp:123
ProxyNotInitializedException.h
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:43
armarx::DatafieldRef::getChannelRef
ChannelRefPtr getChannelRef() const
Definition: DatafieldRef.cpp:129
InvalidDataFieldException.h
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
armarx::VariantType::DatafieldRef
const VariantTypeId DatafieldRef
Definition: DatafieldRef.h:197
armarx::navigation::client::validate
void validate(const std::vector< WaypointTarget > &path)
Definition: ice_conversions.h:70
armarx::DatafieldRef::DatafieldRef
DatafieldRef()
Definition: DatafieldRef.cpp:46
armarx::DatafieldRef::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: DatafieldRef.cpp:103
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
Logging.h
Exception.h
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::DatafieldRef::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: DatafieldRef.cpp:162