op_ima_obj_attr_set_str()
Abstract
Assigns the value of a string attribute in the specified object.
Syntax
op_ima_obj_attr_set_str (objid, attr_name, value)
| Argument | Type | Description |
|---|---|---|
objid |
Objid |
object ID of the object-of-interest [An object ID can be obtained from several KPs in the Topo and Id packages: op_id_self(), op_topo_parent(), op_topo_child(), op_id_from_userid(), and op_id_from_name().] |
attr_name |
const char * |
name of the attribute-of-interest [This value must be a defined attribute of the specified object.] |
value |
const char * |
new value for the specified attribute |
Return Type
Compcode
OPC_COMPCODE_SUCCESS if the attribute value was successfully set; OPC_COMPCODE_FAILURE otherwise.
Example
/* Extract the interface’s address and subnetwork mask. */
op_ima_obj_attr_get_str (addr_info_attr_objid, "Address", IPC_ADDR_STR_LEN,
address_string);
op_ima_obj_attr_get_str (addr_info_attr_objid, "Subnet Mask", IPC_ADDR_STR_LEN,
subnet_mask_string);
/* Check the values of addresses. If the value is left empty, assign AUTO_ADDRESS */
/* to it. A valid address is at least 7 characters, such as 0.0.0.0. */
if (strlen (address_string) < 7)
{
op_ima_obj_attr_set_str (addr_info_attr_objid, "Address", IPC_AUTO_ADDRESS);
strcpy (address_string, IPC_AUTO_ADDRESS);
}
if (strlen (subnet_mask_string) < 7)
{
op_ima_obj_attr_set_str (addr_info_attr_objid, "Subnet Mask", IPC_AUTO_ADDRESS);
strcpy (subnet_mask_string, IPC_AUTO_ADDRESS);
}
Details
This KP will not report an error if the attribute is not found; you must check the return value to discover this. By not reporting errors, this KP eliminates the need to use op_ima_obj_attr_exists() beforehand to prevent warnings from being generated.
Purpose
Provides a mechanism to dynamically assign object attributes during the course of a simulation. This KP works identically to op_ima_obj_attr_set(), but applies only to object attributes of data type string. Refer to op_ima_obj_attr_set() for full purpose and details.
Errors
- Same as op_ima_obj_attr_set().
Reference
- Use the KP op_ima_obj_attr_set_dbl() to set the value of an object attribute of type double
- Use the KP op_ima_obj_attr_set_int32() to set the value of an object attribute of type integer
- Use the KP op_ima_obj_attr_set_objid() to set the value of an object attribute of type objid
- Use the KP op_ima_obj_attr_set_toggle() to set the value of an object attribute of type toggle
- Use the KPs op_ima_obj_attr_get(), op_ima_obj_attr_get_dbl(), op_ima_obj_attr_get_int32(), op_ima_obj_attr_get_objid(), op_ima_obj_attr_get_str(), and op_ima_obj_attr_get_toggle() to obtain the value of an object attribute
- Use the KPs op_ima_sim_attr_get(), op_ima_sim_attr_get_dbl(), op_ima_sim_attr_get_int32(), and op_ima_sim_attr_get_str() to obtain the value of a simulation attribute
- Use the KP op_ima_obj_svar_get() to obtain the value of a process state variable
- Use the KP op_ima_obj_command() to issue a command to an object
- Use the KP op_id_self() to obtain the object ID of the surrounding processor or queue
- Use the KP op_id_from_name() to obtain the object ID of an arbitrary object