Is there any example code available for using prg_mapping callback functions?
Is there any example code available for using prg_mapping callback functions?
Here is an example for specifying the prg_mapping callback functions. Let us suppose that we are using mapping structure to store the packet and we use the packet ID as a key to identify packets.Here are the callback procedures:void* key_of_value_proc (void *object_ptr){/* given an object, return the key */Packet* pkptr;pkptr = (Packet*) object_ptr;return ((void *) (& (op_pk_id (pkptr));}int less_than_proc (void* key_a, void* key_b){/* Given two keys, determine if first key is less than second key*/OpT_Packet_Id* a_ptr, b_ptr;a_ptr = (OpT_Packet_Id*) key_a;b_ptr = (OpT_Packet_Id*) key_b;if (*a_ptr < *b_ptr)return 1;elsereturn 0;}void destroy_proc (void *object_ptr){/* free memory associated with object. */Packet* pkptr;pkptr = (Packet*) object_ptr;op_pk_destroy (pkptr);}When you create an object to be placed in the mapping, make sure you allocate dynamic memory for it.
DES Kernel->Process Modeling/Coding