op_ici_attr_exists()
摘要
判断按名称指定的属性是否在某个 ICI 的格式中已定义。
语法
op_ici_attr_exists (iciptr, attr_name)
| 参数 | 类型 | 说明 |
|---|---|---|
iciptr |
Ici * |
指向目标 ICI 的指针 [指向 ICI 的指针可以从三个内核过程获得: op_ici_create() 返回指向新分配 ICI 的指针(在 ICI 发送进程中);op_intrpt_ici() 返回与传入中断关联的 ICI 的指针(在 ICI 接收进程中;以及 op_ev_ici() 返回与特定事件关联的 ICI。] |
attr_name |
const char * |
目标属性的名称 |
返回类型
Boolean
布尔值,指示指定属性是否存在于指定 ICI 中。如果该属性不存在或发生可恢复错误,将返回常量 OPC_FALSE;如果该属性确实存在,将返回常量 OPC_TRUE。
示例
摘自:示例模型(models\std\fddi);进程模型(fddi_mac_v4);状态(ENCAP);enter execs。
/* A frame has arrived from a higher layer. */
/* If in encap_decap mode, encapsulation is to be */
/* to be performed. Place the frame in 'pdu_ptr'. */
if (encap_decap == OPC_TRUE)
{
pdu_ptr = op_pk_get (op_intrpt_strm ());
if (pdu_ptr == OPC_NIL)
{
fddi_mac_error ("Unable to get packet from higher layer.", OPC_NIL, OPC_NIL);
}
/* Also get the interface control information */
/* associated with the new frame. */
ici_ptr = op_intrpt_ici ();
if (ici_ptr == OPC_NIL)
{
fddi_mac_error ("Did not receive ICI with packet from higher layer.",
OPC_NIL, OPC_NIL);
}
/* Extract the requested service class: synchronous or asynchronous. */
if (op_ici_attr_exists (ici_ptr, "svc_class"))
{
if (op_ici_attr_get (ici_ptr, "svc_class", &svc_class) ==
OPC_COMPCODE_FAILURE)
{
fddi_mac_error ("Unable to get service class field from ICI.",
"The field does exist, but the get call failed.", OPC_NIL);
}
}
else svc_class = FDDI_SVC_ASYNC;
. . .
详情
与格式化数据包字段不同,在 ICI 格式中定义的 ICI 属性从 ICI 创建的那一刻起就存在,并且始终具有初始值。ICI 属性不存在“已设置”或“未设置”的概念;因此该内核过程只涉及某个特定属性是否存在于 ICI 的格式中,而不是是否存在于某个 ICI 实例中。
用途
如果指定的属性名称不在该 ICI 格式所定义的属性之列,尝试设置或获取该 ICI 属性将导致错误。为了避免此类错误并同时支持使用多种 ICI 类型乃至未知 ICI 格式的接口,进程模型需要能够在访问属性之前先检验属性是否存在。内核过程 op_ici_attr_exists() 提供了这一能力。
错误
- 程序中止:Segmentation violation.(由于非法的 ICI 地址、格式错误的 ICI 数据结构,或格式错误的
attr_name参数) - 可恢复错误:ICI 指针为 NIL。
参考
- 使用内核过程 op_intrpt_ici() 获取与传入中断关联的 ICI 指针
- 使用内核过程 op_ici_attr_get_dbl()、op_ici_attr_get_int32()、op_ici_attr_get_int64() 和 op_ici_attr_get_ptr() 获取某个 ICI 属性的值
- 使用内核过程 op_ici_attr_set_dbl()、op_ici_attr_set_int32()、op_ici_attr_set_int64() 和 op_ici_attr_set_ptr() 修改某个 ICI 属性的值