|
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
|
icegridutils.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_ICEGRID_UTILITIES_H 00012 #define ORCAICE_ICEGRID_UTILITIES_H 00013 00014 #include <Ice/Ice.h> 00015 #include <IceGrid/Query.h> 00016 00017 #include <orcaice/context.h> 00018 #include <orcaice/configutils.h> 00019 #include <orcaice/exceptions.h> 00020 // #include <orcaice/stringutils.h> // just for debugging 00021 #include <orcaice/printutils.h> 00022 00023 namespace orcaice 00024 { 00029 00034 bool isRegistryReachable( const Context& context ); 00035 00038 IceGrid::QueryPrx getDefaultQuery( const orcaice::Context& context ); 00039 00041 Ice::Identity toAdminIdentity( const orca::FQComponentName& ); 00042 00048 orca::FQComponentName toComponentName( const Ice::Identity& adminId ); 00049 00051 orca::FQComponentName toComponentName( const Ice::ObjectPrx& homePrx ); 00052 00059 Ice::ObjectPrx getComponentAdmin( const orcaice::Context& context, const orca::FQComponentName& fqName ); 00060 00064 Ice::ObjectProxySeq getAllComponentAdmins( const orcaice::Context& context ); 00065 00082 std::string toAdminFacet( const orca::FQComponentName& fqName, const std::string& interfaceType ); 00083 00096 bool isAdminInterfaceReachable( const Context& context, const orca::FQComponentName& fqName, const std::string& interfaceType, 00097 std::string& diagnostic ); 00098 00117 void createAdminInterface( const Context& context, Ice::ObjectPtr& object, const orca::FQComponentName& fqname ); 00118 00146 // template<class InterfaceProxyType> 00147 // void connectToAdminInterfaceWithFacet( const Context& context, InterfaceProxyType interfacePrx, const std::string& facet, 00148 template<class InterfaceType, class InterfaceProxyType> 00149 void connectToAdminInterface( const Context& context, InterfaceProxyType& interfacePrx, const orca::FQComponentName& fqname ) 00150 { 00151 orca::FQComponentName resolvedFqname = orcaice::resolveLocalPlatform( context, fqname ); 00152 00153 // std::cout<<"DEBUG: "<<__func__<<"(): will look for Admin interface of ="<<orcaice::toString(resolvedFqname)<<std::endl; 00154 00155 const std::string interfaceType = InterfaceType::ice_staticId(); 00156 const std::string facetName = orcaice::toAdminFacet( resolvedFqname, interfaceType ); 00157 00158 // std::cout<<"DEBUG: "<<__func__<<"(): will connect to facet="<<facetName<<std::endl; 00159 00160 // 00161 // This is the generic proxy to the Admin object. Cannot be used as such because it does not have a default facet. 00162 // 00163 Ice::ObjectPrx objectPrx = orcaice::getComponentAdmin( context, resolvedFqname ); 00164 00165 if ( !objectPrx ) 00166 throw gbxutilacfr::Exception( ERROR_INFO, "Registry returned null admin proxy." ); 00167 00168 // std::cout<<"DEBUG: "<<__func__<<"(): got admin proxy ="<<objectPrx->ice_toString()<<std::endl; 00169 00170 // 00171 // Change proxy to the user-supplied facet name. 00172 // 00173 objectPrx = objectPrx->ice_facet( facetName ); 00174 00175 // check with the server that the one we found is of the right type 00176 // the check operation is remote and may fail (see sec.6.11.2) 00177 try { 00178 interfacePrx = InterfaceProxyType::checkedCast( objectPrx ); 00179 // got some answer, check that it's the right type 00180 if ( !interfacePrx ) { 00181 // contains another remote call ice_id() !!! 00182 std::string errString = "Admin interface with facet '" + facetName + "' is of wrong type."+ 00183 " Tried to connect proxy of type "+InterfaceType::ice_staticId()+ 00184 " to remote interface of type "+objectPrx->ice_id(); 00185 orcaice::initTracerWarning( context, errString, 2 ); 00186 throw orcaice::TypeMismatchException( ERROR_INFO, errString ); 00187 } 00188 } 00189 catch ( const Ice::ConnectionRefusedException& e ) 00190 { 00191 std::stringstream ss; 00192 ss << "(while connecting to Admin interface with facet '" << facetName << "') cannot reach the adaptor: "<<e.what(); 00193 orcaice::initTracerWarning( context, ss.str(), 2 ); 00194 throw orcaice::NetworkException( ERROR_INFO, ss.str() ); 00195 } 00196 catch ( const Ice::ObjectNotExistException& e ) 00197 { 00198 std::stringstream ss; 00199 ss << "(while connecting to Admin interface with facet '" << facetName << "') reached the adaptor but not the interface: "<<e.what(); 00200 orcaice::initTracerWarning( context, ss.str(), 2 ); 00201 throw orcaice::NetworkException( ERROR_INFO, ss.str() ); 00202 } 00203 catch ( const Ice::FacetNotExistException& e ) 00204 { 00205 std::stringstream ss; 00206 ss << "(while connecting to Admin interface with facet '" << facetName << "') reached the adaptor and the interface but not the facet: "<<e.what(); 00207 orcaice::initTracerWarning( context, ss.str(), 2 ); 00208 throw orcaice::NetworkException( ERROR_INFO, ss.str() ); 00209 } 00210 catch ( const std::exception& e ) 00211 { 00212 std::stringstream ss; 00213 ss << "(while connecting to Admin interface with facet '" << facetName << "') something unexpected: "<<e.what(); 00214 orcaice::initTracerWarning( context, ss.str(), 2 ); 00215 throw orcaice::NetworkException( ERROR_INFO, ss.str() ); 00216 } 00217 } 00218 00220 00221 } // namespace 00222 00223 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)
1.4.5