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 Project Download Mailing lists
|
icestormlistenerdetail.h00001 /* 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_DETAIL_H 00012 #define ORCAGUI_ICESTORM_LISTENER_DETAIL_H 00013 00014 #include <orcaice/connectutils.h> 00015 #include <gbxsickacfr/gbxiceutilacfr/store.h> 00016 #include <gbxsickacfr/gbxiceutilacfr/timer.h> 00017 00018 namespace orcaqguielementutil 00019 { 00020 00021 // non-member utility stuff 00022 namespace detail { 00023 00024 // A little bit of magic to get around the fact that different (un)subscription 00025 // functions may have different names 00026 template< class ProxyType, class ConsumerPrxType > 00027 class DefaultSubscriptionMaker 00028 { 00029 public: 00030 DefaultSubscriptionMaker( ProxyType proxy, ConsumerPrxType callbackPrx ) 00031 { topic_ = proxy->subscribe( callbackPrx ); } 00032 IceStorm::TopicPrx topic_; 00033 }; 00034 00035 template< class ConsumerPrxType > 00036 class DefaultUnSubscriptionMaker 00037 { 00038 public: 00039 DefaultUnSubscriptionMaker( const IceStorm::TopicPrx& topic, const ConsumerPrxType& consumerPrx ) 00040 { topic->unsubscribe( consumerPrx ); } 00041 }; 00042 00043 // 00044 // ================ Definition ===================== 00045 // 00046 00047 // Subscribe/unsubscribe IceStormListeners 00048 template< class ProxyType, 00049 class ConsumerType, 00050 class ConsumerPrxType, 00051 class SubscriptionMakerType > 00052 IceStorm::TopicPrx 00053 subscribeListener( orcaice::Context &context, 00054 const std::string &proxyString, 00055 ConsumerType *consumer, 00056 ConsumerPrxType &callbackPrx, 00057 ProxyType &proxy); 00058 00059 template< class ConsumerType, 00060 class ConsumerPrxType, 00061 class UnSubscriptionMakerType > 00062 void 00063 unSubscribeListener( orcaice::Context &context, 00064 const IceStorm::TopicPrx& topic, 00065 ConsumerType *consumer, 00066 ConsumerPrxType &callbackPrx); 00067 00068 // 00069 // ================ Implementation ===================== 00070 // 00071 00072 template< class ProxyType, 00073 class ConsumerType, 00074 class ConsumerPrxType, 00075 class SubscriptionMakerType > 00076 IceStorm::TopicPrx 00077 subscribeListener( orcaice::Context &context, 00078 const std::string &proxyString, 00079 ConsumerType *consumer, 00080 ConsumerPrxType &callbackPrx, 00081 ProxyType &proxy ) 00082 { 00083 try { 00084 // Connect to remote interface 00085 orcaice::connectToInterfaceWithString( context, proxy, proxyString ); 00086 00087 // Ask the remote object to subscribe us to the topic. 00088 try { 00089 SubscriptionMakerType s( proxy, callbackPrx ); 00090 return s.topic_; 00091 } 00092 catch ( ... ) 00093 { 00094 std::cout<<"TRACE(icestormlistenerdetail.h): Subscribe failed." << std::endl; 00095 throw; 00096 } 00097 } 00098 // Ignore all exceptions, and try again next time. 00099 catch ( orca::OrcaException &e ) { 00100 std::cout<<"TRACE(subscribeListener): Caught orca exception: " << e << ": " << e.what << std::endl; 00101 throw; 00102 } 00103 catch ( std::exception &e ) { 00104 std::cout<<"TRACE(subscribeListener): Caught std exception: " << e.what() << std::endl; 00105 throw; 00106 } 00107 catch ( ... ) { 00108 std::cout<<"TRACE(subscribeListener): Caught unknown exception." << std::endl; 00109 throw; 00110 } 00111 } 00112 template< class ConsumerType, 00113 class ConsumerPrxType, 00114 class UnSubscriptionMakerType > 00115 void 00116 unSubscribeListener( orcaice::Context &context, 00117 const IceStorm::TopicPrx& topic, 00118 ConsumerType *consumer, 00119 ConsumerPrxType &callbackPrx ) 00120 { 00121 try { 00122 // Ask the remote object to unsubscribe us from the topic. 00123 UnSubscriptionMakerType s( topic, callbackPrx ); 00124 } 00125 catch ( std::exception &e ) { 00126 // std::cout<<"TRACE(unSubscribeListener): Caught std exception: " << e.what() << std::endl; 00127 throw; 00128 } 00129 catch ( ... ) { 00130 // std::cout<<"TRACE(unSubscribeListener): Caught unknown exception." << std::endl; 00131 throw; 00132 } 00133 } 00134 00136 00137 /* 00138 * @brief A convenience class for consumers with setData() operation. 00139 * 00140 * Relies on the fact that the Consumer objects has only one operation 00141 * to implement and it's called setData(). 00142 * 00143 */ 00144 template<class ConsumerType, class ObjectType> 00145 class StoredTimedConsumerI : public ConsumerType 00146 { 00147 public: 00148 00149 StoredTimedConsumerI() 00150 : store_() {}; 00151 00152 void setData( const ObjectType& data, const Ice::Current& ) 00153 { 00154 store_.set( data ); 00155 handleData( data ); 00156 } 00157 00158 double msSinceReceipt() { return timer_.elapsedMs(); } 00159 void resetTimer() { return timer_.restart(); } 00160 00161 // store_ is public so that guielements can access it directly 00162 gbxiceutilacfr::Store<ObjectType> store_; 00163 00164 protected: 00165 00166 void handleData( const ObjectType & obj ) 00167 { 00168 timer_.restart(); 00169 } 00170 00171 gbxiceutilacfr::Timer timer_; 00172 }; 00173 00174 } // namespace 00175 } // namespace 00176 00177 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)