sipxportlib  Version 3.3
OsSysLogTask.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _OsSysLogTask_h_
13 #define _OsSysLogTask_h_
14 
15 // SYSTEM INCLUDES
16 #include <stdarg.h>
17 // APPLICATION INCLUDES
18 #include "os/OsSocket.h"
19 #include "os/OsSysLog.h"
20 #include "os/OsSysLogFacilities.h"
21 #include "os/OsServerTask.h"
22 #include "os/OsRWMutex.h"
23 
24 // DEFINES
25 #define MAX_SOCKET_TARGETS 4 // Max number of output sockets
26 #define MAX_REOPEN_LOG_DELAY_SEC 15 // Close/Reopen log after 15
27  // seconds. This is actually
28  // performed on the next message,
29  // so it will likely be larger-
30  // perhaps much.
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 // STRUCTS
36 // ENUMS
37 
38 // TYPEDEFS
39 // FORWARD DECLARATIONS
40 class OsTimer;
41 class OsSocket;
42 class OsEvent;
43 
44 // The OsSysLogTask handles all of the syslog processing
45 class OsSysLogTask : public OsServerTask
46 {
47 /* //////////////////////////// PUBLIC //////////////////////////////////// */
48 public:
49 
50 /* ============================ CREATORS ================================== */
51 
52  OsSysLogTask(const int maxInMemoryLogEntries = 0,
53  const int options = OsSysLog::OPT_NONE);
54  //:Default constructor
55 
56  virtual ~OsSysLogTask();
57  //:Destructor
58 
59 /* ============================ MANIPULATORS ============================== */
60 
61  virtual UtlBoolean handleMessage(OsMsg& eventMessage);
62  //:Handles all incoming requests
63 
64  OsStatus clear();
65  //:Clear all of the log entries
66 
67  OsStatus flush(const OsTime& rTimeout = OsTime::OS_INFINITY);
68  //:Stores all of the in-memory log entries to storage
69 
71  {
72  return mpTimer;
73  }
74 
75 /* ============================ ACCESSORS ================================= */
76 
77  OsStatus getMaxEntries(int& maxEntries);
78  //:Obtains the maximum number of in-memory log entries.
80 
81  OsStatus getLogEntries( const int maxEntries,
82  char* entries[],
83  int& actualEntries) ;
84  //:Gets the last <maxEntries> log entries ordered with the most recent
85  //:entry first.
88  // maxEntries entries. It is the caller responsibility to free
89  // all of the char* pointers.
91  // will always be less than or equal to maxEntries.
92 
93 /* ============================ INQUIRY =================================== */
94 
95 /* //////////////////////////// PROTECTED ///////////////////////////////// */
96 
97 protected:
98  UtlBoolean mConsoleEnabled; // Is console output enabled?
99 
100  char** mpRingBuffer; // In memory ring buffer
101  int mLogCount; // Number of entries in ring buffer
102  int mRingBufferLength; // Length of ring buffer
103  int mRingBufferNext; // Next available ring buffer
104 
105  FILE* mpUnboundedLog; // Unbounded Log file (if used)
106  UtlString mUnboundedLogFile; // File/Path of Unbounded log file
107 
108  UtlString mBoundedLogFile; // Name/Path of bounded log file
109  int mFlushPeriod; // How often the log file should be flushed
110  UtlBoolean mLogChanged; // Has the log changed/need flushing?
111  OsTimer* mpTimer; // Timer responsible for flushing log
112  OsSocket* mpSockets[MAX_SOCKET_TARGETS] ; // Output sockets
113  OsSysLogCallback mpCallback; // Callback function
114  OsRWMutex mRWMutex; // Guards log data
115  OsTime mpLastReopen ; // Time of last reopen (unbounded only)
116  int mOptions ; // Instance-specific options
117 
118 
119  OsStatus processAdd(char* pEntry);
120  //:Handlers adding a new log entry
121  OsStatus processAddTail(char* pEntry);
122  //:Handlers adding a log entry to the "tail" of the list
124  //:Handles enabling/disabling console output
125  OsStatus processHeadCommand(const int iEntries);
126  //:Handles displaying log contents starting from "head" of log
127  OsStatus processTailCommand(const int iEntries);
128  //:Handles displaying log contents starting from "tail" of log
129  OsStatus processSetFile(const char* szFile);
130  //:Process setting the target output file
131  OsStatus processAddSocket(const char* remoteHost);
132  //:Process adding a target output socket
133  OsStatus processSetFlushPeriod(const int iPeriod);
134  //:Process setting the flush period
135  OsStatus processFlushLog(OsEvent* pEvent);
136  //:Process flushing the actual log.
138  //:Process setting a callback function
139 
140 /* //////////////////////////// PRIVATE /////////////////////////////////// */
141 private:
142  OsSysLogTask(const OsSysLogTask& rOsSysLogTask);
143  //:Copy constructor
144 
145  OsSysLogTask& operator=(const OsSysLogTask& rhs);
146  //:Assignment operator
147 
148 };
149 
150 /* ============================ INLINE METHODS ============================ */
151 
152 #endif /* _OsSysLogTask_h_ */
153 
Definition: OsSysLogTask.h:45
OsStatus getLogEntries(const int maxEntries, char *entries[], int &actualEntries)
param maxEntries - The maximum number of in-memory log entries
Definition: OsSysLogTask.cpp:186
OsStatus processAdd(char *pEntry)
Definition: OsSysLogTask.cpp:363
UtlString mBoundedLogFile
Definition: OsSysLogTask.h:108
Definition: OsSocket.h:79
virtual UtlBoolean handleMessage(OsMsg &eventMessage)
Definition: OsSysLogTask.cpp:255
UtlString mUnboundedLogFile
Definition: OsSysLogTask.h:106
int mFlushPeriod
Definition: OsSysLogTask.h:109
OsStatus getMaxEntries(int &maxEntries)
Definition: OsSysLogTask.cpp:174
OsTimer * mpTimer
Definition: OsSysLogTask.h:111
#define MAX_SOCKET_TARGETS
Definition: OsSysLogTask.h:25
OsStatus processHeadCommand(const int iEntries)
Definition: OsSysLogTask.cpp:541
int mOptions
Definition: OsSysLogTask.h:116
UtlBoolean mConsoleEnabled
param: maxEntries - The maximum number of entries to fetch. param: entries - Array of char* large eno...
Definition: OsSysLogTask.h:98
int mRingBufferNext
Definition: OsSysLogTask.h:103
Definition: OsServerTask.h:34
OsSysLogCallback mpCallback
Definition: OsSysLogTask.h:113
OsStatus processAddTail(char *pEntry)
Definition: OsSysLogTask.cpp:331
char ** mpRingBuffer
Definition: OsSysLogTask.h:100
OsStatus
Definition: OsStatus.h:27
UtlBoolean mLogChanged
Definition: OsSysLogTask.h:110
int mLogCount
Definition: OsSysLogTask.h:101
OsStatus processFlushLog(OsEvent *pEvent)
Definition: OsSysLogTask.cpp:786
OsSocket * mpSockets[MAX_SOCKET_TARGETS]
Definition: OsSysLogTask.h:112
OsStatus processSetFlushPeriod(const int iPeriod)
Definition: OsSysLogTask.cpp:695
OsTimer * getTimer()
Definition: OsSysLogTask.h:70
OsSysLogTask(const int maxInMemoryLogEntries=0, const int options=OsSysLog::OPT_NONE)
Definition: OsSysLogTask.cpp:62
Definition: UtlString.h:48
int mRingBufferLength
Definition: OsSysLogTask.h:102
OsRWMutex mRWMutex
Definition: OsSysLogTask.h:114
Definition: OsTime.h:45
OsStatus processAddSocket(const char *remoteHost)
Definition: OsSysLogTask.cpp:736
OsStatus processConsoleEnable(const UtlBoolean enable)
Definition: OsSysLogTask.cpp:525
OsStatus processTailCommand(const int iEntries)
Definition: OsSysLogTask.cpp:581
OsStatus flush(const OsTime &rTimeout=OsTime::OS_INFINITY)
Definition: OsSysLogTask.cpp:150
OsStatus processSetCallback(OsSysLogCallback pCallback)
Definition: OsSysLogTask.cpp:867
Events are used to synchronize a task with an ISR or between two tasks.
Definition: OsEvent.h:70
Definition: OsTime.h:37
Definition: OsSysLog.h:198
OsStatus clear()
Definition: OsSysLogTask.cpp:124
Definition: OsTimer.h:105
int UtlBoolean
Definition: UtlDefs.h:41
OsStatus processSetFile(const char *szFile)
Definition: OsSysLogTask.cpp:619
Definition: OsMsg.h:36
void(* OsSysLogCallback)(const char *szPriority, const char *szSource, const char *szMsg)
enumcode: LOG_DEBUG - Debug-level message. Debug level messages should
Definition: OsSysLog.h:101
FILE * mpUnboundedLog
Definition: OsSysLogTask.h:105
virtual ~OsSysLogTask()
Definition: OsSysLogTask.cpp:101
OsTime mpLastReopen
Definition: OsSysLogTask.h:115