The following code sample demonstrates how to register and unregister an RTC condition and action pair:
Note: The enum definition and structures shown are in ctadisp.h.
/* RTC-related symbol definitions and data structures. */
/* Specific characteristics about RTC being requested. */
typedef enum {
RTC_NONE = 0, /* Nothing special */
RTC_ALL_CONSUMER_RTCS, /* All consumer RTC actions */
RTC_ALL_PROVIDER_EVENTS, /* All provider RTC events */
RTC_EVT_AND_ONE_VALUE, /* Use value as well as event ID */
RTC_EVT_AND_ANY_VALUE /* Use for all values w event ID */
} RTC_ATTRIBUTES;
/* RTC "DISP_EVENT" to "DISP_COMMAND" data */
typedef struct
{
DWORD Size; /* Size RTC_EVT_CMD_DATA */
DWORD EventId; /* Event ID of RTC condition */
DWORD EventValue; /* "value" from RTC condition event */
} RTC_EVT_CMD_DATA;
/* RTC "event ID" to "name" alias. Length include terminating NULL */
#define RTC_NAME_LEN 20
typedef struct
{
DWORD EventID; /* RTC condition event ID */
Char Alias[ RTC_NAME_LEN ]; / *ASCII name associated with event */
} RTC_ALIAS;
typedef struct _RTC_CONDITION
{
RTC_ATTRIBUTES Attribute; /* Characteristics of condition */
DWORD EventID; /* Service event ID for condition */
DWORD EventValue; /* (RTC_WITH_VALUE) */
Char Alias[ RTC_NAME_LEN ]; /* ASCII name of RTC condition */
} RTC_CONDITION;
typedef struct _RTC_ACTION
{
DWORD Consumer; /* Service ID of RTC consumer */
DWORD ActionCmd; /* Special command sent by service on */
/* recognition of condition */
} RTC_ACTION;
/* An example of registering and canceling a pair of RTC_CONDITION */
/* and RTC_ACTION. */
RTC_CONDITION condition;
RTC_ACTION action;
/* RTC_CONDITION: one event code, one reason code, from one */
/* provider service (TIK) */
condition.Attribute = RTC_EVT_AND_ONE_VALUE; /* Event + reason as */
/* condition */
condition.EventID = TIKEVN_TIMER_DONE; /* Event code */
condition.Reason = CTA_REASON_FINISHED; /* Reason code */
/* RTC_ACTION: EVT service as RTC consumer, EVTCMD_SHOW_EVENT */
/* as callback function */
action.Consumer = EVT_SVCID; /* RTC consumer service ID */
action.ActionCmd = EVTCMD_SHOW_EVENT; /* Call back function when */
/* condition met */
/* Register the pair of RTC_CONDITION and RTC_ACTION. */
dispAddRTC(m->ctahd,&condition,&action); /* Condition-action pair */
/* added to RTC */
/* Cancel the pair of RTC_CONDITION and RTC_ACTION. */
condition.Attribute = RTC_EVT_AND_ONE_VALUE; /* Event + reason as */
/* condition */
condition.EventID = TIKEVN_TIMER_DONE; /* Event code */
condition.Reason = CTA_REASON_FINISHED; /* Reason code */
action.Consumer = EVT_SVCID; /* RTC consumer service ID */
action.ActionCmd = EVTCMD_SHOW_EVENT; /* Call back function when */
/* condition met */
dispRemoveRTC(m->ctahd,&condition,&action); /* Condition-action pair */
/* removed from RTC */
The following example shows the callback function provided by the event tracking service (EVT) as part of the RTC action command:
DWORD evtCmdShowEvent( EVT_PERCTX* pevtPerCtx, DISP_COMMAND* m )
{
DWORD ret = SUCCESS;
RTC_EVT_CMD_DATA rtcData;
/* Validate the arguments. */
ret = evtValidate( pevtPerCtx, m );
if ( ret != SUCCESS )
return ret;
/* Update the event counts for queuecontext and mgrcontext */
/* whenever an event qualifies an RTC_CONDITION. */
pevtPerCtx->pevtPerQue->evcount++;
pevtPerCtx->evcount++;
/* Check if the application log switch is on. */
if (!pevtPerCtx->logStarted)
{
return SUCCESS;
}
/* Retrieve the Event ID and Event Value fields. */
memcpy(&rtcData,m->dataptr1,m->size1);
if (evtLogFileChoice == 1)
{
/* Log event into the user-chosen event log file. */
... ... ... ...
}
else
{
/* Log event into the standard output file. */
... ... ... ...
}
return ret;
}