// // Log Daemon // Neal Probert // #include #include #include #include #include #include #include #include #include #include #include #include "UriParse.h" #include "LogDaemon.h" #include "netlib.h" //**************************************************************************** // defines //***************************************************************************/ //**************************************************************************** // macros //***************************************************************************/ //**************************************************************************** // structs & typedefs //***************************************************************************/ //**************************************************************************** // global constants //***************************************************************************/ //**************************************************************************** // global variables //***************************************************************************/ //**************************************************************************** // static constants //***************************************************************************/ //**************************************************************************** // static variables //***************************************************************************/ //**************************************************************************** // static functions //***************************************************************************/ //**************************************************************************** // C++ functions //***************************************************************************/ LogDaemon::LogDaemon() { // logging log_open( LOGD_NAME ); } LogDaemon::~LogDaemon() { } /* UDP ***********************************************************************/ int LogDaemon::ClientInOut( char *buf, int n, int max ) { if ( n > 0 ) { Dprintf( "%s\n", buf ); Log.LogWrite( buf, n ); } // no response return 0; } /* log ***********************************************************************/ int LogDaemon::LogOpen( const char *uri ) { if ( Log.LogOpen( uri ) ) { return 1; } return -1; } int LogDaemon::LogPlayback( void ) { timeval tv; tv.tv_sec = 0L; tv.tv_usec = 0L; // read log input // send message // if ( strlen( logbuf ) ) // ClientCast( logbuf, strlen(logbuf) ); // read next message if ( Log.LogRead( &tv, logbuf, sizeof(logbuf) ) > 0 ) { // is this first one? if ( logcount == 0 ) { // fudge it so it kicks off 10 seconds later loglast.tv_sec = tv.tv_sec - 10; loglast.tv_usec = tv.tv_usec; } logcount++; // diff between this one and last if ( loglast.tv_usec > tv.tv_usec ) { // carry tv.tv_sec--; tv.tv_usec += 1000000L; } timeval sv = tv; // diff is timeout period tv.tv_sec = tv.tv_sec - loglast.tv_sec; tv.tv_usec = tv.tv_usec - loglast.tv_usec; // mark last log record loglast = sv; } else return 1; // set next timeout SetTimeout( tv ); return 1; }