<< 点击显示目录 >> 主页 exOS使用助手 > exOS Automation Help > Development > Programming > exOS Communication API reference (exos_api.h) > exos_datamodel_connect() |
将数据模型连接到数据集消息路由器
EXOS_ERROR_CODE exos_datamodel_connect(exos_datamodel_handle_t *datamodel, exos_datamodel_event_cb datamodel_event_callback);
在当前版本中, datamodel_connect 函数是从 .typ 文件中 生成的代码 ,其名称 是 指定的数据模型主数据结构的名称。
例如,假设 MyApp 数据模型使用 MyApp.typ 文件,而该文件中的主数据模型结构名为 MyApplication。在这种情况下,生成的头文件 (exos_myapplication.h) 将声明函数 exos_datamodel_connect_myapplication(),其用法如下:
#include "exos_myapplication.h"
...
static void datamodelEvent(exos_datamodel_handle_t *datamodel, const EXOS_DATAMODEL_EVENT_TYPE event_type, void *info)
{
...
}
...
exos_datamodel_connect_myapplication(&mydatamodel, datamodelEvent);
出于未来兼容性的考虑, exos_datamodel_connect 作为一个假函数留在了这个头中,它将始终返回 EXOS_ERROR_NOT_IMPLEMENTED。
如果需要通过 exos_datamodel_process()在不同的循环中运行数据集 ,或者应用程序被分割成不同的部分,可以在服务器上注册多个同名的数据模型 。
•datamodel:数据模型句柄,以指针形式给出
•datamodel_event_callback:处理数据模型事件的回调函数
Connect a datamodel to the Dataset Message Router
EXOS_ERROR_CODE exos_datamodel_connect(exos_datamodel_handle_t *datamodel, exos_datamodel_event_cb datamodel_event_callback);
In the current version, the datamodel_connect function is code generated from a .typ file and will have the name of the specified main data structure of the datamodel.
For example, lets say the MyApp datamodel uses a MyApp.typ file, and in that file, the main datamodel structure is called MyApplication. In that case the generated header (exos_myapplication.h) will declare the function exos_datamodel_connect_myapplication(), which will result in the following usage:
#include "exos_myapplication.h"
...
static void datamodelEvent(exos_datamodel_handle_t *datamodel, const EXOS_DATAMODEL_EVENT_TYPE event_type, void *info)
{
...
}
...
exos_datamodel_connect_myapplication(&mydatamodel, datamodelEvent);
For reasons of future compatibility, the exos_datamodel_connect has been left in this header as a dummy function that will always return EXOS_ERROR_NOT_IMPLEMENTED
More than one datamodel can be registered on the server with the same name, if you need to run your datasets in different loops via the exos_datamodel_process(), or if the application is split up in different parts.
•datamodel: datamodel handle, given as a pointer
•datamodel_event_callback: callback function that handles datamodel events