HP-UX Event ManagerProgrammer's Guide
You can reduce the size and improve the efficiency of your code by creating an event and adding
items to it in a single step, using the varargs (variable-length argument list) version of the
create function. You can add items to an existing event efficiently by using the varargs version
of theitem-setfunction.
Example 4-2 introduces the following functions:
• EvmEventCreateVa — Creates an event, and supplies item names and values in a single
call. For more information about this function, see EvmEventCreateVa(3).
• EvmItemSetVa — Sets data item values in the event. The list of items and variables to be
supplied is the same as that supplied for EvmEventCreateVa. For more information about
this function, see EvmItemSetVa(3).
Example 4-2 Using Variable-Length Argument Lists
#include <stdio.h>
#include <evm/evm.h>
int main()
{ EvmEvent_t event;
EvmItemValue_t itemval_name, itemval_priority;
/* Each item you include in EvmEventCreateVa() function must have an identifier and a value, and the argument
list
must be terminated with an EvmITEM_NONE identifier.
*//* NOTE: To store the values of standard data items in an event, they should first be stored in a variable
of type
EvmItemValue_t which is an union whose definition can be found in /usr/include/evm/evm.h
*//* NOTE: EvmItemValue_t is an union, so you will have to use different variables to store different items,
otherwise they will be overwritten */
itemval_name.NAME = "sys.unix.evm";
itemval_priority.PRIORITY = 200;
EvmEventCreateVa(&event, EvmITEM_NAME, itemval_name, EvmITEM_PRIORITY, itemval_priority, EvmITEM_NONE);
/* The varargs version of EvmItemSetva() uses the same style of argument list as EvmEventCreateVa(). In this
example,
items that are already present in the event are being added, so the new values just replace the old ones. */
itemval_name.NAME = "sys.unix.evm.mark";
itemval_priority.PRIORITY = 100;
EvmItemSetVa(event,EvmITEM_NAME, itemval_name, EvmITEM_PRIORITY, itemval_priority, EvmITEM_NONE);
/* You can easily include variable data item in a varargs list by using the EvmITEM_VAR_Xxx item identifier,
where
Xxx is the type of the variable. If you include a variable in this way, it is very important that you follow
the
identifier with the correct number of arguments to describe the variable. You must always supply two further
arguments: a string containing the name of the variable, and a value argument. The type of the value argument
depends on thetype of the variable in this example, the first variable requires a string and the second requires
an integer. Certain types of variable require an additional argument - see EvmItemSet (3) for more details.*/
EvmItemSetVa(event, EvmITEM_VAR_UINT16,"exit_code",17, EvmITEM_VAR_STRING,"progname","my_app", EvmITEM_NONE);
/* The call to EvmEventDump() displays a formatted dump of the event on stdout, to demonstrate that the
expected data items and variables have been added correctly. */
EvmEventDump(event,stdout);
/* When you have finished with the event, free the storage space the event uses. */
EvmEventDestroy(event); }
Adding and Retrieving Variables
In Example 4-2, variable items were added to an event by including them in a varargs list,
using EvmItemSetVa. You can add or change variable values by using any of the varargs
functions that take item identifiers as arguments.
Example 4-3 illustrates another way to add variable data values to an existing event and shows
how to retrieve the values of the variables. The EVM library includes primitive get and set
functions that use a data structure to describe a variable, and a set of convenience functions that
simplify programming by encapsulating the handling of the structure. This example illustrates
the use of both types of function.
Example 4-3 introduces the following functions:
Adding and Retrieving Variables 39