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

 

         

genericgpsprobe.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2008 Alex Brooks
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_ORCAPROBEFACTORY_GENERIC_GPS_PROBE_H
00012 #define ORCA_ORCAPROBEFACTORY_GENERIC_GPS_PROBE_H
00013 
00014 #include <orcaprobe/interfaceprobe.h>
00015 #include <orcaice/connectutils.h>
00016 #include <orcaprobe/orcaprobe.h>
00017 #include <orcaifacestring/gps.h>
00018 
00019 namespace orcaprobefactory
00020 {
00021 
00022 template<typename ConsumerType,
00023          typename ConsumerPrxType,
00024          typename InterfacePrxType,
00025          typename DataType,
00026          typename DescriptionType>
00027 class GenericGpsProbe : public ConsumerType, public orcaprobe::InterfaceProbe
00028 {
00029 
00030 public:
00031 
00032     GenericGpsProbe( const orca::FQInterfaceName& name,
00033                      orcaprobe::IDisplay& display,                     
00034                      const std::string &id,
00035                      const orcaice::Context& context );
00036 
00037     virtual int loadOperationEvent( const int index, orcacm::OperationData& data );
00038     
00039     virtual void setData(const DataType& data, const Ice::Current&);
00040 
00041 private:
00042 
00043     int loadGetDescription( orcacm::OperationData& data );
00044     int loadGetData( orcacm::OperationData& data );
00045     int loadSubscribe( orcacm::OperationData& data );
00046     int loadUnsubscribe( orcacm::OperationData& data );
00047 
00048     ConsumerPrxType callbackPrx_;
00049     orcacm::OperationData subscribeOperationData_;
00050 };
00051 
00052 template<typename ConsumerType,
00053          typename ConsumerPrxType,
00054          typename InterfacePrxType,
00055          typename DataType,
00056          typename DescriptionType>
00057 GenericGpsProbe<ConsumerType,
00058                 ConsumerPrxType,
00059                 InterfacePrxType,
00060                 DataType,
00061                 DescriptionType>::GenericGpsProbe( const orca::FQInterfaceName&  name,
00062                                                    orcaprobe::IDisplay&     display,
00063                                                    const std::string&            id,
00064                                                    const orcaice::Context&       context )
00065     : InterfaceProbe(name,display,context)
00066 {
00067     id_ = id;
00068     
00069     addOperation( "getDescription" );
00070     addOperation( "getData" );
00071     addOperation( "subscribe" );
00072     addOperation( "unsubscribe" );
00073 
00074     Ice::ObjectPtr consumer = this;
00075     callbackPrx_ = orcaice::createConsumerInterface<ConsumerPrxType>( context_, consumer );
00076 }
00077 
00078 template<typename ConsumerType,
00079          typename ConsumerPrxType,
00080          typename InterfacePrxType,
00081          typename DataType,
00082          typename DescriptionType>
00083 int 
00084 GenericGpsProbe<ConsumerType,
00085                 ConsumerPrxType,
00086                 InterfacePrxType,
00087                 DataType,
00088                 DescriptionType>::loadOperationEvent( const int index,
00089                                                       orcacm::OperationData& data )
00090 {
00091     switch ( index )
00092     {
00093     case orcaprobe::UserIndex :
00094         return loadGetDescription( data );
00095     case orcaprobe::UserIndex+1 :
00096         return loadGetData( data );
00097     case orcaprobe::UserIndex+2 :
00098         return loadSubscribe( data );
00099     case orcaprobe::UserIndex+3 :
00100         return loadUnsubscribe( data );
00101     }
00102     return 1;
00103 }
00104 
00105 template<typename ConsumerType,
00106          typename ConsumerPrxType,
00107          typename InterfacePrxType,
00108          typename DataType,
00109          typename DescriptionType>
00110 int 
00111 GenericGpsProbe<ConsumerType,
00112                 ConsumerPrxType,
00113                 InterfacePrxType,
00114                 DataType,
00115                 DescriptionType>::loadGetData( orcacm::OperationData& data )
00116 {
00117     DataType result;
00118     try
00119     {
00120         InterfacePrxType derivedPrx = InterfacePrxType::checkedCast(prx_);
00121         result = derivedPrx->getData();
00122         orcaprobe::reportResult( data, "data", ifacestring::toString(result) );
00123     }
00124     catch( const Ice::Exception& e )
00125     {
00126         std::stringstream ss;
00127         ss<<e<<std::endl;
00128         orcaprobe::reportException( data, ss.str() );
00129     }
00130     return 0;
00131 }
00132 
00133 template<typename ConsumerType,
00134          typename ConsumerPrxType,
00135          typename InterfacePrxType,
00136          typename DataType,
00137          typename DescriptionType>
00138 int 
00139 GenericGpsProbe<ConsumerType,
00140                 ConsumerPrxType,
00141                 InterfacePrxType,
00142                 DataType,
00143                 DescriptionType>::loadGetDescription( orcacm::OperationData& data )
00144 {
00145     DescriptionType result;
00146     orcacm::ResultHeader res;
00147 
00148     try
00149     {
00150         InterfacePrxType derivedPrx = InterfacePrxType::checkedCast(prx_);
00151         result = derivedPrx->getDescription();
00152         orcaprobe::reportResult( data, "data", ifacestring::toString(result) );
00153     }
00154     catch( const Ice::Exception& e )
00155     {
00156         std::stringstream ss;
00157         ss<<e<<std::endl;
00158         orcaprobe::reportException( data, ss.str() );
00159     }
00160     return 0;
00161 }
00162 
00163 template<typename ConsumerType,
00164          typename ConsumerPrxType,
00165          typename InterfacePrxType,
00166          typename DataType,
00167          typename DescriptionType>
00168 int 
00169 GenericGpsProbe<ConsumerType,
00170                 ConsumerPrxType,
00171                 InterfacePrxType,
00172                 DataType,
00173                 DescriptionType>::loadSubscribe( orcacm::OperationData& data )
00174 {
00175     try
00176     {
00177         InterfacePrxType derivedPrx = InterfacePrxType::checkedCast(prx_);
00178         derivedPrx->subscribe( callbackPrx_ );
00179         orcaprobe::reportSubscribed( data );
00180 
00181         // save the op data structure so we can use it when the data arrives
00182         subscribeOperationData_ = data;
00183     }
00184     catch( const Ice::Exception& e )
00185     {
00186         std::stringstream ss;
00187         ss<<e<<std::endl;
00188         orcaprobe::reportException( data, ss.str() );
00189     }
00190     return 0;
00191 }
00192 
00193 template<typename ConsumerType,
00194          typename ConsumerPrxType,
00195          typename InterfacePrxType,
00196          typename DataType,
00197          typename DescriptionType>
00198 int 
00199 GenericGpsProbe<ConsumerType,
00200                 ConsumerPrxType,
00201                 InterfacePrxType,
00202                 DataType,
00203                 DescriptionType>::loadUnsubscribe( orcacm::OperationData& data )
00204 {    
00205     try
00206     {
00207         InterfacePrxType derivedPrx = InterfacePrxType::checkedCast(prx_);
00208         derivedPrx->unsubscribe( callbackPrx_ );
00209         orcaprobe::reportUnsubscribed( data );
00210     }
00211     catch( const Ice::Exception& e )
00212     {
00213         std::stringstream ss;
00214         ss<<e<<std::endl;
00215         orcaprobe::reportException( data, ss.str() );
00216     }
00217     return 0;
00218 }
00219 
00220 template<typename ConsumerType,
00221          typename ConsumerPrxType,
00222          typename InterfacePrxType,
00223          typename DataType,
00224          typename DescriptionType>
00225 void 
00226 GenericGpsProbe<ConsumerType,
00227                 ConsumerPrxType,
00228                 InterfacePrxType,
00229                 DataType,
00230                 DescriptionType>::setData( const DataType& result,
00231                                            const Ice::Current& )
00232 {
00233     subscribeOperationData_.results.clear();
00234     orcaprobe::reportResult( subscribeOperationData_, "data", ifacestring::toString(result) );
00235     display_.setOperationData( subscribeOperationData_ );
00236 };
00237 
00238 } // namespace
00239 
00240 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5