rllib  1
Public Member Functions | Private Attributes | List of all members
rlEventLogServer Class Reference

#include <rleventlogserver.h>

Collaboration diagram for rlEventLogServer:
Collaboration graph
[legend]

Public Member Functions

 rlEventLogServer (const char *filename=NULL, int max_events=10000)
 
virtual ~rlEventLogServer ()
 
const char * getEvent (char *buf, int *num)
 
void putEvent (const char *event)
 

Private Attributes

char memory [rlMAX_MESSAGES *rlMAX_EVENT]
 
rlMutex mutex
 
int front
 
int cnt
 
char * filename
 
void * fp
 
int max_events
 
int num_events
 

Detailed Description

A class for implementing an event log server.
You may use it with rlevent.h

Definition at line 29 of file rleventlogserver.h.

Constructor & Destructor Documentation

◆ rlEventLogServer()

rlEventLogServer::rlEventLogServer ( const char *  filename = NULL,
int  max_events = 10000 
)
the event log files will be called:
filename<date-and-time>.rlEventLog
max_events = max number of events in one file
files may be purged by cron

Definition at line 23 of file rleventlogserver.cpp.

24 {
25  for(int i=0; i<rlMAX_MESSAGES; i++) // init memory
26  {
27  sprintf(&memory[i*rlMAX_EVENT]," ");
28  }
29  front = -1;
30  cnt = 0;
31  if(file != NULL)
32  {
33  filename = new char [strlen(file)+1];
34  strcpy(filename,file);
35  }
36  fp = NULL;
37  max_events = max;
38  num_events = 0;
39 }
#define rlMAX_EVENT
Definition: rlevent.h:26
char memory[rlMAX_MESSAGES *rlMAX_EVENT]
#define rlMAX_MESSAGES

◆ ~rlEventLogServer()

rlEventLogServer::~rlEventLogServer ( )
virtual

Definition at line 41 of file rleventlogserver.cpp.

42 {
43  if(filename != NULL) delete [] filename;
44  if(fp != NULL) fclose((FILE *) fp);
45 }

Member Function Documentation

◆ getEvent()

const char * rlEventLogServer::getEvent ( char *  buf,
int *  num 
)
num is the event number
num = -1 will retrieve all events

Definition at line 47 of file rleventlogserver.cpp.

48 {
49  char *cptr;
50 
51  mutex.lock();
52  if(*num == -1 && front != -1) *num = front+1; // read all
53  if(*num >= rlMAX_MESSAGES) *num = -1;
54  if(*num == front || front == -1) // nothing to read
55  {
56  buf[0] = '\0';
57  mutex.unlock();
58  return NULL;
59  }
60  else // read next record
61  {
62  (*num)++;
63  if(*num >= rlMAX_MESSAGES)
64  {
65  *num = 0;
66  if(*num == front)
67  {
68  buf[0] = '\0';
69  mutex.unlock();
70  return NULL;
71  }
72  }
73  strcpy(buf,&memory[(*num)*rlMAX_EVENT]);
74  cptr = strchr(buf,'\n');
75  if(cptr != NULL) *cptr = '\0'; // delete newline
76  mutex.unlock();
77  // if(buf[0] < ' ') return "";
78  return buf;
79  }
80 }
#define rlMAX_EVENT
Definition: rlevent.h:26
int lock()
Definition: rlthread.cpp:105
char memory[rlMAX_MESSAGES *rlMAX_EVENT]
int unlock()
Definition: rlthread.cpp:110
#define rlMAX_MESSAGES

◆ putEvent()

void rlEventLogServer::putEvent ( const char *  event)

Definition at line 82 of file rleventlogserver.cpp.

83 {
84  mutex.lock();
85  front++;
86  if(front >= rlMAX_MESSAGES) front = 0;
88  if(fp == NULL && filename != NULL)
89  {
90  char name[1024],time[50];
91  rlTime t;
92 
93  t.getLocalTime();
94  strcpy(time,t.getTimeString()); time[10] = '_'; time[13] = '_'; time[16] = '\0';
95  strcpy(name,filename);
96  strcat(name,time);
97  strcat(name,".rlEventLog");
98  //printf("openEventlog(%s)\n",name);
99 #ifdef __VMS
100  fp = (void *) fopen(name,"w","shr=get");
101 #else
102  fp = (void *) fopen(name,"w");
103 #endif
104  }
105  if(fp != NULL && filename != NULL)
106  {
107  fprintf((FILE *) fp,"%s",event);
108  fflush((FILE *) fp);
109  num_events++;
110  }
111  if(num_events > max_events && filename != NULL)
112  {
113  num_events = 0;
114  fclose((FILE *) fp);
115  fp = NULL;
116  }
117  mutex.unlock();
118 }
const char * getTimeString()
Definition: rltime.cpp:106
void getLocalTime()
Definition: rltime.cpp:342
#define rlMAX_EVENT
Definition: rlevent.h:26
int lock()
Definition: rlthread.cpp:105
char memory[rlMAX_MESSAGES *rlMAX_EVENT]
char * rlstrncpy(char *dest, const char *source, int n)
Definition: rlcutil.cpp:169
int unlock()
Definition: rlthread.cpp:110
#define rlMAX_MESSAGES
Definition: rltime.h:25

Member Data Documentation

◆ cnt

int rlEventLogServer::cnt
private

Definition at line 52 of file rleventlogserver.h.

◆ filename

char* rlEventLogServer::filename
private

Definition at line 53 of file rleventlogserver.h.

◆ fp

void* rlEventLogServer::fp
private

Definition at line 54 of file rleventlogserver.h.

◆ front

int rlEventLogServer::front
private

Definition at line 51 of file rleventlogserver.h.

◆ max_events

int rlEventLogServer::max_events
private

Definition at line 55 of file rleventlogserver.h.

◆ memory

char rlEventLogServer::memory[rlMAX_MESSAGES *rlMAX_EVENT]
private

Definition at line 49 of file rleventlogserver.h.

◆ mutex

rlMutex rlEventLogServer::mutex
private

Definition at line 50 of file rleventlogserver.h.

◆ num_events

int rlEventLogServer::num_events
private

Definition at line 55 of file rleventlogserver.h.


The documentation for this class was generated from the following files: