orca-robotics INTRODUCTION Overview Download and Install Quick Start Documentation Publications REPOSITORY Interfaces Components Libraries Utilities Software Map DEVELOPER Tutorials Examples Dev Guide Dashboard Wiki login/pass: orca/orca PEOPLE Contributors Users Project Download Mailing lists
|
multiconnectutils.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef ORCAICE_MULTI_CONNECT_UTILITIES_H 00012 #define ORCAICE_MULTI_CONNECT_UTILITIES_H 00013 00014 #include <orcaice/connectutils.h> 00015 #include <gbxsickacfr/gbxiceutilacfr/safethread.h> 00016 #include <IceUtil/Thread.h> 00017 00018 namespace orcaice 00019 { 00024 00039 void createInterfaceWithString( const Context & context, 00040 Ice::ObjectPtr & object, 00041 const std::string & name, 00042 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00043 int retryInterval=2, int retryNumber=-1 ); 00044 00067 void createInterfaceWithTag( const Context & context, 00068 Ice::ObjectPtr & object, 00069 const std::string & interfaceTag, 00070 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00071 int retryInterval=2, int retryNumber=-1 ); 00072 00082 // note: Context::activate() is not a const function, that's why a ref to it is not const. 00083 void activate( Context& context, 00084 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00085 int retryInterval=2, int retryNumber=-1 ); 00086 00110 template<class ProxyType> 00111 void 00112 connectToInterfaceWithString( const Context & context, 00113 ProxyType & proxy, 00114 const std::string & proxyString, 00115 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00116 int retryInterval=2, int retryNumber=-1 ) 00117 { 00118 context.tracer().debug( "orcaice::connectToInterfaceWithString(thread) proxy="+proxyString, 10 ); 00119 int count = 0; 00120 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00121 { 00122 try { 00123 connectToInterfaceWithString<ProxyType>( context, proxy, proxyString ); 00124 break; 00125 } 00126 catch ( const orcaice::NetworkException& e ) { 00127 std::stringstream ss; 00128 ss << "Failed to connect to interface with string "<<proxyString<<". " 00129 <<"Will retry in "<<retryInterval<<"s." 00130 << e.what(); 00131 context.tracer().warning( ss.str() ); 00132 } 00133 ++count; 00134 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00135 if ( !subsysName.empty() ) { 00136 context.status().heartbeat( subsysName ); 00137 } 00138 } 00139 } 00140 00169 template<class ProxyType> 00170 void 00171 connectToInterfaceWithTag( const Context & context, 00172 ProxyType & proxy, 00173 const std::string & interfaceTag, 00174 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00175 int retryInterval=2, int retryNumber=-1 ) 00176 { 00177 context.tracer().debug( "orcaice::connectToInterfaceWithTag(thread) tag="+interfaceTag, 10 ); 00178 00179 int count = 0; 00180 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00181 { 00182 try { 00183 connectToInterfaceWithTag<ProxyType>( context, proxy, interfaceTag ); 00184 break; 00185 } 00186 catch ( const orcaice::NetworkException& e ) { 00187 std::stringstream ss; 00188 ss << "Failed to connect to interface with tag "<<interfaceTag<<". " 00189 <<"Will retry in "<<retryInterval<<"s." 00190 << e.what(); 00191 context.tracer().warning( ss.str() ); 00192 } 00193 ++count; 00194 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00195 if ( !subsysName.empty() ) { 00196 context.status().heartbeat( subsysName ); 00197 } 00198 } 00199 } 00200 00212 template<class ConsumerProxyType> 00213 IceStorm::TopicPrx 00214 connectToTopicWithString( const Context & context, 00215 ConsumerProxyType & publisher, 00216 const std::string & topicName, 00217 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00218 int retryInterval=2, int retryNumber=-1 ) 00219 { 00220 context.tracer().debug( "orcaice::connectToTopicWithString(thread) topic="+topicName, 10 ); 00221 IceStorm::TopicPrx topicPrx; 00222 00223 int count = 0; 00224 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00225 { 00226 try { 00227 topicPrx = connectToTopicWithString<ConsumerProxyType>( context, publisher, topicName ); 00228 break; 00229 } 00230 catch ( const orcaice::NetworkException& e ) { 00231 std::stringstream ss; 00232 ss << "Failed to connect to topic with string "<<topicName<<". " 00233 <<"Will retry in "<<retryInterval<<"s." 00234 << e.what(); 00235 context.tracer().warning( ss.str() ); 00236 } 00237 ++count; 00238 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00239 if ( !subsysName.empty() ) { 00240 context.status().heartbeat( subsysName ); 00241 } 00242 } 00243 return topicPrx; 00244 } 00245 00257 template<class ConsumerProxyType> 00258 IceStorm::TopicPrx 00259 connectToTopicWithTag( const Context & context, 00260 ConsumerProxyType & publisher, 00261 const std::string & interfaceTag, 00262 const std::string & subtopic, 00263 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00264 int retryInterval=2, int retryNumber=-1 ) 00265 { 00266 context.tracer().debug( "orcaice::connectToTopicWithTag(thread) tag="+interfaceTag, 10 ); 00267 IceStorm::TopicPrx topicPrx; 00268 00269 int count = 0; 00270 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00271 { 00272 try { 00273 topicPrx = connectToTopicWithTag<ConsumerProxyType>( context, publisher, interfaceTag, subtopic ); 00274 break; 00275 } 00276 catch ( const orcaice::NetworkException& e ) { 00277 std::stringstream ss; 00278 ss << "Failed to connect to topic with tag "<<interfaceTag<<". " 00279 <<"Will retry in "<<retryInterval<<"s." 00280 << e.what(); 00281 context.tracer().warning( ss.str() ); 00282 } 00283 ++count; 00284 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00285 if ( !subsysName.empty() ) { 00286 context.status().heartbeat( subsysName ); 00287 } 00288 } 00289 return topicPrx; 00290 } 00291 00301 std::string getInterfaceIdWithString( const Context& context, const std::string& proxyString, 00302 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00303 int retryInterval=2, int retryNumber=-1 ); 00304 00316 std::string getInterfaceIdWithTag( const Context& context, const std::string& interfaceTag, 00317 gbxsickacfr::gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00318 int retryInterval=2, int retryNumber=-1 ); 00319 00321 00322 } // namespace 00323 00324 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)