mco_iot_init
此函数用于初始化 ARF(物联网)运行时环境。在每个进程中创建和连接数据库之前,必须调用此函数。
请注意,此功能类似于 mco_cluster_init()
和 mco_HA_start()。
MCO_RET mco_iot_init();
有关概述,请参阅主动复制结构页面。
参数
没有参数。
返回
MCO_S_OK
已成功初始化 ARF 运行时。
示例
下面的代码片段初始化 ARF (IoT) 运行时,并选择性地在打开数据库之前调整自动生成的 IoTagent_id
int main(int argc, char *argv[])
{
mco_db_params_t db_params;
mco_device_t dev;
mco_db_h db;
mco_iot_replicator_params_t repl_params;
mco_iot_comm_params_t comm_params;
mco_iot_replicator_h repl;
mco_iot_comm_h comm;
const char *conn_string = (argc > 1) ? argv[1] : "127.0.0.1:15000";
...
/* Initialize SmartEDB and IoT runtimes */
mco_error_set_handler(&sample_errhandler);
mco_runtime_start();
mco_iot_init();
/* Create database */
dev.type = MCO_MEMORY_CONV;
dev.assignment = MCO_MEMORY_ASSIGN_DATABASE;
dev.size = DEVICE_DATABASE_SIZE;
dev.dev.conv.ptr = (void*)malloc(dev.size);
mco_db_params_init (&db_params);
db_params.db_max_connections = 5;
if (argc > 2) {
db_params.iot_agent_id = atoi(argv[2]); /* Override the agent_id in the schema */
}
CHECK(mco_db_open_dev(db_name, iotdevice_get_dictionary(), &dev, 1, &db_params));
CHECK(mco_db_connect(db_name, &db));
...
}
文件
- 头文件:
mcoiot.h
- 源文件:
mcoiotdb.c
- 库:
libmcoiotrepl.a