Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Event Manager Programmer's Guide: HP-UX 11i v3 Edition 1 > Chapter 4 Sample EVM Programming Operations

Performing Simple Event Manipulations

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

All EVM clients must work with the EVM event, an opaque binary structure that can hold standard data items and variables. Example 4-1 illustrates how to create an event, add items to it, and retrieve the items from it.

Example 4-1 introduces the following functions:

  • EvmEventCreate — Creates an empty event. For more information about this function, see EvmEventCreate(3).

  • EvmEventDestroy — Destroys a previously created event, freeing its memory. This function must be used if it is necessary to free an event. Although the event reference points to a structure allocated from the heap, that structure contains references to other structures, and hence using free directly on the event reference results in lost memory. For more information about this function, see EvmEventDestroy(3).

  • EvmItemSet — Sets data item values in the event. The list of items and variables supplied to this function is the same as the list of items and variables supplied for theEvmEventCreateVa function. For more information about this function, see EvmItemSet(3).

  • EvmItemGet — Supplies the value of a specified event data item. For more information about this function, see EvmItemGet(3).

  • EvmItemRelease — Releases any memory that was allocated when a specified data item was retrieved from an event by EvmItemGet(). For more information about this function, see EvmItemRelease(3).

Example 4-1 Performing Simple Event Manipulations

#include <stdio.h>
#include <evm/evm.h>
int main()
{
         EvmEvent_t event;
         EvmItemValue_t itemval,itemval_local;
         EvmStatus_t status;
/* You can create an empty event with EvmEventCreate()
function. When you use this function, you supply a
pointer to the event handle, and you receive an event
that contains no standard data items. Even though the
event is empty, it does take up memory, and you must
eventually use EvmEventDestroy() to free the space. */

EvmEventCreate(&event);

/* You can add any of the standard data items to the
events using EvmItemSet() function. In most cases,
however, the only item you will want to add in your
program is the name of the event - other standard items
will be automatically added when you post the event, or
are better included in the event template. For more
information see EvmItemSet(3) man page.*/

/* 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 */

itemval_local.NAME = "sys.unix.evm";

EvmItemSet(event, EvmITEM_NAME, itemval_local);

itemval_local.PRIORITY = 200;

EvmItemSet(event, EvmITEM_PRIORITY, itemval_local);

/* You can retrieve any item from the event using
EvmItemGet() function. The value is copied from the event
into storage referenced through your EvmItemValue_t
structure. So you must use EvmItemRelease() function to
release the referenced storage when you have finished
using the items. Retrieving the item does not remove it
from the event; you receive a copy and you can get it as
many times as you want.*/

status = EvmItemGet(event, EvmITEM_NAME, &itemval);

if (status == EvmERROR_NONE)
{
      fprintf(stdout, "Event name: %s\n", itemval.NAME);

      EvmItemRelease(EvmITEM_NAME, itemval);
}

/* When you have finished with the event, free the
storage space used by the event.*/
EvmEventDestroy(event);
}
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 2007 Hewlett-Packard Development Company, L.P.