gtpc2m8f | C/C++ Language Support User's Guide |
This function sends informational or error messages to the terminal. The message is provided as a structure containing the message number, severity code, routing information, and message text.
Format
#include <c$mesg.h> void tpf_msg(const char *prefix,TPF_MSG *msg,va_list arg_ptr)
Normal Return
Void.
Error Return
Not applicable.
Programming Considerations
typedef const struct { const unsigned short number; const unsigned char severity; const long rout_list; const char * const text; } TPF_MSG;
The fields are the same type used for the wtopc function:
This is the message number used in the header. This number must be unique for every message in the package.
The severity code, which identifies the type of message. See wtopc_insert_header-Save Header for wtopc for a list of predefined values.
The routing list, which specifies the destination of the message. You can specify more than one type, in which case the message is copied to both devices. See wtopc-Send System Message for a list of routing destinations.
This is the output message, which is one constant string that may be longer than 255 bytes. It can contain any format attribute that is supported by the vsprintf function.
Examples
The following example shows how the tpf_msg function is used. The message handler (which is send_message() in this example) must be in a separate function to reduce system overhead.
#include <tpfapi.h> #include <c$mesg.h> . . /* POSIX Note */ /*The following defines should be done in the c$mesg.h header file. */ /*The prefix can be a symbolic name such as OLDR or */ /*the program name from the caller. A */ /*symbolic name is easier to handle in an automated */ /*environment than the program name; however, the */ /*program name provides fast access to the segment */ /*where the message originated. A possible solution to */ /*meet both requirements is shown in MSG_THREE. */ #define MSG_ONE 1 #define MSG_TWO 2 #define MSG_THREE 3 #define MSG_FOUR 4 #define FCT_PFX "OLDR"
·
·
·
void send_message(const char *prefix,long nbr, ...) { TPF_MSG msg[] = { { 0,WTOPC_ERROR,WTOPC_EBROUT, "INVALID MESSAGE NUMBER %d PASSED TO FUNCTION" }, { MSG_ONE,WTOPC_INFO,WTOPC_EBROUT+WTOPC_RO, "INFO MSG FLOAT %f LONG %ld\n" "NEW LINE\nSTRING %s" }, { MSG_TWO,WTOPC_ERROR,WTOPC_EBROUT, "SIMPLE ERROR MESSAGE" }, { MSG_THREE,WTOPC_ERROR,WTOPC_EBROUT, "%s - ACTIVATE ERROR\n" "LOADSET %s WAS NOT AVAILABLE FOR USER %06lX" } }; va_list arg_ptr; if ((nbr<0) || (nbr>=(sizeof(msg)/sizeof(TPF_MSG)))) { send_message(prefix,0,nbr); } else { va_start(arg_ptr,nbr); tpf_msg(prefix,&msg[nbr],arg_ptr); va_end(arg_ptr); } return; } . . . long main() { send_message(FCT_PFX,MSG_ONE,1.23,999,"HELLO WORLD"); send_message(FCT_PFX,MSG_TWO); send_message(FCT_PFX,MSG_THREE,"PROG","S011200",terminal); send_message(FCT_PFX,MSG_FOUR); exit(0); } . . .
Output:
OLDR0001I 12.35.48 INFO MSG FLOAT 1.230000 LONG 999 NEW LINE STRING HELLO WORLD OLDR0002E 12.35.48 SIMPLE ERROR MESSAGE OLDR0003E 12.35.48 PROG - ACTIVATE ERROR LOADSET S011200 WAS NOT AVAILABLE FOR USER 0F120E OLDR0000E 12.35.48 INVALID MSG NUMBER 4
Related Information