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

 

         

snapshotloggers.h

00001 #ifndef ORCALOGFACTORY_SNAPSHOTLOGGERS_H
00002 #define ORCALOGFACTORY_SNAPSHOTLOGGERS_H
00003 
00004 #include <IceUtil/Mutex.h>
00005 #include <orcalog/snapshotloggerfactory.h>
00006 #include <orcalog/snapshotlogbuffer.h>
00007 #include <orcalogfactory/logwriters.h>
00008 #include <orcaice/connectutils.h>
00009 #include <orcaice/icestormutils.h>
00010 
00011 namespace orcalogfactory {
00012 
00013     //
00014     // A set of SnapshotLoggers: ie loggers which run continuously as soon as they're
00015     //                       initialised
00016     //
00017 
00019 
00024     template<class DataType,
00025              class ConsumerType,
00026              class ConsumerPrxType,
00027              class PrxType,
00028              class LogWriterType>
00029     class GenericSnapshotLogger : public ConsumerType, public orcalog::SnapshotLogger
00030     {
00031     public:
00032 
00033         GenericSnapshotLogger()
00034             : isTakingSnapshot_(false)
00035             {}
00036         virtual ~GenericSnapshotLogger() {}
00037 
00038         // Assumes the ConsumerType's method is called setData
00039         virtual void setData(const DataType& data, const Ice::Current&)
00040             { 
00041                 {
00042                     // Don't accept new data while taking a snapshot.
00043                     IceUtil::Mutex::Lock lock(mutex_);
00044                     if ( isTakingSnapshot_ ) return;
00045                 }
00046                 snapshotLogBuffer_->addItem( data );
00047             }
00048 
00049         // Inherited from orcalog::SnapshotLogger
00050         virtual void init( const std::string &format, double timeWindowSec )
00051             {
00052                 LogWriterType dummyLogWriter;
00053                 dummyLogWriter.checkFormat( format );
00054                 snapshotLogBuffer_.reset( new orcalog::SnapshotLogBuffer<DataType,
00055                                                                          LogWriterType>( timeWindowSec ) );
00056             }
00057 
00058         virtual void subscribe( orcaice::Context &context, const std::string &interfaceTag )
00059             {
00060                 // may throw
00061                 PrxType objectPrx;
00062                 orcaice::connectToInterfaceWithTag<PrxType>( context,
00063                                                              objectPrx,
00064                                                              interfaceTag );
00065 
00066                 Ice::ObjectPtr consumer = this;
00067                 ConsumerPrxType callbackPrx = 
00068                     orcaice::createConsumerInterface<ConsumerPrxType>( context,
00069                                                                        consumer );
00070 
00071                 objectPrx->subscribe( callbackPrx );
00072             }
00073 
00074         virtual void prepareForSnapshot( const orcalog::LogWriterInfo &logWriterInfo,
00075                                          orcalog::MasterFileWriter    &masterFileWriter )
00076             {
00077                 {
00078                     IceUtil::Mutex::Lock lock(mutex_);
00079                     isTakingSnapshot_ = true;
00080                 }
00081                 logWriter_.reset( new LogWriterType );
00082                 logWriter_->init( logWriterInfo, masterFileWriter );
00083                 
00084                 // Allow interface-specific stuff to happen (eg getting description)
00085                 doSpecialisedSnapshotPreparation( *logWriter_ );
00086             }
00087 
00088         virtual void finaliseSnapshot()
00089             {
00090                 {
00091                     IceUtil::Mutex::Lock lock(mutex_);
00092                     isTakingSnapshot_ = false;
00093                 }
00094             }
00095 
00096         virtual unsigned int snapshotBufferSize() const
00097             { return snapshotLogBuffer_->bufferSize(); }
00098         virtual const orca::Time &oldestArrivalTime() const
00099             { return snapshotLogBuffer_->oldestArrivalTime(); }
00100         virtual void writeOldestObjToLogAndDiscard()
00101             { snapshotLogBuffer_->writeOldestObjToLogAndDiscard(*logWriter_); }
00102 
00103     protected:
00104 
00105         // Called during initialisation
00106         virtual void doSpecialisedSnapshotPreparation( LogWriterType &logWriter ) {}
00107 
00108     private:
00109 
00110         bool                                      isTakingSnapshot_;
00111         std::auto_ptr< orcalog::SnapshotLogBuffer<DataType,LogWriterType> > snapshotLogBuffer_;
00112         std::auto_ptr<LogWriterType>              logWriter_;
00113         IceUtil::Mutex                            mutex_;
00114     };
00115 
00117 
00118     typedef GenericSnapshotLogger<orca::CpuData,
00119                               orca::CpuConsumer,
00120                               orca::CpuConsumerPrx,
00121                               orca::CpuPrx,
00122                               CpuLogWriter> CpuSnapshotLogger;
00123 
00125 
00126     class DriveBicycleSnapshotLogger : public GenericSnapshotLogger<orca::DriveBicycleData,
00127                                                             orca::DriveBicycleConsumer,
00128                                                             orca::DriveBicycleConsumerPrx,
00129                                                             orca::DriveBicyclePrx,
00130                                                             DriveBicycleLogWriter>
00131     {
00132     private:
00133         void doSpecialisedSnapshotPreparation( DriveBicycleLogWriter &logWriter )
00134             {
00135                 // may throw
00136                 orca::DriveBicyclePrx objectPrx;
00137                 orcaice::connectToInterfaceWithTag( logWriter.logWriterInfo().context,
00138                                                     objectPrx,
00139                                                     logWriter.logWriterInfo().interfaceTag );
00140                 logWriter.write( objectPrx->getDescription() );
00141             }
00142     };
00143 
00145 
00146     typedef GenericSnapshotLogger<orca::ImuData,
00147                               orca::ImuConsumer,
00148                               orca::ImuConsumerPrx,
00149                               orca::ImuPrx,
00150                               ImuLogWriter> ImuSnapshotLogger;
00151 
00153 
00154     class LaserScanner2dSnapshotLogger : public orca::RangeScanner2dConsumer, public orcalog::SnapshotLogger
00155     {
00156     public:
00157 
00158         LaserScanner2dSnapshotLogger()
00159             : isTakingSnapshot_(false)
00160             {}
00161         virtual ~LaserScanner2dSnapshotLogger() {}
00162 
00163         virtual void setData(const orca::RangeScanner2dDataPtr& data, const Ice::Current &c)
00164             { 
00165                 {
00166                     // Don't accept new data while taking a snapshot.
00167                     IceUtil::Mutex::Lock lock(mutex_);
00168                     if ( isTakingSnapshot_ ) return;
00169                 }
00170                 // special case: do not copy to other loggers!
00171                 // we assume that the data is really LaserScanner2dDataPtr but it has to be cast
00172                 // @todo: what if it's not the right type?
00173                 orca::LaserScanner2dDataPtr laserData = orca::LaserScanner2dDataPtr::dynamicCast( data );
00174                 snapshotLogBuffer_->addItem( laserData );
00175             }
00176 
00177         virtual void init( const std::string &format, double timeWindowSec )
00178             {
00179                 LaserScanner2dLogWriter dummyLogWriter;
00180                 dummyLogWriter.checkFormat( format );
00181                 snapshotLogBuffer_.reset( new orcalog::SnapshotLogBuffer<orca::LaserScanner2dDataPtr,
00182                                                                          LaserScanner2dLogWriter>( timeWindowSec ) );
00183             }
00184 
00185         virtual void subscribe( orcaice::Context &context, const std::string &interfaceTag )
00186             {
00187                 orca::LaserScanner2dPrx objectPrx;
00188                 orcaice::connectToInterfaceWithTag( context,
00189                                                     objectPrx,
00190                                                     interfaceTag );
00191 
00192                 Ice::ObjectPtr consumer = this;
00193                 orca::RangeScanner2dConsumerPrx callbackPrx = 
00194                     orcaice::createConsumerInterface<orca::RangeScanner2dConsumerPrx>( context,
00195                                                                                        consumer );
00196 
00197                 objectPrx->subscribe( callbackPrx );
00198             }
00199 
00200         virtual void prepareForSnapshot( const orcalog::LogWriterInfo &logWriterInfo,
00201                                          orcalog::MasterFileWriter    &masterFileWriter )
00202             {
00203                 {
00204                     IceUtil::Mutex::Lock lock(mutex_);
00205                     isTakingSnapshot_ = true;
00206                 }
00207                 logWriter_.reset( new LaserScanner2dLogWriter );
00208                 logWriter_->init( logWriterInfo, masterFileWriter );
00209                 
00210                 // Allow interface-specific stuff to happen (eg getting description)
00211                 // doSpecialisedSnapshotPreparation( *logWriter_ );
00212                 // may throw
00213                 orca::LaserScanner2dPrx objectPrx;
00214                 orcaice::connectToInterfaceWithTag( logWriter_->logWriterInfo().context,
00215                                                     objectPrx,
00216                                                     logWriter_->logWriterInfo().interfaceTag );
00217                 logWriter_->write( objectPrx->getDescription() );
00218             }
00219         virtual void finaliseSnapshot()
00220             {
00221                 {
00222                     IceUtil::Mutex::Lock lock(mutex_);
00223                     isTakingSnapshot_ = false;
00224                 }
00225             }
00226         virtual unsigned int snapshotBufferSize() const
00227             { return snapshotLogBuffer_->bufferSize(); }
00228         virtual const orca::Time &oldestArrivalTime() const
00229             { return snapshotLogBuffer_->oldestArrivalTime(); }
00230         virtual void writeOldestObjToLogAndDiscard()
00231             { snapshotLogBuffer_->writeOldestObjToLogAndDiscard(*logWriter_); }
00232 
00233     private:
00234 
00235         bool                                      isTakingSnapshot_;
00236         std::auto_ptr< orcalog::SnapshotLogBuffer<orca::LaserScanner2dDataPtr,
00237                                                   LaserScanner2dLogWriter> > snapshotLogBuffer_;
00238         std::auto_ptr<LaserScanner2dLogWriter>    logWriter_;
00239         IceUtil::Mutex                            mutex_;
00240 
00241     };
00242 
00244 
00245     class Localise2dSnapshotLogger : public GenericSnapshotLogger<orca::Localise2dData,
00246                                                           orca::Localise2dConsumer,
00247                                                           orca::Localise2dConsumerPrx,
00248                                                           orca::Localise2dPrx,
00249                                                           Localise2dLogWriter>
00250     {
00251     private:
00252         void doSpecialisedSnapshotPreparation( Localise2dLogWriter &logWriter )
00253             {
00254                 // may throw
00255                 orca::Localise2dPrx objectPrx;
00256                 orcaice::connectToInterfaceWithTag( logWriter.logWriterInfo().context,
00257                                                     objectPrx,
00258                                                     logWriter.logWriterInfo().interfaceTag );
00259                 logWriter.write( objectPrx->getDescription() );
00260             }
00261     };
00262 
00264 
00265     class Localise3dSnapshotLogger : public GenericSnapshotLogger<orca::Localise3dData,
00266                                                             orca::Localise3dConsumer,
00267                                                             orca::Localise3dConsumerPrx,
00268                                                             orca::Localise3dPrx,
00269                                                             Localise3dLogWriter>
00270     {
00271     private:
00272         void doSpecialisedSnapshotPreparation( Localise3dLogWriter &logWriter )
00273             {
00274                 // may throw
00275                 orca::Localise3dPrx objectPrx;
00276                 orcaice::connectToInterfaceWithTag( logWriter.logWriterInfo().context,
00277                                                     objectPrx,
00278                                                     logWriter.logWriterInfo().interfaceTag );
00279                 logWriter.write( objectPrx->getDescription() );
00280             }
00281     };
00282 
00284 
00285     class Odometry2dSnapshotLogger : public GenericSnapshotLogger<orca::Odometry2dData,
00286                                                             orca::Odometry2dConsumer,
00287                                                             orca::Odometry2dConsumerPrx,
00288                                                             orca::Odometry2dPrx,
00289                                                             Odometry2dLogWriter>
00290     {
00291     private:
00292         void doSpecialisedSnapshotPreparation( Odometry2dLogWriter &logWriter )
00293             {
00294                 // may throw
00295                 orca::Odometry2dPrx objectPrx;
00296                 orcaice::connectToInterfaceWithTag( logWriter.logWriterInfo().context,
00297                                                     objectPrx,
00298                                                     logWriter.logWriterInfo().interfaceTag );
00299                 logWriter.write( objectPrx->getDescription() );
00300             }
00301     };
00302 
00304 
00305     class Odometry3dSnapshotLogger : public GenericSnapshotLogger<orca::Odometry3dData,
00306                                                             orca::Odometry3dConsumer,
00307                                                             orca::Odometry3dConsumerPrx,
00308                                                             orca::Odometry3dPrx,
00309                                                             Odometry3dLogWriter>
00310     {
00311     private:
00312         void doSpecialisedSnapshotPreparation( Odometry3dLogWriter &logWriter )
00313             {
00314                 // may throw
00315                 orca::Odometry3dPrx objectPrx;
00316                 orcaice::connectToInterfaceWithTag( logWriter.logWriterInfo().context,
00317                                                     objectPrx,
00318                                                     logWriter.logWriterInfo().interfaceTag );
00319                 logWriter.write( objectPrx->getDescription() );
00320             }
00321     };
00322 
00324 
00325     typedef GenericSnapshotLogger<orca::PolarFeature2dData,
00326                               orca::PolarFeature2dConsumer,
00327                               orca::PolarFeature2dConsumerPrx,
00328                               orca::PolarFeature2dPrx,
00329                               PolarFeature2dLogWriter> PolarFeature2dSnapshotLogger;
00330 
00332     
00333     typedef GenericSnapshotLogger<orca::PowerData,
00334                               orca::PowerConsumer,
00335                               orca::PowerConsumerPrx,
00336                               orca::PowerPrx,
00337                               PowerLogWriter> PowerSnapshotLogger;
00338 
00340 
00341     typedef GenericSnapshotLogger<orca::WifiData,
00342                               orca::WifiConsumer,
00343                               orca::WifiConsumerPrx,
00344                               orca::WifiPrx,
00345                               WifiLogWriter> WifiSnapshotLogger;
00346 
00348 
00349     class GpsSnapshotLogger : public GenericSnapshotLogger<orca::GpsData,
00350                                                             orca::GpsConsumer,
00351                                                             orca::GpsConsumerPrx,
00352                                                             orca::GpsPrx,
00353                                                             GpsLogWriter>
00354     {
00355     private:
00356         void doSpecialisedSnapshotPreparation( GpsLogWriter &logWriter )
00357             {
00358                 // may throw
00359                 orca::GpsPrx objectPrx;
00360                 orcaice::connectToInterfaceWithTag( logWriter.logWriterInfo().context,
00361                                                     objectPrx,
00362                                                     logWriter.logWriterInfo().interfaceTag );
00363                 logWriter.write( objectPrx->getDescription() );
00364             }
00365     };
00366 
00367 }
00368 
00369 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5