|
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
|
multiicestormutils.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_ICESTORM_UTILITIES_H 00012 #define ORCAICE_MULTI_ICESTORM_UTILITIES_H 00013 00014 #include <orcaice/icestormutils.h> 00015 #include <gbxsickacfr/gbxiceutilacfr/thread.h> 00016 00017 namespace orcaice 00018 { 00023 00035 template<class ConsumerProxyType> 00036 IceStorm::TopicPrx 00037 connectToTopicWithString( const Context & context, 00038 ConsumerProxyType & publisher, 00039 const std::string & topicName, 00040 gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00041 int retryInterval=2, int retryNumber=-1 ) 00042 { 00043 IceStorm::TopicPrx topicPrx; 00044 00045 int count = 0; 00046 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00047 { 00048 try { 00049 topicPrx = connectToTopicWithString<ConsumerProxyType>( context, publisher, topicName ); 00050 break; 00051 } 00052 catch ( const orcaice::NetworkException& e ) { 00053 std::stringstream ss; 00054 ss << "Failed to connect to topic with string "<<topicName<<". " 00055 <<"Will retry in "<<retryInterval<<"s." 00056 << e.what(); 00057 bool localOnly = true; 00058 context.tracer().warning( ss.str(), 1, localOnly ); 00059 } 00060 ++count; 00061 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00062 if ( !subsysName.empty() ) { 00063 context.status().heartbeat( subsysName ); 00064 } 00065 } 00066 return topicPrx; 00067 } 00068 00080 template<class ConsumerProxyType> 00081 IceStorm::TopicPrx 00082 connectToTopicWithTag( const Context & context, 00083 ConsumerProxyType & publisher, 00084 const std::string & interfaceTag, 00085 const std::string & subtopic, 00086 gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00087 int retryInterval=2, int retryNumber=-1 ) 00088 { 00089 IceStorm::TopicPrx topicPrx; 00090 00091 int count = 0; 00092 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00093 { 00094 try { 00095 topicPrx = connectToTopicWithTag<ConsumerProxyType>( context, publisher, interfaceTag, subtopic ); 00096 break; 00097 } 00098 catch ( const orcaice::NetworkException& e ) { 00099 std::stringstream ss; 00100 ss << "Failed to connect to topic with tag "<<interfaceTag<<". " 00101 <<"Will retry in "<<retryInterval<<"s." 00102 << e.what(); 00103 bool localOnly = true; 00104 context.tracer().warning( ss.str(), 1, localOnly ); 00105 } 00106 ++count; 00107 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00108 if ( !subsysName.empty() ) { 00109 context.status().heartbeat( subsysName ); 00110 } 00111 } 00112 return topicPrx; 00113 } 00114 00116 00117 } // namespace 00118 00119 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)
1.4.5