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

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


Generated for Orca Robotics by  doxygen 1.4.5