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

SourceForge.net Logo
Project
Download
Mailing lists

 

         

orcaice/connectutils.h

00001 /*
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_CONNECT_UTILITIES_H
00012 #define ORCAICE_CONNECT_UTILITIES_H
00013 
00014 #include <Ice/Ice.h>
00015 
00016 #include <orcaice/context.h>
00017 #include <orcaice/exceptions.h>
00018 #include <orcaice/configutils.h>
00019 // #include <hydroutil/sysutils.h>
00020 #include <orcaice/printutils.h>
00021 #include <orcaice/stringutils.h>
00022 
00023 namespace orcaice
00024 {
00029 
00040 bool isInterfaceReachable( const Context& context, const std::string& proxyString, std::string& diagnostic );
00041 
00044 std::string getInterfaceIdWithString( const Context& context, const std::string& proxyString );
00045 
00049 std::string getInterfaceIdWithTag( const Context& context, const std::string& interfaceTag );
00050 
00051 //
00052 //  Implementation Note:
00053 //  the two 'connectToInterface' functions have to be templated, unfortunately,
00054 //  to ensure we're connecting to the right type.
00071 template<class InterfaceType>
00072 void
00073 connectToInterfaceWithString( const Context                             &context,
00074                               ::IceInternal::ProxyHandle<InterfaceType> &proxy,
00075                               const std::string                         &proxyString)
00076 {
00077     // for indirect proxies only: if platform is set to 'local', replace it by hostname
00078     std::string resolvedProxyString = resolveLocalPlatform( context, proxyString );
00079 
00080     Ice::ObjectPrx base = context.communicator()->stringToProxy( resolvedProxyString );
00081 
00082     // check with the server that the one we found is of the right type
00083     // the check operation is remote and may fail (see sec.6.11.2)
00084     try {
00085         proxy = ::IceInternal::ProxyHandle<InterfaceType>::checkedCast( base );
00086         // got some answer, check that it's the right type
00087         if ( !proxy ) {
00088             std::string errString = "Required interface '" + resolvedProxyString +
00089                 "' is of wrong type."+
00090                 "  Tried to connect proxy of type "+InterfaceType::ice_staticId()+
00091                 " to remote interface of type "+base->ice_id();
00092             initTracerWarning( context, errString, 2 );
00093             throw orcaice::TypeMismatchException( ERROR_INFO, errString );
00094         }
00095     }
00096     catch ( const Ice::ConnectionRefusedException& e )
00097     {
00098         std::stringstream ss;
00099         ss << "(while connecting to interface '" << resolvedProxyString << "') cannot reach the adaptor: "<<e.what();
00100         orcaice::initTracerWarning( context, ss.str(), 2 );
00101         throw orcaice::NetworkException( ERROR_INFO, ss.str() );
00102     }
00103     catch ( const Ice::ObjectNotExistException& e )
00104     {
00105         std::stringstream ss;
00106         ss << "(while connecting to interface '" << resolvedProxyString << "') reached the adaptor but not the interface: "<<e.what();
00107         orcaice::initTracerWarning( context, ss.str(), 2 );
00108         throw orcaice::NetworkException( ERROR_INFO, ss.str() );
00109     }
00110     catch ( const std::exception& e )
00111     {
00112         std::stringstream ss;
00113         ss << "(while connecting to interface '" << resolvedProxyString << "') something unexpected: "<<e.what();
00114         orcaice::initTracerWarning( context, ss.str(), 2 );
00115         throw orcaice::NetworkException( ERROR_INFO, ss.str() );
00116     }
00117 
00118     // @todo Record who we connected to as a required interface so that Home can report this.
00119 }
00120 
00131 template<class InterfaceType>
00132 void
00133 connectToInterfaceWithTag( const Context       & context,
00134                            InterfaceType       & proxy,
00135                            const std::string   & interfaceTag )
00136 {
00137     // this may throw ConfigFileException, we don't catch it, let the user catch it at the component level
00138     std::string proxyString = orcaice::getRequiredInterfaceAsString( context, interfaceTag );
00139 
00140     // now that we have the stingified proxy, use the function above.
00141     connectToInterfaceWithString( context, proxy, proxyString );
00142 }
00143 
00145 
00146 } // namespace
00147 
00148 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5