file name: err2eval.hpp, err2eval.cpp
classification: simulation
contents: class CErrorEval
derived from: CErrorTask
use: stores error strings in a queue and periodically send them
to a datagram socket (the socket is provided by the evaluation, which will
receive the error messages and print them to the screen and/or to some
error log)
Note: with the introduction of sockets instead of printing to
a screen, we get a whole lot of new problems. For if an error occurs when
using the socket, this error is reported and put into the message queue,
and of course that message is sent using the socket, so another error is
reported a.s.o. To avoid such an endless loop, two means of output are
needed. One is the output of a limited number of messages to the socket,
the other is an emergency output to some other device (the screen, or \dev\null
if no other output device exists), if it is probable that the queue cannot
be emptied because of a faulty socket.
global items used:
local items used: #define SocketCreateFailed:
an error message that is printed if the client datagram socket could not
be created.
#define
ABORTFUNC: the name of the function that is called to stop the program
if an assert fails. The function depends on the operating system: if PSOS_SIM
is defined, then the macro is set to k_fatal. Otherwise, it is
set to abort.
#define ABORTPARAMS:
the parameters of the abort function. Again, the value of the macro depends
on the operating system: if PSOS_SIM
is defined, then the macro is set to 0x10000, K_LOCAL. The first
parameter is the error code that is set by k_fatal(), the second
parameter specifies that only the local node should be shutdown. If PSOS_SIM
is not defined, the macro is void.
member variables:
CDatagramClient
*socket_: the datagram socket to the evaluation.
member functions:
CErrorEval
(char qname[4], ACSocketAddress *addr): Creates a datagram socket
with the given address. If creation of the socket has failed, EmergenceProcessMessage()
is called with an error message and program execution is aborted through
a call to ABORTFUNC (ABORTPARAMS).
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.
~CErrorEval
(): First calls Flush() to try and empty the queue in the
normal way, then calls EmergencyFlush() for all messages still
left in the queue. Finally, the socket is deleted.
Both flush methods are inherited from CErrorTask,
they call ProcessMessage() and EmergencyProcessMessage().
virtual
void EmergencyProcessMessage (char *string): Calls the ProcessMessage()
function of CErrorTask, which is inherited from
CErrorHandler and simply prints to the screen.
It is very important here *not* to send the message to the socket. The
message must be printed in such a way that its processing does not produce
new errors that are reported. Otherwise, an endless loop will occur.
virtual
void ProcessMessage (char *string): Transmits the string over the
socket. If the string could not be sent (socket full), the transmission
is repeated. If MaxTrials attempts to send
the string have failed, EmergencyProcessMessage() is called instead.