|
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/thread.h> 00016 00017 namespace orcaice 00018 { 00023 00047 template<class ProxyType> 00048 void 00049 connectToInterfaceWithString( const Context & context, 00050 ProxyType & proxy, 00051 const std::string & proxyString, 00052 gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00053 int retryInterval=2, int retryNumber=-1 ) 00054 { 00055 context.tracer().debug( "orcaice::connectToInterfaceWithString(thread) proxy="+proxyString, 10 ); 00056 int count = 0; 00057 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00058 { 00059 try { 00060 connectToInterfaceWithString( context, proxy, proxyString ); 00061 break; 00062 } 00063 catch ( const orcaice::NetworkException& e ) { 00064 std::stringstream ss; 00065 ss << "Failed to connect to interface with string "<<proxyString<<". " 00066 <<"Will retry in "<<retryInterval<<"s." 00067 << e.what(); 00068 context.tracer().warning( ss.str() ); 00069 } 00070 ++count; 00071 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00072 if ( !subsysName.empty() ) { 00073 context.status().heartbeat( subsysName ); 00074 } 00075 } 00076 } 00077 00106 template<class ProxyType> 00107 void 00108 connectToInterfaceWithTag( const Context & context, 00109 ProxyType & proxy, 00110 const std::string & interfaceTag, 00111 gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00112 int retryInterval=2, int retryNumber=-1 ) 00113 { 00114 context.tracer().debug( "orcaice::connectToInterfaceWithTag(thread) tag="+interfaceTag, 10 ); 00115 00116 int count = 0; 00117 while ( !thread->isStopping() && ( retryNumber<0 || count<retryNumber) ) 00118 { 00119 try { 00120 connectToInterfaceWithTag<ProxyType>( context, proxy, interfaceTag ); 00121 break; 00122 } 00123 catch ( const orcaice::NetworkException& e ) { 00124 std::stringstream ss; 00125 ss << "Failed to connect to interface with tag "<<interfaceTag<<". " 00126 <<"Will retry in "<<retryInterval<<"s." 00127 << e.what(); 00128 context.tracer().warning( ss.str() ); 00129 } 00130 ++count; 00131 IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(retryInterval)); 00132 if ( !subsysName.empty() ) { 00133 context.status().heartbeat( subsysName ); 00134 } 00135 } 00136 } 00137 00147 std::string getInterfaceIdWithString( const Context& context, const std::string& proxyString, 00148 gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00149 int retryInterval=2, int retryNumber=-1 ); 00150 00162 std::string getInterfaceIdWithTag( const Context& context, const std::string& interfaceTag, 00163 gbxiceutilacfr::Thread* thread, const std::string& subsysName="", 00164 int retryInterval=2, int retryNumber=-1 ); 00165 00167 00168 } // namespace 00169 00170 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)
1.4.5