INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

multiconnectutils.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2009 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 // we only need the definition of Stoppable and checkedSleep() function.
00016 // (we don't need the actual Thread class).
00017 #include <gbxsickacfr/gbxiceutilacfr/threadutils.h>
00018 
00019 namespace orcaice
00020 {
00025 
00051 template<class ProxyType>
00052 void
00053 connectToInterfaceWithString( const Context     & context,
00054                               ProxyType         & proxy,
00055                               const std::string & proxyString,
00056                               gbxutilacfr::Stoppable* activity, const std::string& subsysName="", 
00057                               int retryIntervalSec=2, int retryNumber=-1 )
00058 {        
00059     assert( activity && "Null activity pointer" );
00060 
00061     context.tracer().debug( subsysName, "orcaice::connectToInterfaceWithString(activity) proxy="+proxyString, 10 );
00062     int count = 0;
00063     while ( !activity->isStopping() && ( retryNumber<0 || count<retryNumber) )
00064     {
00065         try {
00066             connectToInterfaceWithString( context, proxy, proxyString );
00067             if ( !subsysName.empty() )
00068                 context.status().ok( subsysName );
00069             break;
00070         }
00071         catch ( const orcaice::NetworkException& e ) {
00072             std::stringstream ss;
00073             ss << "Failed to connect to interface with string "<<proxyString<<" : "<< e.what()
00074                << "\nWill retry in "<<retryIntervalSec<<"s.";
00075             if ( !subsysName.empty() )
00076                 context.status().warning( subsysName, ss.str() );
00077             else
00078                 context.tracer().warning( subsysName, ss.str() );
00079         }
00080         ++count;
00081         gbxiceutilacfr::checkedSleep( activity, retryIntervalSec*1000 );
00082     }
00083 }
00084 
00115 template<class ProxyType>
00116 void
00117 connectToInterfaceWithTag( const Context     & context,
00118                            ProxyType         & proxy,
00119                            const std::string & interfaceTag,
00120                            gbxutilacfr::Stoppable* activity, const std::string& subsysName="", 
00121                            int retryIntervalSec=2, int retryNumber=-1 )
00122 {    
00123     assert( activity && "Null activity pointer" );
00124 
00125     context.tracer().debug( subsysName, "orcaice::connectToInterfaceWithTag(activity) tag="+interfaceTag, 10 );
00126 
00127     int count = 0;
00128     while ( !activity->isStopping() && ( retryNumber<0 || count<retryNumber) )
00129     {
00130         try {
00131             connectToInterfaceWithTag<ProxyType>( context, proxy, interfaceTag );
00132             if ( !subsysName.empty() )
00133                 context.status().ok( subsysName );
00134             break;
00135         }
00136         catch ( const orcaice::NetworkException& e ) {
00137             std::stringstream ss;
00138             ss << "Failed to connect to interface with tag "<<interfaceTag<<": "<<e.what()
00139                << "\nWill retry in "<<retryIntervalSec<<"s.";
00140             if ( !subsysName.empty() )
00141                 context.status().warning( subsysName, ss.str() );
00142             else
00143                 context.tracer().warning( subsysName, ss.str() );
00144         }
00145         ++count;
00146         gbxiceutilacfr::checkedSleep( activity, retryIntervalSec*1000 );
00147     }
00148 }
00149 
00161 std::string getInterfaceIdWithString( const Context& context, const std::string& proxyString,
00162                             gbxutilacfr::Stoppable* activity, const std::string& subsysName="", 
00163                             int retryIntervalSec=2, int retryNumber=-1 );
00164 
00178 std::string getInterfaceIdWithTag( const Context& context, const std::string& interfaceTag,
00179                             gbxutilacfr::Stoppable* activity, const std::string& subsysName="", 
00180                             int retryIntervalSec=2, int retryNumber=-1 );
00181 
00182 template<class InterfacePrxType, typename DescriptionType>
00183 void
00184 getDescriptionWithTag( const Context          &context,
00185                        const std::string      &interfaceTag,
00186                        DescriptionType        &description,
00187                        gbxutilacfr::Stoppable *activity,
00188                        const std::string      &subsysName       = "", 
00189                        int                     retryIntervalSec = 2, 
00190                        int                     retryNumber      = -1 )
00191 {
00192     int count = 0;
00193     while ( !activity->isStopping() && ( retryNumber<0 || count<retryNumber) )
00194     {
00195         try {
00196             description = orcaice::getDescriptionWithTag<InterfacePrxType,DescriptionType>( context, interfaceTag );
00197             if ( !subsysName.empty() )
00198                 context.status().ok( subsysName );
00199             break;
00200         }
00201         catch ( const orcaice::NetworkException& e ) {
00202             std::stringstream ss;
00203             ss << "Failed to connect to interface with tag "<<interfaceTag<<" : "<< e.what()
00204                << "\nWill retry in "<<retryIntervalSec<<"s.";
00205             if ( !subsysName.empty() )
00206                 context.status().warning( subsysName, ss.str() );
00207             else
00208                 context.tracer().warning( subsysName, ss.str() );
00209         }
00210         ++count;
00211         gbxiceutilacfr::checkedSleep( activity, retryIntervalSec*1000 );
00212     }
00213 }
00214 
00215 template<class InterfacePrxType, typename DescriptionType>
00216 void
00217 getDescriptionWithString( const Context          &context,
00218                           const std::string      &interfaceString,
00219                           DescriptionType        &description,
00220                           gbxutilacfr::Stoppable *activity,
00221                           const std::string      &subsysName       = "", 
00222                           int                     retryIntervalSec = 2, 
00223                           int                     retryNumber      = -1 )
00224 {
00225     int count = 0;
00226     while ( !activity->isStopping() && ( retryNumber<0 || count<retryNumber) )
00227     {
00228         try {
00229             description = orcaice::getDescriptionWithString<InterfacePrxType,DescriptionType>( context, interfaceString );
00230             if ( !subsysName.empty() )
00231                 context.status().ok( subsysName );
00232             break;
00233         }
00234         catch ( const orcaice::NetworkException& e ) {
00235             std::stringstream ss;
00236             ss << "Failed to connect to interface with string "<<interfaceString<<" : "<< e.what()
00237                << "\nWill retry in "<<retryIntervalSec<<"s.";
00238             if ( !subsysName.empty() )
00239                 context.status().warning( subsysName, ss.str() );
00240             else
00241                 context.tracer().warning( subsysName, ss.str() );
00242         }
00243         ++count;
00244         gbxiceutilacfr::checkedSleep( activity, retryIntervalSec*1000 );
00245     }
00246 }
00247 
00248 
00250 
00251 } // namespace
00252 
00253 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5