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

 

         

ptricestormlistener.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 ORCAGUI_PTR_ICESTORM_LISTENER_H
00012 #define ORCAGUI_PTR_ICESTORM_LISTENER_H
00013 
00014 #include <iostream>
00015 #include <assert.h>
00016 #include <Ice/Ice.h>
00017 #include <IceStorm/IceStorm.h>
00018 
00019 #include <orcaice/connectutils.h>
00020 #include <orcaice/context.h>
00021 #include <gbxsickacfr/gbxiceutilacfr/timer.h>
00022 
00023 #include <orcaqguielementutil/icestormlistenerdetail.h>
00024 
00025 namespace orcaqguielementutil
00026 {
00027 
00029 
00037 template< class DataType,
00038           class DataPtrType,
00039           class ProxyType,
00040           class ConsumerType,
00041           class ConsumerPrxType,
00042           class SubscriptionMakerType=detail::DefaultSubscriptionMaker<ProxyType,ConsumerPrxType>,
00043           class UnSubscriptionMakerType=detail::DefaultUnSubscriptionMaker<ProxyType,ConsumerPrxType> >
00044 class PtrIceStormListener
00045 {
00046 
00047 public:
00048 
00049     PtrIceStormListener( const orcaice::Context  &context,
00050                       const std::string       &proxyStr )
00051         : data_(new DataType),
00052           context_(context),
00053           proxyString_(proxyStr),
00054           isSubscribed_(false)
00055         {
00056             // Register with the adapter
00057             consumer_ = new detail::PtrBufferedTimedConsumerI<ConsumerType,DataPtrType>;
00058             registerWithAdapter();
00059         }
00060 
00061     ~PtrIceStormListener()
00062         {
00063             shutdown();
00064             // do not delete consumer_, it's deletedwhen the smart pointers fall out of scope.
00065         }
00066 
00067     orcaice::PtrBuffer<DataPtrType> &buffer() { return consumer_->buffer_; }
00068 
00069     // Returns zero on success
00070     int connect()
00071     {
00072         // clean up first
00073         if ( shutdown() != 0 ) return -1;
00074 
00075         // then resubscribe
00076         try {
00077             Ice::ObjectPtr objPtr = consumer_;
00078             callbackPrx_ = orcaice::createConsumerInterface<ConsumerPrxType>( context_,
00079                                                                               objPtr );
00080 
00081             detail::subscribeListener<ProxyType,
00082                 ConsumerType,
00083                 ConsumerPrxType,
00084                 SubscriptionMakerType>( context_, proxyString_, consumer_, callbackPrx_, proxy_ );
00085             isSubscribed_ = true;
00086             return 0;
00087         }
00088         catch ( ... ) {
00089             return -1;
00090         }
00091     };
00092 
00093     double msSinceReceipt() const { return consumer_->msSinceReceipt(); }
00094     void   resetTimer() { consumer_->resetTimer(); }
00095     std::string interfaceName() const { return proxyString_; };
00096 
00097 private:
00098 
00099     DataPtrType                                                  data_;
00100     detail::PtrBufferedTimedConsumerI<ConsumerType,DataPtrType> *consumer_;
00101 
00102     orcaice::Context  context_;
00103     std::string       proxyString_;
00104 
00105     void registerWithAdapter()
00106         {
00107             Ice::ObjectPrx obj = context_.adapter()->addWithUUID( consumer_ );
00108             Ice::ObjectPrx prx = context_.adapter()->createDirectProxy( obj->ice_getIdentity() );
00109             callbackPrx_ = ConsumerPrxType::uncheckedCast( prx );
00110         }
00111 
00112     // 0=success
00113     int shutdown()
00114         {
00115             // std::cout<<"TRACE(icestormlistener.h): start of shutdown(): isSubscribed_: " << isSubscribed_ << std::endl;
00116             // unsubscribe
00117             if ( isSubscribed_ )
00118             {
00119                 try {
00120                     detail::unSubscribeListener<ProxyType,
00121                         ConsumerType,
00122                         ConsumerPrxType,
00123                         UnSubscriptionMakerType>( context_, proxyString_, consumer_, callbackPrx_, proxy_ );
00124 
00125                     // remove consumer from the list of active servants
00126                     context_.adapter()->remove( callbackPrx_->ice_getIdentity() );
00127 
00128                     isSubscribed_ = false;
00129                     // std::cout<<"TRACE(icestormlistener.h): unsubscription successful." << std::endl;
00130                 } catch ( ... ) {
00131                     return -1;
00132                 }
00133             }
00134             return 0;
00135         }
00136 
00137     // Proxy to remote object
00138     ProxyType      proxy_;
00139 
00140     // Smart pointer to consumer_.
00141     // We need to hold onto this to keep it alive.
00142     ConsumerPrxType callbackPrx_;
00143     bool            isSubscribed_;
00144 };
00145 
00146 
00147 } // namespace
00148 
00149 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5