Writing Monitors for the Event Monitoring Service (December 1999)

154 Chapter5
Writing a Target Application
Processing a Notification Message
Sample Code
/*****************************************************************************/
/* Name: format_notify_object */
/* */
/* Description: Extracts, formats and prints various fields of a notify */
/* object. Assumes object passed in is notify object. */
/* */
/* Parameters: obj Notify object */
/* */
/* Return: None. */
/*****************************************************************************/
void format_notify_object (rm_object_addr notify_obj )
{
rm_object_addr value_obj;
rm_option_type resource_type;
rm_error_type error_code;
rm_value_type value;
int user_data_len;
char *user_data;
char userbuf[256];
char errbuf[200];
/*************************************************************************/
/* Extract and print fields from notify object */
/*************************************************************************/
if (rm_get(notify_obj, RmResourceName, &value, &error_code) == -1) {
rm_strerror(error_code, errbuf, sizeof(errbuf));
fprintf(stderr, "Could not get resource name: %s", errbuf);
printf("Resource Name:???\n");
}
else {
printf("Resource Name:%s\n", value.str);
}
if (rm_get(notify_obj, RmUserDataLen, &user_data_len, &error_code) == -1) {
rm_strerror(error_code, errbuf, sizeof(errbuf));
fprintf(stderr, "Could not get user data length: %s", errbuf);
printf("User Data Length:???\n");
}
else {
printf("User Data Length:%d\n", user_data_len);