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 
32 
33 #include <IceUtil/Exception.h>
34 
35 #include <algorithm>
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  }
50 
51  DatafieldRef::DatafieldRef(Observer* observer, const std::string& channelName, const std::string& datafieldName, bool performValidation)
52  {
53  channelRef = new ChannelRef(observer, channelName);
54  this->datafieldName = datafieldName;
55 
56  if (performValidation)
57  if (!validate())
58  {
59  ARMARX_WARNING_S << "Could not validate ChannelRef for " << getDataFieldIdentifier()->getIdentifierStr();
60  }
61  }
62 
63  DatafieldRef::DatafieldRef(ObserverInterfacePrx observerPrx, const std::string& channelName, const std::string& datafieldName, bool performValidation)
64  {
65  channelRef = new ChannelRef(observerPrx, channelName);
66  this->datafieldName = datafieldName;
67 
68  if (performValidation)
69  if (!validate())
70  {
71  ARMARX_WARNING_S << "Could not validate ChannelRef for " << getDataFieldIdentifier()->getIdentifierStr();
72  }
73  }
74 
75  DatafieldRef::DatafieldRef(ChannelRefPtr channelRef, const std::string& datafieldName, bool performValidation)
76  {
77  if (!channelRef)
78  {
79  throw exceptions::local::eNullPointerException("ChannelRef must not be NULL");
80  }
81 
82  this->channelRef = channelRef;
83  this->datafieldName = datafieldName;
84 
85  if (performValidation)
86  if (!validate())
87  {
88  ARMARX_WARNING_S << "Could not validate ChannelRef for " << getDataFieldIdentifier()->getIdentifierStr();
89  }
90  }
91 
93  {
94  return this->clone();
95  }
96 
97  // *******************************************************
98  // Datafield access
99  // *******************************************************
101  {
102  if (!id)
103  {
104  id = getChannelRef()->getDataFieldIdentifier(datafieldName);
105  }
106 
107  return id;
108  }
109 
111  {
112  return getChannelRef()->getDataField(datafieldName);
113  }
114 
115 
117  {
118  return ChannelRefPtr::dynamicCast(channelRef);
119  }
120 
121 
122  // *******************************************************
123  // Inherited from VariantDataClass
124  // *******************************************************
125  VariantDataClassPtr DatafieldRef::clone(const Ice::Current& c) const
126  {
127  DatafieldRefPtr dfr = new DatafieldRef(*this);
128 
129  return dfr;
130  }
131 
132  std::string DatafieldRef::output(const Ice::Current& c) const
133  {
134  std::stringstream s;
135  s << "Reference to datafield " << DataFieldIdentifierPtr::dynamicCast(getDataFieldIdentifier())->getIdentifierStr();
136 
137  return s.str();
138  }
139 
140  VariantTypeId DatafieldRef::getType(const Ice::Current& c) const
141  {
143  }
144 
145  bool DatafieldRef::validate(const Ice::Current& c)
146  {
147 
148  if (!getChannelRef())
149  {
150  return false;
151  }
152 
153  if (!getChannelRef()->hasDatafield(datafieldName))
154  {
155  return false;
156  }
157 
158  if (!getChannelRef()->getDataField(datafieldName)->getInitialized())
159  {
160  return false;
161  }
162 
163  return true;
164  }
165 
166  void DatafieldRef::serialize(const ObjectSerializerBasePtr& serializer, const ::Ice::Current&) const
167  {
168  AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
169 
170  channelRef->serialize(serializer);
171  obj->setString("datafieldName", datafieldName);
172  }
173 
174  void DatafieldRef::deserialize(const ObjectSerializerBasePtr& serializer, const ::Ice::Current& c)
175  {
176  AbstractObjectSerializerPtr obj = AbstractObjectSerializerPtr::dynamicCast(serializer);
177 
178  channelRef->deserialize(serializer, c);
179  datafieldName = obj->getString("datafieldName");
180  }
181 }
armarx::DatafieldRef::deserialize
void deserialize(const ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: DatafieldRef.cpp:174
armarx::DatafieldRef::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:132
armarx::Observer
Baseclass for all ArmarX Observers.
Definition: Observer.h:80
armarx::DatafieldRef::getType
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:140
armarx::DatafieldRef::clone
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:125
AbstractObjectSerializer.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::exceptions::local::eNullPointerException
Definition: Exception.h:42
armarx::DatafieldRef::serialize
void serialize(const ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: DatafieldRef.cpp:166
IceInternal::Handle< ChannelRef >
DatafieldRef.h
armarx::exceptions::local
Definition: DynamicLibraryException.h:31
armarx::DatafieldRef::getDataFieldIdentifier
DataFieldIdentifierPtr getDataFieldIdentifier() const
Definition: DatafieldRef.cpp:100
armarx::VariantType::ChannelRef
const VariantTypeId ChannelRef
Definition: ChannelRef.h:162
armarx::DatafieldRef::getDataField
TimedVariantPtr getDataField() const
Retrieves the value of the datafield from the Observer.
Definition: DatafieldRef.cpp:110
ProxyNotInitializedException.h
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::DatafieldRef::getChannelRef
ChannelRefPtr getChannelRef() const
Definition: DatafieldRef.cpp:116
InvalidDataFieldException.h
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::VariantType::DatafieldRef
const VariantTypeId DatafieldRef
Definition: DatafieldRef.h:169
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:92
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:28
armarx::DatafieldRef::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: DatafieldRef.cpp:145