op_ima_obj_state_set()
Abstract
Attaches a structure or value to an object that can be retrieved with the KP op_ima_obj_state_get().
Syntax
op_ima_obj_state_set (objid, state_ptr)
| Argument | Type | Description |
|---|---|---|
objid |
Objid |
object ID of the object-of-interest [A processor or queue object ID can be obtained from several KPs in the Topo and Id packages: op_topo_assoc(), op_topo_child(), op_id_self(), and op_id_from_name().] |
state_ptr |
void* |
pointer to a data structure or value [The data structure or value is an arbitrary state indicator whose meaning is determined by the modeler.] |
Return Type
Compcode
Completion code indicating whether the operation completed successfully. This code can be compared to the two symbolic constants OPC_COMPCODE_SUCCESS and OPC_COMPCODE_FAILURE.
Example
Excerpt from oms_bgutil.ex.c in models/std/utilities/oms.
/* We will use op_ima_obj_state_set to store in the channel object a dynamically */
/* allocated pointer to the bgutil_routed_state_ptr. */
bgutil_routed_state_pptr = (OmsT_Bgutil_Routed_State **)
op_prg_mem_alloc (sizeof (OmsT_Bgutil_Routed_State *));
*bgutil_routed_state_pptr = bgutil_routed_state_ptr;
/* Install on this channel the pointer to the bgutil routed state pointer. */
op_ima_obj_state_set (tx_ch_objid, bgutil_routed_state_pptr);
Details
Objects can contain state information in the form of values or structures. The KP op_ima_obj_state_set() attaches these values or structures to the object, and the KP op_ima_obj_state_get() retrieves a copy of them. The state information remains set on the object and may be gotten again.
Purpose
Provides a mechanism to attach state information to simulation objects.
Errors
- Recoverable Error: Object ID (
<objid>) is out-of-range. - Recoverable Error: Object ID (
<objid>) refers to a restricted object.
Reference
- Use the KP op_ima_obj_state_get() to retrieve a value or structure from an object