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

 

         

replayer.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_ORCALOG_REPLAYER_H
00012 #define ORCA_ORCALOG_REPLAYER_H
00013 
00014 #include <string>
00015 #include <orcalog/orcalog.h>
00016 
00017 namespace orcalog
00018 {
00019 
00022 class Replayer
00023 {
00024 public:
00025 
00026     virtual ~Replayer() {}
00027 
00028     virtual void init() {}
00029 
00031     virtual void replayData( int index )=0;
00032 
00034     virtual std::string toString() const=0;
00035     
00036 };
00037 
00040 
00041 
00042 // fwd declarations (ignore, they're defined below)
00043 template<class LogReaderType,
00044          class IfaceImplType>
00045 class DefaultIfaceImplSetup;
00046 template<class LogReaderType,
00047          class IfaceImplType,
00048          class DescriptionType>
00049 class DescriptionIfaceImplSetup;
00050 
00051 
00053 
00054 
00055 //
00056 // Generic Replayer.  The last template argument is a class whose constructor
00057 // will set up the IfaceImpl (including reading a description if necessary).
00058 //
00059 template< class IfaceImplType,
00060           class LogReaderType,
00061           class DataType,
00062           class IfaceImplSetup=DefaultIfaceImplSetup<LogReaderType,IfaceImplType> >
00063 class GenericReplayer : public orcalog::Replayer
00064 {
00065 public:
00066 
00067     GenericReplayer( const orcalog::LogReaderInfo &logReaderInfo )
00068         : logReader_( logReaderInfo )
00069         {}
00070     virtual ~GenericReplayer() {}
00071 
00072     void init()
00073         {
00074             logReader_.init();
00075             IfaceImplSetup( logReader_, iface_ );
00076             iface_->initInterface();
00077         }
00078 
00079     void replayData( int index )
00080         {
00081             logReader_.setLogIndex( index );
00082             logReader_.read( data_ );
00083             // Don't setAndSend it: otherwise the interface will
00084             // remember the thing we last sent, which will behave
00085             // badly if we rewind the log then reconnect a client:
00086             // they'll get pushed something from the future.
00087             // iface_->localSetAndSend( data_ );
00088             iface_->localSend( data_ );
00089         }
00090 
00091     std::string toString() const { return logReader_.toString(); }
00092 
00093 protected:
00094 
00095     IceUtil::Handle<IfaceImplType> iface_;
00096     LogReaderType                  logReader_;
00097     DataType                       data_;
00098 
00099 };
00100 
00101 //
00102 // Useful defaults for setting up the IfaceImpl:
00103 //
00104 
00105 //
00106 // This default will set up the IfaceImpl with no description required.
00107 //
00108 template<class LogReaderType,
00109          class IfaceImplType>
00110 class DefaultIfaceImplSetup {
00111 public:
00112     DefaultIfaceImplSetup( LogReaderType                  &logReader,
00113                            IceUtil::Handle<IfaceImplType> &iface )
00114         {
00115             iface = new IfaceImplType( logReader.logReaderInfo().context,
00116                                        logReader.logReaderInfo().interfaceName );
00117         }
00118 };
00119 //
00120 // This version works when all that needs to happen is that a description
00121 // needs to be read in.
00122 //
00123 template<class LogReaderType,
00124          class IfaceImplType,
00125          class DescriptionType>
00126 class DescriptionIfaceImplSetup {
00127 public:
00128     DescriptionIfaceImplSetup( LogReaderType                  &logReader,
00129                                IceUtil::Handle<IfaceImplType> &iface )
00130         {
00131             DescriptionType descr;
00132             logReader.read( descr );
00133             iface = new IfaceImplType( descr,
00134                                        logReader.logReaderInfo().context,
00135                                        logReader.logReaderInfo().interfaceName );
00136         }
00137 };
00138 
00139 
00140 } // namespace
00141 
00142 #endif
 

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


Generated for Orca Robotics by  doxygen 1.4.5