Initial commit of files
This commit is contained in:
139
daemons/logd/LogDaemon.cpp
Normal file
139
daemons/logd/LogDaemon.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
//
|
||||
// Log Daemon
|
||||
// Neal Probert
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user