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

 

         

snapshotlogger.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 ORCA_LOGGER_SNAPSHOT_LOGGER_H
00012 #define ORCA_LOGGER_SNAPSHOT_LOGGER_H
00013 
00014 #include <orcalog/logwriterinfo.h>
00015 #include <orcalog/masterfilewriter.h>
00016 #include <orcaifaceimpl/consumerImpl.h>
00017 #include <IceUtil/Mutex.h>
00018 #include <orcalog/snapshotlogbuffer.h>
00019 
00020 namespace orcalog
00021 {
00022 
00025 class SnapshotLogger {
00026 public:
00027     virtual ~SnapshotLogger() {}
00028 
00029     // format is any string.  timeWindowSec is the length of history
00030     // that will be logged in a snapshot.
00031     virtual void init( const std::string &format, double timeWindowSec )=0;
00032     virtual void subscribe( const std::string &interfaceTag )=0;
00033 
00034     // Call these before and after taking the snapshot
00035     virtual void prepareForSnapshot( const LogWriterInfo &logWriterInfo,
00036                                      MasterFileWriter &masterFileWriter ) = 0;
00037     // This is always safe to call, even if prepareForSnapshot() hasn't been called.
00038     virtual void finaliseSnapshot()=0;
00039 
00040     // Call these during snapshotting
00041     virtual unsigned int snapshotBufferSize() const=0;
00042     virtual const orca::Time &oldestArrivalTime() const=0;
00043     virtual void writeOldestObjToLogAndDiscard()=0;
00044 };
00045 
00050 template<class ProviderType, 
00051          class ConsumerType,  
00052          class ObjectType,
00053          class LogWriterType>
00054     class GenericSnapshotLogger : 
00055                   public orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>, 
00056                   public orcalog::SnapshotLogger
00057 {
00058 using orcaifaceimpl::ConsumerSubscriber::subscribeWithTag;
00059 
00060 public:
00061     GenericSnapshotLogger( const orcaice::Context &context ) :
00062         orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>( context ),
00063         isTakingSnapshot_(false)
00064     {
00065     }
00066 
00067     virtual void dataEvent( const ObjectType& data ) 
00068     {
00069         {
00070             // Don't accept new data while taking a snapshot.
00071             IceUtil::Mutex::Lock lock(mutex_);
00072             if ( isTakingSnapshot_ ) return;
00073         }
00074         snapshotLogBuffer_->addItem( data );
00075     }
00076 
00077     // Inherited from orcalog::SnapshotLogger
00078     virtual void subscribe( const std::string &interfaceTag )
00079         { subscribeWithTag( interfaceTag ); };
00080 
00081     virtual void init( const std::string &format, double timeWindowSec )
00082     {
00083         LogWriterType dummyLogWriter;
00084         dummyLogWriter.checkFormat( format );
00085         snapshotLogBuffer_.reset( new orcalog::SnapshotLogBuffer<ObjectType,
00086                                                                   LogWriterType>( timeWindowSec ) );
00087     }
00088 
00089     virtual void prepareForSnapshot( const orcalog::LogWriterInfo &logWriterInfo,
00090                                       orcalog::MasterFileWriter    &masterFileWriter )
00091     {
00092         {
00093             IceUtil::Mutex::Lock lock(mutex_);
00094             isTakingSnapshot_ = true;
00095         }
00096         logWriter_.reset( new LogWriterType );
00097         logWriter_->init( logWriterInfo, masterFileWriter );
00098         
00099         // Allow interface-specific stuff to happen (eg getting description)
00100         doSpecialisedSnapshotPreparation( *logWriter_ );
00101     }
00102 
00103     virtual void finaliseSnapshot()
00104     {
00105         {
00106             IceUtil::Mutex::Lock lock(mutex_);
00107             isTakingSnapshot_ = false;
00108         }
00109     }
00110 
00111     virtual unsigned int snapshotBufferSize() const
00112         { return snapshotLogBuffer_->bufferSize(); }
00113     virtual const orca::Time &oldestArrivalTime() const
00114         { return snapshotLogBuffer_->oldestArrivalTime(); }
00115     virtual void writeOldestObjToLogAndDiscard()
00116         { snapshotLogBuffer_->writeOldestObjToLogAndDiscard(*logWriter_); }
00117 
00118 protected:
00119 
00120     // Called during initialisation
00121     virtual void doSpecialisedSnapshotPreparation( LogWriterType &logWriter ) {}
00122 
00123 private:
00124 
00125     bool                                      isTakingSnapshot_;
00126     std::auto_ptr< orcalog::SnapshotLogBuffer<ObjectType,LogWriterType> > snapshotLogBuffer_;
00127     std::auto_ptr<LogWriterType>              logWriter_;
00128     IceUtil::Mutex                            mutex_;
00129 };
00130 
00131 }
00132 
00133 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5