Callback functions are available for all primitive types:
●
●
●
●
●With reference to the callback routine:
set_<element>_cbk (g_addr,el_p,callback_routine, callback_param)where each element is identified by two parameters:
g_addr
, the instance in which it is defined, andel_p
, the address of the element itself.For
g_addr
, set the value to 0 in most cases. However, when referring to elements in generic charts, set the value to 1. Theel_p
indicates the address of the element. Make sure you insert the correct address of the data item.
callback_routine
is the address of a C function.
callback_param
is a parameter used by the callback routine when called.The callback function has the following interface:
where
value
holds the new value of the element.Note: The type of the value parameter depends on the element with which the callback is associated: for data-items of type string, it returns a pointer to a string (char *), for real data-items, value is of type double. If the element is an event, the value parameter does not exist.The
callback_param
is the same value that was installed when setting the callback.Note: Use thecallback_param
when you want to associate one procedure to a number of elements (instead of writing a separate procedure for each element). The returned value allows the callback procedure to perform differently on each element.
●
●
For activities, the value is 0-nonactive, 1-active, 2-hanging
In the following interfaces, these conventions are used:
public void set_event_cbk(g_addr, el_p, func_p, param)
genptr g_addr;
genptr el_p;
funcp func_p;
int param;public void set_cond_cbk(g_addr, el_p, func_p, param)
genptr g_addr;
genptr el_p;
funcp func_p;
int param;public void set_int_cbk(g_addr, el_p, func_p, param)
genptr g_addr;
genptr el_p;
funcp func_p;
int param;public void set_real_cbk(g_addr, el_p, func_p, param)
genptr g_addr;
genptr el_p;
funcp func_p;
int param;public void set_str_cbk(g_addr, el_p, func_p, param)
genptr g_addr;
genptr el_p;
funcp func_p;
int param;public void set_ba_cbk(g_addr, el_addr, len, func_p,
param)
genptr g_addr;
genptr el_addr;
int len;
funcp func_p;
int param;public void set_bit_cbk(g_addr, el_p, func_p, param)
genptr g_addr;
genptr el_p;
funcp func_p;
int param;Assume that conditions c1, c2 are in your specification and you want to monitor them. The callback routine looks like:
void show_conditions(c_val, c_num)
int c_val;
int c_num;
{
if (c_num == 1)
printf(“Condition C1 was set to
%s\n”,
(c_val==0) ? “true” :
“false”);
else
printf(Condition C2 was set toThe callbacks should be set during the initialization. The most logical place is within the
user_init
procedure (seeuser_activities.c
).void user_init()
{
set_cond_cbk(0,&c1, show_conditions, 1);
set_cond_cbk(0,&c2, show_conditions, 2);
}Note that each element can be associated with a number of callback routines. This is why the callback setting functions is called
prt_add_cbk
, since it adds callback functions.