ICI 内容

当使用内核过程 op_ici_create() 创建 ICI 时,必须提供 ICI 格式的名称。ICI 格式以其包含的属性来定义 ICI 的结构。每个属性定义由四个部分组成:名称、数据类型、默认值和可选的描述,如下图所示。

图 220:ICI 格式规范

ICI 格式规范

属性名称用于在 ICI 内部引用属性。换句话说,属性的名称扮演着与格式化数据包中字段名称相同的角色。需要指定属性名称的操作包括设置属性、获取属性以及检测属性是否存在。

属性的数据类型决定它可以存储什么样的信息。支持的类型有 integer、double 和 structure。integer 和 double 数据类型分别存储整数和浮点小数。structure 属性包含内存地址,以支持通过 ICI 传输任意用户定义的数据。通常,这类属性被赋予由动态内存分配内核过程 op_prg_mem_alloc() 返回的内存地址,如下面的示例所示。请注意,与嵌入数据包字段的 structure 地址不同,ICI 属性中的 structure 地址在其所属 ICI 被销毁时不会被自动释放;如有必要,必须由用户进程执行释放。

图 221:structure 类型 ICI 属性的赋值

/* Allocate a structure of type “Command” to pass within an ICI */
command_ptr = (Command*) op_prg_mem_alloc (sizeof (Command));

/* Setup the command structure. */
command_ptr->type = COMMAND_TYPE_A;
command_ptr->priority = COMMAND_PRIORITY_LOW;
command_ptr->request = SET_COMPRESSED_MODE;

/* Install the structure in “command” attribute of a new ICI. */
ici_ptr = op_ici_create (“link_control”);
op_ici_attr_set (ici_ptr, “command”, command_ptr);

当 ICI 最初被创建时,integer 和 double 属性包含 ICI 格式定义中指定的默认值。structure 字段不能被赋予默认值,因为内存地址无法预先知晓。之后可以通过调用内核过程 op_ici_attr_set() 来赋予 ICI 属性值,该过程适用于全部三种类型的属性。三种属性类型的值也可以通过内核过程 op_ici_attr_get() 获取。