mco_iot_replicator_create

Create a replicator object.

For an overview see page ARF Applications in C

Prototype

 
    MCO_RET mco_iot_replicator_create(mco_db_h db, mco_iot_comm_h comm, 
                        mco_iot_replicator_params_t *params, 
                        /* OUT */ mco_iot_replicator_h *repl);
 

Arguments

db The mco_db_hdatabase connection handle
comm The communicator object handle created through the mco_iot_comm_create()
params The mco_iot_replicator_params_t structure containing the initialized parameters
repl The replicator object handle

Description

This function creates a replicator object and returns the handle in repl. Once the replicator has been created, the database handle db is no longer needed. For instance the connection can be closed through the mco_db_disconnect(). The communicator comm must not be destroyed until after the paired replicator is destroyed.

Return Codes

MCO_S_OK Replicator successfully created
MCO_E_IOT_INVALID_HANDLE Invalid database db or communicator comm handle
MCO_E_IOT_NOT_INITIALIZED The IoT runtime was not initialized or the database does not declare IoT in the schema
MCO_E_NOMEM Unable to allocate memory for replicator data structure
MCO_E_SESLIMIT Or other connect() errors if the function can't create a database connection

Example

The code snippet below initializes the ARF (IoT) runtime, opens and connects the database, then creates the communicator and replicator objects:

     
    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 eXtremeDB 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));
        mco_iot_comm_params_init(&comm_params);
        CHECK(mco_iot_comm_create(&comm_params, &comm));
        mco_iot_replicator_params_init(&repl_params);
        CHECK(mco_iot_replicator_create(db, comm, &repl_params, &repl));
        ...
    }
     

Files

Header file:
mcoiot.h
Source file:
mcoiotrepl.c
Library:
libmcoiotrepl.a