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

 

         

util.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 ORCA_IFACE_IMPL_UTIL_H
00012 #define ORCA_IFACE_IMPL_UTIL_H
00013 
00014 #include <orcaice/context.h>
00015 #include <orcaice/connectutils.h>
00016 #include <sstream>
00017 #include <iostream>
00018 #include <IceStorm/IceStorm.h>
00019 
00020 namespace orcaifaceimpl {
00021 
00022     namespace detail {
00023 
00024         // Catches all exceptions.
00025         // Returns: true if re-connected OK.
00026         template<class ConsumerPrxType>
00027         bool
00028         tryReconnectToIceStorm( orcaice::Context   &context,
00029                                 ConsumerPrxType    &consumerPrx,
00030                                 IceStorm::TopicPrx &topicPrx,
00031                                 const std::string  &interfaceName,
00032                                 const std::string  &topicName )
00033         {
00034             try {
00035                 std::stringstream ss;
00036                 ss << interfaceName << ": Re-connecting to IceStorm...";
00037                 context.tracer().info( ss.str() );
00038                 topicPrx = orcaice::connectToTopicWithString<ConsumerPrxType>
00039                     ( context, consumerPrx, topicName );
00040 
00041                 ss.str("");
00042                 ss << interfaceName << ": Re-connected to IceStorm.";
00043                 context.tracer().info( ss.str() );
00044 
00045                 return true;
00046             }
00047             catch ( ... )
00048             {
00049                 // ignore it
00050                 std::stringstream ss;
00051                 ss << interfaceName << ": Re-connection to IceStorm failed.";
00052                 context.tracer().info( ss.str() );
00053                 return false;
00054             }
00055         }
00056 
00057     }    
00058 
00068     template<class ConsumerPrxType,
00069              class DataType>
00070     void
00071     tryPushToIceStormWithReconnect( orcaice::Context   &context,
00072                                     ConsumerPrxType    &consumerPrx,
00073                                     const DataType     &data,
00074                                     IceStorm::TopicPrx &topicPrx,
00075                                     const std::string  &interfaceName,
00076                                     const std::string  &topicName )
00077     {
00078         // check that communicator still exists
00079         if ( !context.communicator() ) {
00080             return;
00081         }
00082     
00083         try {
00084             consumerPrx->setData( data );
00085         }
00086         catch ( Ice::CommunicatorDestroyedException & )
00087         {
00088             // If we see this, we're obviously shutting down.  Don't bitch about anything.
00089         }
00090         catch ( Ice::Exception &e )
00091         {
00092             // This could happen if IceStorm dies.
00093             // If we're running in an IceBox and the IceBox is shutting down, 
00094             // this is expected (our co-located IceStorm is obviously going down).
00095             std::stringstream ss; ss << interfaceName << ": Failed push to IceStorm: " << e;
00096             context.tracer().warning( ss.str() );
00097 
00098             // If IceStorm just re-started for some reason though, we want to try to re-connect
00099             bool reconnected = detail::tryReconnectToIceStorm( context,
00100                                                                consumerPrx,
00101                                                                topicPrx,
00102                                                                interfaceName,
00103                                                                topicName );
00104             if ( reconnected )
00105             {
00106                 try {
00107                     // try again to push that bit of info
00108                     consumerPrx->setData( data );
00109                 }
00110                 catch ( Ice::Exception &e )
00111                 {
00112                     std::stringstream ss;
00113                     ss << interfaceName << ": Re-push of data failed: " << e;
00114                     context.tracer().info( ss.str() );
00115                 }
00116             }
00117         }
00118     }
00119 
00122     void
00123     tryRemoveInterface( orcaice::Context  &context,
00124                         const std::string &interfaceName );
00125 
00128     std::string getInterfaceNameFromTag( const orcaice::Context &context,
00129                                          const std::string      &interfaceTag );
00130     
00132     std::string getTopicNameFromInterfaceName( const orcaice::Context &context,
00133                                                const std::string      &interfaceTag );
00134 }
00135 
00136 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5