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

 

         

connectutils.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_CONNECT_UTILITIES_H
00012 #define ORCAICE_CONNECT_UTILITIES_H
00013 
00014 #include <orcaice/context.h>
00015 #include <orcaice/exceptions.h>
00016 #include <orcaice/configutils.h>
00017 #include <orcaice/printutils.h>
00018 #include <orcaice/stringutils.h>
00019 
00020 namespace orcaice
00021 {
00026 
00037 bool isInterfaceReachable( const Context& context, const std::string& proxyString, std::string& diagnostic );
00038 
00041 std::string getInterfaceIdWithString( const Context& context, const std::string& proxyString );
00042 
00046 std::string getInterfaceIdWithTag( const Context& context, const std::string& interfaceTag );
00047 
00048 //
00049 //  Implementation Note:
00050 //  the two 'connectToInterface' functions have to be templated, unfortunately,
00051 //  to ensure we're connecting to the right type.
00068 template<class InterfaceType>
00069 void
00070 connectToInterfaceWithString( const Context                             &context,
00071                               ::IceInternal::ProxyHandle<InterfaceType> &proxy,
00072                               const std::string                         &proxyString)
00073 {
00074     // for indirect proxies only: if platform is set to 'local', replace it by hostname
00075     std::string resolvedProxyString = resolveLocalPlatform( context, proxyString );
00076 
00077     Ice::ObjectPrx base = context.communicator()->stringToProxy( resolvedProxyString );
00078 
00079     // check with the server that the one we found is of the right type
00080     // the check operation is remote and may fail (see sec.6.11.2)
00081     try {
00082         proxy = ::IceInternal::ProxyHandle<InterfaceType>::checkedCast( base );
00083         // got some answer, check that it's the right type
00084         if ( !proxy ) {
00085             std::string errString = "Required interface '" + resolvedProxyString +
00086                 "' is of wrong type."+
00087                 "  Tried to connect proxy of type "+InterfaceType::ice_staticId()+
00088                 " to remote interface of type "+base->ice_id();
00089             throw orcaice::TypeMismatchException( ERROR_INFO, errString );
00090         }
00091     }
00092     catch ( const Ice::ConnectionRefusedException& e )
00093     {
00094         std::stringstream ss;
00095         ss << "(while connecting to interface '" << resolvedProxyString << "') cannot reach the adaptor: "<<e.what();
00096         throw orcaice::NetworkException( ERROR_INFO, ss.str() );
00097     }
00098     catch ( const Ice::ObjectNotExistException& e )
00099     {
00100         std::stringstream ss;
00101         ss << "(while connecting to interface '" << resolvedProxyString << "') reached the adaptor but not the interface: "<<e.what();
00102         throw orcaice::NetworkException( ERROR_INFO, ss.str() );
00103     }
00104     catch ( const std::exception& e )
00105     {
00106         std::stringstream ss;
00107         ss << "(while connecting to interface '" << resolvedProxyString << "') something unexpected: "<<e.what();
00108         throw orcaice::NetworkException( ERROR_INFO, ss.str() );
00109     }
00110 
00111     // @todo Record who we connected to as a required interface so that Home can report this.
00112 }
00113 
00124 template<class InterfaceType>
00125 void
00126 connectToInterfaceWithTag( const Context       & context,
00127                            InterfaceType       & proxy,
00128                            const std::string   & interfaceTag )
00129 {
00130     // this may throw ConfigFileException, we don't catch it, let the user catch it at the component level
00131     std::string proxyString = orcaice::getRequiredInterfaceAsString( context, interfaceTag );
00132 
00133     // now that we have the stingified proxy, use the function above.
00134     connectToInterfaceWithString( context, proxy, proxyString );
00135 }
00136 
00141 template<class InterfacePrxType,typename DescriptionType>
00142 DescriptionType
00143 getDescriptionWithTag( const Context     &context,
00144                        const std::string &interfaceTag )
00145 {
00146     InterfacePrxType interfacePrx;
00147     connectToInterfaceWithTag( context, interfacePrx, interfaceTag );
00148     return interfacePrx->getDescription();
00149 }
00150 
00155 template<class InterfacePrxType,typename DescriptionType>
00156 DescriptionType
00157 getDescriptionWithString( const Context     &context,
00158                           const std::string &interfaceString )
00159 {
00160     InterfacePrxType interfacePrx;
00161     connectToInterfaceWithString( context, interfacePrx, interfaceString );
00162     return interfacePrx->getDescription();
00163 }
00164 
00166 
00167 } // namespace
00168 
00169 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5