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 Project Download Mailing lists
|
autologger.h00001 /* 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_AUTO_LOGGER_H 00012 #define ORCA_LOGGER_AUTO_LOGGER_H 00013 00014 #include <orcalog/logwriterinfo.h> 00015 #include <orcalog/masterfilewriter.h> 00016 #include <orcaifaceimpl/consumerImpl.h> 00017 #include <orcaice/timeutils.h> 00018 00019 namespace orcalog 00020 { 00021 00023 class AutoLogger { 00024 public: 00025 virtual ~AutoLogger() {} 00026 00027 virtual void init( const LogWriterInfo &logWriterInfo, MasterFileWriter &masterFileWriter )=0; 00028 virtual void startLogging()=0; 00029 }; 00030 00035 template<class ProviderType, 00036 class ConsumerType, 00037 class ObjectType, 00038 class LogWriterType> 00039 class GenericAutoLogger : 00040 public orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>, 00041 public orcalog::AutoLogger 00042 { 00043 using orcaifaceimpl::ConsumerSubscriber::context_; 00044 typedef typename ProviderType::ProxyType ProviderPrxType; 00045 typedef typename ConsumerType::ProxyType ConsumerPrxType; 00046 00047 public: 00048 GenericAutoLogger( const orcaice::Context &context ) : 00049 orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>( context ) 00050 { 00051 } 00052 00053 virtual void dataEvent( const ObjectType& data ) 00054 { 00055 logWriter_->write( data, orcaice::getNow() ); 00056 } 00057 00058 // Inherited from orcalog::AutoLogger 00059 virtual void init( const orcalog::LogWriterInfo &logWriterInfo, 00060 orcalog::MasterFileWriter &masterFileWriter ) 00061 { 00062 logWriter_.reset( new LogWriterType ); 00063 logWriter_->checkFormat( logWriterInfo.format ); 00064 logWriter_->init( logWriterInfo, masterFileWriter ); 00065 } 00066 00067 virtual void startLogging() 00068 { 00069 // may throw 00070 ProviderPrxType providerPrx; 00071 orcaice::connectToInterfaceWithTag<ProviderPrxType>( 00072 context_, 00073 providerPrx, 00074 logWriter_->logWriterInfo().interfaceTag ); 00075 00076 // Allow derived classes to do something special (like get description) 00077 setupEvent( providerPrx, *logWriter_ ); 00078 00079 subscribeWithTag( logWriter_->logWriterInfo().interfaceTag ); 00080 } 00081 00082 protected: 00083 00084 // Customizable event, called during initialisation 00085 virtual void setupEvent( ProviderPrxType &providerPrx, LogWriterType &logWriter ) {} 00086 00087 private: 00088 00089 std::auto_ptr<LogWriterType> logWriter_; 00090 }; 00091 00092 } 00093 00094 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)