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

 

         

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

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


Generated for Orca Robotics by  doxygen 1.4.5