34 #include <Ice/ObjectAdapter.h>
35 #include <Ice/ValueFactory.h>
39 template class ::IceInternal::Handle<::armarx::ChannelRef>;
49 validationTimeout(4000),
58 this->observerProxy = ObserverInterfacePrx::uncheckedCast(observer->
getProxy());
59 this->communicator = observerProxy->ice_getCommunicator();
60 this->observerName = observer->
getName();
61 this->channelName = channelName;
64 initializeDataFields(observer);
68 validationTimeout(4000),
76 this->observerProxy = observerPrx;
77 this->observerName = observerPrx->ice_getIdentity().name;
78 this->channelName = channelName;
79 this->communicator = observerProxy->ice_getCommunicator();
82 initializeDataFields();
95 if (std::find(datafieldNames.begin(), datafieldNames.end(), datafieldName) == datafieldNames.end())
99 if (std::find(datafieldNames.begin(), datafieldNames.end(), datafieldName) == datafieldNames.end())
117 result = TimedVariantPtr::dynamicCast(observerProxy->getDatafieldByName(
getChannelName(), datafieldName));
123 observerProxy = ObserverInterfacePrx::uncheckedCast(communicator->stringToProxy(observerName));
124 result = TimedVariantPtr::dynamicCast(observerProxy->getDatafieldByName(
getChannelName(), datafieldName));
144 return observerProxy;
159 return datafieldNames;
164 for (
unsigned int i = 0; i < datafieldNames.size(); ++i)
166 if (datafieldName == datafieldNames.at(i))
196 initializeDataFields();
207 cln->initialized = this->initialized;
209 cln->observerName = this->observerName;
210 cln->channelName = this->channelName;
211 cln->datafieldNames = this->datafieldNames;
213 cln->observerProxy = this->observerProxy;
221 s <<
"Reference to channel " << channelName <<
" on observer " << observerName;
233 int validateWaitIntervallMs = waitIntervallMs;
236 IceUtil::Time timeout = IceUtil::Time::milliSeconds(validationTimeout);
240 while (
IceUtil::Time(waitStartTime + timeout - IceUtil::Time::now()).toMilliSeconds() > 0)
247 if (
IceUtil::Time(IceUtil::Time::now() - lastOutput).toSeconds() >= 1)
250 lastOutput = IceUtil::Time::now();
253 usleep(validateWaitIntervallMs * 1000);
255 if (validateWaitIntervallMs < validationTimeout * 0.5f)
257 validateWaitIntervallMs *= 2;
267 bool ChannelRef::assureProxy()
273 observerProxy = ObserverInterfacePrx::checkedCast(communicator->stringToProxy(observerName));
280 if (observerProxy && !initialized)
282 initializeDataFields();
285 return (observerProxy != 0);
288 void ChannelRef::initializeDataFields(Observer* obs)
290 ChannelRegistryEntry channel = obs ?
294 DataFieldRegistry::const_iterator iterData = channel.dataFields.begin();
295 datafieldNames.clear();
297 while (iterData != channel.dataFields.end())
299 datafieldNames.push_back(iterData->second.identifier->datafieldName);
303 initialized = channel.initialized;
310 communicator = observerProxy->ice_getCommunicator();
318 obj->setString(
"observerName", observerName);
319 obj->setString(
"channelName", channelName);
326 observerName = obj->getString(
"observerName");
327 channelName = obj->getString(
"channelName");
331 throw LocalException(
"The adapter in the Ice::current object must be set to load a ChannelRef from XML");
334 communicator =
c.adapter->getCommunicator();