op_ima_obj_attr_exists()
摘要
判断指定属性是否为指定对象所定义。
语法
op_ima_obj_attr_exists (objid, attr_name)
| 参数 | 类型 | 说明 |
|---|---|---|
objid |
Objid |
关注对象的对象 ID [对象 ID 可以从 Topo 包和 Id 包中的多个内核过程获得,包括: op_id_self()、op_topo_parent()、op_topo_child()、op_id_from_userid() 和 op_id_from_name()。] |
attr_name |
const char* |
关注属性的名称 |
返回类型
Boolean
Boolean 值,指示指定属性是否为关注对象所定义。
若该属性已定义,此值等于常量 OPC_TRUE;否则返回值为 OPC_FALSE。
示例
/* Up to MAX_DESTS destinations are allowed for this traffic source process. */
/* Each one will be specified by an attribute. Determine which destinations */
/* are specified (Attributes only exist for defined destinations). */
for (d = 0; d < MAX_DESTS; d++)
{
/* Compose a name for the destination attribute. */
sprintf (name, "destination_%d", d);
/* Test for its existence to see if the destination is defined. */
/* If it is defined, proceed with configuration for that dest. */
if (op_ima_obj_attr_exists (node_objid, name) == OPC_TRUE)
configure_destination (d);
/* If not, assume there are no others. */
else break;
}
详情
某些情况下,属性对对象而言是按条件定义的。特别是,提升属性和扩展属性在给定对象上可能存在,也可能不存在。此外,属性名称可能依赖于动态确定的信息。在这些情况下,进程或流水线阶段在获取或修改属性值之前,可能需要通过 op_ima_obj_attr_exists() 检测该属性是否存在。尽管内核过程 op_ima_obj_attr_set() 和 op_ima_obj_attr_get() 在引用不存在的属性时会返回完成码 OPC_COMPCODE_FAILURE,但该完成码也可能指示其他类型的失败。而且,当通过这些内核过程访问未定义的属性时,还会生成可恢复错误消息。
用途
对象属性可以使用内核过程 op_ima_obj_attr_get() 和 op_ima_obj_attr_set() 动态获取或修改。然而,这些内核过程假定关注对象维护着所需的属性。如果使用这些内核过程访问一个并不存在的属性,就会发生错误。当无法确定某个属性是否已定义时,可以在使用这些访问内核过程之前先使用内核过程 op_ima_obj_attr_exists(),以防止此类错误。
错误
- 程序中止:Segmentation violation(由于
attr_name的地址无效) - 可恢复错误:对象 ID(
<objid>)超出范围。 - 可恢复错误:对象 ID(
<objid>)指向受限对象。
参考
- 使用内核过程 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() 和 op_ima_obj_attr_get_toggle() 获取对象属性的值
- 使用内核过程 op_ima_obj_attr_set()、op_ima_obj_attr_set_dbl()、op_ima_obj_attr_set_int32()、op_ima_obj_attr_set_objid()、op_ima_obj_attr_set_str() 和 op_ima_obj_attr_set_toggle() 为对象属性赋值
- 使用内核过程 op_id_self() 获取所在处理器或队列的对象 ID
- 使用内核过程 op_id_from_name() 获取任意对象的对象 ID