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
37template class ::IceInternal::Handle<::armarx::DatafieldRef>;
38
39namespace armarx
40{
41 using namespace armarx::exceptions::local;
42
43 // *******************************************************
44 // Construction / destruction
45 // *******************************************************
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
102 Ice::ObjectPtr
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
constexpr T c
The ChannelRef class is a reference to a channel on an Observer.
Definition ChannelRef.h:51
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
TimedVariantPtr getDataField() const
Retrieves the value of the datafield from the Observer.
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
ChannelRefPtr getChannelRef() const
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
DataFieldIdentifierPtr getDataFieldIdentifier() const
void deserialize(const ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
Ice::ObjectPtr ice_clone() const override
void serialize(const ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Baseclass for all ArmarX Observers.
Definition Observer.h:87
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
const VariantTypeId DatafieldRef
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< TimedVariant > TimedVariantPtr
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< AbstractObjectSerializer > AbstractObjectSerializerPtr
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
Ice::Int VariantTypeId
Definition Variant.h:43
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.