SCOM详解
SCOM:Synchronized COMmunication module
使用的时候要包含:#include <scom.h>
使用的类型和常数
typedef struct SCOM_Attrs { /* SCOM object creation attributes */
Char dummy; /* no attributes at present */
} SCOM_Attrs;
typedef struct SCOM_Obj SCOM_Obj, *SCOM_Handle; /* SCOM object handle */
extern SCOM_Attrs SCOM_ATTRS; /* default SCOM creation attributes */
描述:这个模块在任务之间传送消息。它允许用户创建任意个异步的队列,并把消息发到这些队列中而且可以
从这些队列中读取消息。这些消息是任意大小的缓存区。
SCOM模块管理SCOM队列对象。每一个SCOM队列内部使用一个队列对象(QUE)和一个旗语对象(SEM)。在SCOM队列的
结构在SCOM模块中是私有的。应用程序不应该涉及到SCOM队列的对象。
一个队列可以拥有任意个消息,但是消息的第一个域必须是QUE_elem。如:
typedef struct ScomBufChannels {
QUE_Elem elem;
Sample *bufChannel[ NUMCHANNELS ];
} ScomBufChannels;
Let us look at a general case where some tasks A and B want to exchange messages. Tasks A and B agree that A sends data of type MyMsg to B via SCOM queues named "scomA" for task A, and "scomB" for task B. The following steps would occur:
SCOM 用到的函数:
• SCOM_init(). Initializes the module.
• SCOM_exit(). Ends use of the module.
• SCOM_create(). Creates a new SCOM queue object.
• SCOM_open(). Gets a reference to an existing SCOM queue object by name.
• SCOM_delete(). Deallocates and deletes an SCOM queue object.
• SCOM_putMsg(). Places SCOM message in an SCOM queue.
• SCOM_getMsg(). Receives SCOM message from an SCOM queue.
分析:
SCOM_create()得到SCOM队列的句柄。
Syntax scomQueue = SCOM_create(queueName, *attrs);
Parameters String queueName; /* Name of SCOM queue to create */
SCOM_Attrs *attrs; /* SCOM object attributes; only NULL supported */
Return Value SCOM_Handle /* handle of new SCOM queue */
上面的表描述了两个任务之间的通信。一旦一个线程建立了一个队列,那么我们就可以在另一个线程里通过SCOM_open()来通信。