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 Project Download Mailing lists
|
autologgers.h00001 #ifndef ORCALOGFACTORY_AUTOLOGGERS_H 00002 #define ORCALOGFACTORY_AUTOLOGGERS_H 00003 00004 #include <orcalog/autologger.h> 00005 #include <orcalogfactory/logwriters.h> 00006 #include <orcaice/connectutils.h> 00007 #include <orcaice/timeutils.h> 00008 00009 namespace orcalogfactory { 00010 00011 // 00012 // A set of AutoLoggers: ie loggers which run continuously as soon as they're 00013 // initialised 00014 // 00015 00017 00022 template<class DataType, 00023 class ConsumerType, 00024 class ConsumerPrxType, 00025 class PrxType, 00026 class LogWriterType> 00027 class GenericAutoLogger : public ConsumerType, public orcalog::AutoLogger 00028 { 00029 public: 00030 00031 virtual ~GenericAutoLogger() {} 00032 00033 // Assumes the ConsumerType's method is called setData 00034 virtual void setData(const DataType& data, const Ice::Current&) 00035 { logWriter_->write(data,orcaice::getNow()); } 00036 00037 // Inherited from orcalog::AutoLogger 00038 virtual void init( const orcalog::LogWriterInfo &logWriterInfo, 00039 orcalog::MasterFileWriter &masterFileWriter ) 00040 { 00041 logWriter_.reset( new LogWriterType ); 00042 logWriter_->checkFormat( logWriterInfo.format ); 00043 logWriter_->init( logWriterInfo, masterFileWriter ); 00044 } 00045 00046 virtual void startLogging() 00047 { 00048 // may throw 00049 PrxType objectPrx; 00050 orcaice::connectToInterfaceWithTag<PrxType>( logWriter_->logWriterInfo().context, 00051 objectPrx, 00052 logWriter_->logWriterInfo().interfaceTag ); 00053 00054 // Allow derived classes to do something special (like get description) 00055 setup(objectPrx,*logWriter_); 00056 00057 Ice::ObjectPtr consumer = this; 00058 ConsumerPrxType callbackPrx = 00059 orcaice::createConsumerInterface<ConsumerPrxType>( logWriter_->logWriterInfo().context, 00060 consumer ); 00061 00062 objectPrx->subscribe( callbackPrx ); 00063 } 00064 00065 protected: 00066 00067 // Called during initialisation 00068 virtual void setup( PrxType &objectPrx, LogWriterType &logWriter ) {} 00069 00070 private: 00071 00072 std::auto_ptr<LogWriterType> logWriter_; 00073 }; 00074 00076 00077 typedef GenericAutoLogger<orca::CpuData, 00078 orca::CpuConsumer, 00079 orca::CpuConsumerPrx, 00080 orca::CpuPrx, 00081 CpuLogWriter> CpuAutoLogger; 00082 00084 00085 class DriveBicycleAutoLogger : public GenericAutoLogger<orca::DriveBicycleData, 00086 orca::DriveBicycleConsumer, 00087 orca::DriveBicycleConsumerPrx, 00088 orca::DriveBicyclePrx, 00089 DriveBicycleLogWriter> 00090 { 00091 private: 00092 void setup( orca::DriveBicyclePrx &objectPrx, DriveBicycleLogWriter &logWriter ) 00093 { 00094 logWriter.write( objectPrx->getDescription() ); 00095 } 00096 }; 00097 00099 00100 typedef GenericAutoLogger<orca::ImuData, 00101 orca::ImuConsumer, 00102 orca::ImuConsumerPrx, 00103 orca::ImuPrx, 00104 ImuLogWriter> ImuAutoLogger; 00105 00107 00108 class LaserScanner2dAutoLogger : public orca::RangeScanner2dConsumer, public orcalog::AutoLogger 00109 { 00110 public: 00111 virtual ~LaserScanner2dAutoLogger() {} 00112 00113 virtual void setData(const orca::RangeScanner2dDataPtr& data, const Ice::Current&) 00114 { 00115 // special case: do not copy to other loggers! 00116 // we assume that the data is really LaserScanner2dDataPtr but it has to be cast 00117 // @todo: what if it's not the right type? 00118 orca::LaserScanner2dDataPtr laserData = orca::LaserScanner2dDataPtr::dynamicCast( data ); 00119 logWriter_->write(laserData,orcaice::getNow()); 00120 } 00121 00122 virtual void init( const orcalog::LogWriterInfo &logWriterInfo, 00123 orcalog::MasterFileWriter &masterFileWriter ) 00124 { 00125 logWriter_.reset( new LaserScanner2dLogWriter ); 00126 logWriter_->checkFormat( logWriterInfo.format ); 00127 logWriter_->init( logWriterInfo, masterFileWriter ); 00128 } 00129 00130 virtual void startLogging() 00131 { 00132 orca::LaserScanner2dPrx objectPrx; 00133 orcaice::connectToInterfaceWithTag( logWriter_->logWriterInfo().context, 00134 objectPrx, 00135 logWriter_->logWriterInfo().interfaceTag ); 00136 00137 orca::RangeScanner2dDescription descr = objectPrx->getDescription(); 00138 logWriter_->write( descr ); 00139 00140 Ice::ObjectPtr consumer = this; 00141 orca::RangeScanner2dConsumerPrx callbackPrx = 00142 orcaice::createConsumerInterface<orca::RangeScanner2dConsumerPrx>( logWriter_->logWriterInfo().context, 00143 consumer ); 00144 00145 objectPrx->subscribe( callbackPrx ); 00146 } 00147 private: 00148 std::auto_ptr<LaserScanner2dLogWriter> logWriter_; 00149 }; 00150 00152 00153 class Localise2dAutoLogger : public GenericAutoLogger<orca::Localise2dData, 00154 orca::Localise2dConsumer, 00155 orca::Localise2dConsumerPrx, 00156 orca::Localise2dPrx, 00157 Localise2dLogWriter> 00158 { 00159 private: 00160 void setup( orca::Localise2dPrx &objectPrx, Localise2dLogWriter &logWriter ) 00161 { 00162 logWriter.write( objectPrx->getVehicleGeometry() ); 00163 } 00164 }; 00165 00167 00168 class Localise3dAutoLogger : public GenericAutoLogger<orca::Localise3dData, 00169 orca::Localise3dConsumer, 00170 orca::Localise3dConsumerPrx, 00171 orca::Localise3dPrx, 00172 Localise3dLogWriter> 00173 { 00174 private: 00175 void setup( orca::Localise3dPrx &objectPrx, Localise3dLogWriter &logWriter ) 00176 { 00177 logWriter.write( objectPrx->getVehicleGeometry() ); 00178 } 00179 }; 00180 00182 00183 class Odometry2dAutoLogger : public GenericAutoLogger<orca::Odometry2dData, 00184 orca::Odometry2dConsumer, 00185 orca::Odometry2dConsumerPrx, 00186 orca::Odometry2dPrx, 00187 Odometry2dLogWriter> 00188 { 00189 private: 00190 void setup( orca::Odometry2dPrx &objectPrx, Odometry2dLogWriter &logWriter ) 00191 { 00192 logWriter.write( objectPrx->getDescription() ); 00193 } 00194 }; 00195 00197 00198 class Odometry3dAutoLogger : public GenericAutoLogger<orca::Odometry3dData, 00199 orca::Odometry3dConsumer, 00200 orca::Odometry3dConsumerPrx, 00201 orca::Odometry3dPrx, 00202 Odometry3dLogWriter> 00203 { 00204 private: 00205 void setup( orca::Odometry3dPrx &objectPrx, Odometry3dLogWriter &logWriter ) 00206 { 00207 logWriter.write( objectPrx->getDescription() ); 00208 } 00209 }; 00210 00212 00213 typedef GenericAutoLogger<orca::PolarFeature2dData, 00214 orca::PolarFeature2dConsumer, 00215 orca::PolarFeature2dConsumerPrx, 00216 orca::PolarFeature2dPrx, 00217 PolarFeature2dLogWriter> PolarFeature2dAutoLogger; 00218 00220 00221 typedef GenericAutoLogger<orca::PowerData, 00222 orca::PowerConsumer, 00223 orca::PowerConsumerPrx, 00224 orca::PowerPrx, 00225 PowerLogWriter> PowerAutoLogger; 00226 00228 00229 typedef GenericAutoLogger<orca::WifiData, 00230 orca::WifiConsumer, 00231 orca::WifiConsumerPrx, 00232 orca::WifiPrx, 00233 WifiLogWriter> WifiAutoLogger; 00234 00236 00237 class GpsAutoLogger : public GenericAutoLogger<orca::GpsData, 00238 orca::GpsConsumer, 00239 orca::GpsConsumerPrx, 00240 orca::GpsPrx, 00241 GpsLogWriter> 00242 { 00243 private: 00244 void setup( orca::GpsPrx &objectPrx, GpsLogWriter &logWriter ) 00245 { 00246 logWriter.write( objectPrx->getDescription() ); 00247 } 00248 }; 00249 00250 } 00251 00252 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)