file name: errtask.hpp, errtask.cpp
classification: simulation
contents: class CErrorTask
derived from: CErrorHandler, ACProcess
use: stores error strings in a queue and periodically prints
them to the output screen (cerr or the XRAY standard output screen)
global items used:
#define PRINTOUT(message):
the macro takes a parameter char *message and either calls function
xp_strout() to print the message and a trailing newline to the
XRAY output screen (if PSOS_SIM
is defined), or calls function ProcessMessage() of the base class
CErrorHandler to print it to cerr.
member variables:
INT32 qid_:
the ID of the error queue.
member functions:
CErrorTask
(char qname[4]): Creates a queue with the name qname and
stores its ID.
Note: call the queue "QERR" or something like that. *Do not*
use a string of (hex) numbers, the queues of the supervisors are named
in such a way.
virtual
~CErrorTask(): Calls EmergencyFlush() and then deletes the
queue.
virtual
void Body (): The main function. It is an endless loop, which calls
Flush() and then waits for ErrorReportPeriod
seconds (using the pSOS call tm_wkafter()).
void EmergencyFlush():
Empties the queue, processes the messages using EmergencyProcessMessage().
Since the function only returns after the queue is empty, it is vital that
no errors (Assert(), Check(),
Report() macros) occur during the execution of
this function (otherwise, we may get an endless loop). After being processed,
the messages are deleted.
virtual
void EmergencyProcessMessage (char *message): Simply calls ProcessMessage().
virtual
void Flush(): The function reads at most MaxErrorMessages
messages from the message queue, calls ProcessMessage() and deletes
them. ProcessMessage() is inherited from the base class and prints
to cerr.
static
char *GetMessageString (INT32 len): Allocates and returns a string
of the given length. Use only this function for obtaining memory for message
strings.
virtual
void NoteError (char *message): If message is NULL, the function
returns at once. Else, it copies the message string into an internal buffer
and stores a pointer to this buffer in the queue.
virtual
void ProcessMessage (char *message): Calls macro PRINTOUT()
to print the message, followed by a newline, to the output screen.
static
void ReturnMessageString (char *string): Deallocates the string. It
is assumed that the string has been allocated using GetMessageString().