예제 #1
0
int main(int argc, const char **argv)
{
    qeo_factory_t *factory;
    qeocore_type_t *type;
    qeocore_reader_t *reader;
    qeocore_reader_listener_t listener = { .on_data = on_data_available };
    qeocore_writer_t *writer;
    pthread_t th = 0;


    /* initialize */
    sem_init(&_sync, 0, 0);
    assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
    init_factory(factory);
    assert(NULL != (type = qeocore_type_register_tsm(factory, _tsm, _tsm[0].name)));
    assert(NULL != (reader = qeocore_reader_open(factory, type, NULL, QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                                                 &listener, NULL)));
    assert(NULL != (writer = qeocore_writer_open(factory, type, NULL, QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                                                 NULL, NULL)));
    /* start writer thread */
    assert(0 == pthread_create(&th, NULL, run, writer));
    /* make sure writing has started */
    sem_wait(&_sync);
    /* shutdown reader */
    qeocore_reader_close(reader);
    _closed = 1;
    /* shutdown writer */
    _done = 1;
    pthread_join(th, NULL);
    qeocore_writer_close(writer);
    qeocore_type_free(type);
    qeocore_factory_close(factory);
}
예제 #2
0
qeo_retcode_t fwd_init_post_auth(qeo_factory_t *factory)
{
    qeo_retcode_t rc = QEO_EFAIL;
    qeocore_type_t *type = NULL;

    /* this will eventually also take the factory lock, so postponing our lock */
    type = qeocore_type_register_tsm(factory, org_qeo_system_Forwarder_type, org_qeo_system_Forwarder_type->name);
    if (NULL != type) {
        lock(&factory->mutex);
        if (factory->flags.is_forwarder) {
            factory->fwd.listener.on_data = fwd_server_on_data;
            factory->fwd.reader = qeocore_reader_open(factory, type, org_qeo_system_Forwarder_type->name,
                                                      QEOCORE_EFLAG_STATE_UPDATE, &factory->fwd.listener, NULL);
            if (NULL != factory->fwd.reader) {
                factory->fwd.u.server.writer = qeocore_writer_open(factory, type, org_qeo_system_Forwarder_type->name,
                                                                   QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                                                                   NULL, NULL);
                if (NULL != factory->fwd.u.server.writer) {
                    factory->fwd.u.server.state = FWD_STATE_INIT;
                    rc = fwd_server_state_machine_eval_ul(factory, -1, false, false);
                }
            }
        } else {
            factory->fwd.listener.on_data = fwd_client_on_data;
            factory->fwd.listener.userdata = (uintptr_t)factory;
            factory->fwd.reader = qeocore_reader_open(factory, type, org_qeo_system_Forwarder_type->name,
                                                      QEOCORE_EFLAG_STATE_DATA, &factory->fwd.listener, NULL);
            /* note: reader construction failure is not fatal */
            if (qeocore_parameter_get_number("FWD_DISABLE_FORWARDING")) {
                qeo_log_i("Disable forwarding");
                factory->fwd.u.client.state = FWD_CLIENT_STATE_READY;
            }
            else {
                factory->fwd.u.client.state = FWD_CLIENT_STATE_INIT;
                client_state_machine_eval_ul(factory, CLIENT_EVENT_START, NULL, -1);
            }
            rc = QEO_OK;
        }
        unlock(&factory->mutex);
        qeocore_type_free(type);
    }
    return rc;
}
예제 #3
0
qeo_state_reader_t *qeo_factory_create_state_reader(const qeo_factory_t *factory,
                                                    const DDS_TypeSupport_meta *type,
                                                    const qeo_state_reader_listener_t *listener,
                                                    uintptr_t userdata)
{
    qeo_state_reader_t *reader = NULL;

    if ((NULL != factory) && (NULL != type) &&
            ((NULL == listener) || (NULL != listener->on_update) || (NULL != listener->on_policy_update))) {
        qeocore_reader_listener_t l = { 0 }, *pl = NULL;
        reader_dispatcher_cookie *dc = NULL;
        qeo_retcode_t rc = QEO_OK;
        qeocore_type_t *t = NULL;

        if (NULL != listener) {
            dc = calloc(1, sizeof(*dc));
            if (NULL != dc) {
                dc->etype = QEO_ETYPE_STATE_UPDATE;
                dc->listener.state = *listener;
                dc->userdata = userdata;
                if (NULL != listener->on_update) {
                    l.on_data = core_callback_dispatcher;
                }
                if (NULL != listener->on_policy_update) {
                    l.on_policy_update = core_reader_policy_update_callback_dispatcher;
                }
                l.userdata = (uintptr_t)dc;
                pl = &l;
            }
            else {
                rc = QEO_ENOMEM;
            }
        }
        if (QEO_OK == rc) {
            t = qeocore_type_register_tsm(factory, type, type->name);
            if (NULL != t) {
                reader = (qeo_state_reader_t *)qeocore_reader_open(factory, t, NULL,
                                                                   QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE,
                                                                   pl, NULL);
                qeocore_type_free(t);
            }
            if (NULL == reader) {
                free(dc);
            }
        }
    }
    return reader;
}
static void run_reader(void)
{
    qeo_factory_t *factory;
    qeocore_type_t *type_nest_i;
    qeocore_reader_t *reader;
    qeocore_reader_listener_t listener = { .on_data = my_on_data_available };

    sem_init(&_sync, 0, 0);
    assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
    init_factory(factory);
    assert(NULL != (type_nest_i = type_nest_i_register(factory)));
    assert(NULL != (reader = qeocore_reader_open(factory, type_nest_i, NULL,
                             QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                             &listener, NULL)));
    log_pid("=============================== reader initialized");
    sem_wait(&_sync); /* wait for sample */
    log_pid("=============================== reader done");
    sem_destroy(&_sync);
    qeocore_reader_close(reader);
    qeocore_type_free(type_nest_i);
    qeocore_factory_close(factory);
}
예제 #5
0
파일: de1804_main.c 프로젝트: bq/qeo-core
int main(int argc, const char **argv)
{
    qeo_factory_t *factory;
    qeocore_reader_t *reader;
    qeocore_writer_t *writer;
    qeocore_type_t *type;
    qeocore_data_t *rdata, *wdata;
    int i;

    for (i = 0; i < 2; i++) {
        /* initialize */
        assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
        init_factory(factory);
        assert(NULL != (type = nested_type_get(1, 0, 0)));
        assert(QEO_OK == qeocore_type_register(factory, type, "nested"));
        assert(NULL != (reader = qeocore_reader_open(factory,  type, NULL,
                                                     QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE, NULL, NULL)));
        assert(NULL != (writer = qeocore_writer_open(factory, type, NULL,
                                                     QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE, NULL, NULL)));
        /* write */
        assert(NULL != (wdata = qeocore_writer_data_new(writer)));
        fill_data(wdata);
        assert(QEO_OK == qeocore_writer_write(writer, wdata));
        /* check data */
        assert(NULL != (rdata = qeocore_reader_data_new(reader)));
        assert(QEO_OK == qeocore_reader_read(reader, NULL, rdata));
        expected_status = QEOCORE_DATA;
        validate_data(rdata);
        /* remove */
        assert(QEO_OK == qeocore_writer_remove(writer, wdata));
        /* clean up */
        qeocore_data_free(wdata);
        qeocore_data_free(rdata);
        qeocore_writer_close(writer);
        qeocore_reader_close(reader);
        qeocore_type_free(type);
        qeocore_factory_close(factory);
    }
}
예제 #6
0
qeo_state_change_reader_t *qeo_factory_create_state_change_reader(const qeo_factory_t *factory,
                                                                  const DDS_TypeSupport_meta *type,
                                                                  const qeo_state_change_reader_listener_t *listener,
                                                                  uintptr_t userdata)
{
    qeo_state_change_reader_t *reader = NULL;

    if ((NULL != factory) && (NULL != type) && (NULL != listener) &&
        ((NULL != listener->on_data) || (NULL != listener->on_remove))) {
        reader_dispatcher_cookie *dc = calloc(1, sizeof(*dc));

        if (NULL != dc) {
            qeocore_type_t *t = qeocore_type_register_tsm(factory, type, type->name);

            if (NULL != t) {
                qeocore_reader_listener_t l = { 0 };

                dc->etype = QEO_ETYPE_STATE_DATA;
                dc->listener.state_change = *listener;
                dc->userdata = userdata;
                l.on_data = core_callback_dispatcher;
                if (NULL != listener->on_policy_update) {
                    l.on_policy_update = core_reader_policy_update_callback_dispatcher;
                }
                l.userdata = (uintptr_t)dc;
                reader = (qeo_state_change_reader_t *)qeocore_reader_open(factory, t, NULL,
                                                                          QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                                                                          &l, NULL);
                qeocore_type_free(t);
            }
            if (NULL == reader) {
                free(dc);
            }
        }
    }
    return reader;
}
예제 #7
0
int main(int argc, const char **argv)
{
    qeo_factory_t *factory;
    qeocore_type_t *type;
    qeocore_reader_t *reader;
    qeocore_reader_listener_t listener = { .on_data = on_data_available };
    qeocore_writer_t *writer;
    int i = 0;

    /* initialize */
    sem_init(&_sync, 0, 0);
    sem_init(&_sync_nodata, 0, 0);
    assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
    init_factory(factory);
    assert(NULL != (type = qeocore_type_register_tsm(factory, org_qeo_dynamic_qdm_test_TypeWithStructs_type, org_qeo_dynamic_qdm_test_TypeWithStructs_type[0].name)));
    assert(NULL != (reader = qeocore_reader_open(factory, type, NULL, QEOCORE_EFLAG_EVENT_DATA, &listener, NULL)));
    assert(NULL != (writer = qeocore_writer_open(factory, type, NULL, QEOCORE_EFLAG_EVENT_DATA, NULL, NULL)));
    /* test late enabling of readers/writers */
    assert(QEO_OK == qeocore_reader_enable(reader));
    assert(QEO_OK == qeocore_writer_enable(writer));
    /* send structure */
    for(i = 0; i < 20; i++){
        log_verbose("testing with %d", i);
        assert(QEO_OK == write_generated_data(writer, i));
        log_verbose("waiting for data");
        /* wait for reception */
        sem_wait(&_sync);
        sem_wait(&_sync_nodata);
    }

    /* clean up */
    qeocore_writer_close(writer);
    qeocore_reader_close(reader);
    qeocore_type_free(type);
    qeocore_factory_close(factory);
    sem_destroy(&_sync);
}
예제 #8
0
파일: test.c 프로젝트: JianlongCao/qeo-core
    };

    DDS_SEQ_INIT(chat_msg.extraInfo);
    dds_seq_from_array(&chat_msg.extraInfo, byte_array, sizeof(byte_array) / sizeof(byte_array[0]));


    DDS_SEQ_INIT(chat_msg.list);
    dds_seq_from_array(&chat_msg.list, scanlist_array, sizeof(scanlist_array) / sizeof(scanlist_array[0]));

    DDS_SEQ_INIT(chat_msg.colorlist);
    dds_seq_from_array(&chat_msg.colorlist, enum_array, sizeof(enum_array) / sizeof(enum_array[0]));

    /* reading */
    qeocore_reader_t *event_reader = qeocore_reader_open(_factory,
            type,
            org_qeo_sample_simplechat_ChatMessage_type[0].name,
            QEOCORE_EFLAG_EVENT_DATA | QEOCORE_EFLAG_ENABLE,
            &_sc_rlistener,
            &ret);
    ck_assert_int_ne(event_reader, NULL);

    /* writing */
    qeocore_writer_t *event_writer = qeocore_writer_open(_factory,
            type,
            org_qeo_sample_simplechat_ChatMessage_type[0].name,
            QEOCORE_EFLAG_EVENT_DATA | QEOCORE_EFLAG_ENABLE,
            NULL, /* FIX ME */
            &ret);
    qeocore_type_free(type);
    ck_assert_int_ne(event_writer, NULL);
    ck_assert_int_eq(ret, QEO_OK);
int main(int argc, const char **argv)
{

    pid_t pid;

    pid = fork();

    if (pid == -1) {
       perror("fork failed");
       exit(EXIT_FAILURE);
    }
    else if (pid == 0) {
       log_verbose("=================== WRITER of type 1 \n");

       qeo_factory_t *factory;
       qeocore_type_t *type1;
       qeocore_writer_t *writer;

       /* initialize */
       assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
       init_factory(factory);
       log_verbose(" =================== c qeocore_type_register_tsm(factory, _tsm_type_qdm_version1, _tsm_type_qdm_version1[0].name) \n");
       assert(NULL != (type1 = qeocore_type_register_tsm(factory, _tsm_type_qdm_version1, _tsm_type_qdm_version1[0].name)));
       log_verbose(" =================== c qeocore_writer_open(factory, type1, NULL, QEOCORE_EFLAG_EVENT_DATA, NULL, NULL) \n");
       assert(NULL != (writer = qeocore_writer_open(factory, type1, NULL, QEOCORE_EFLAG_EVENT_DATA, NULL, NULL)));
       /* test late enabling of readers/writers */
       log_verbose(" =================== c qeocore_writer_enable(writer) \n");
       assert(QEO_OK == qeocore_writer_enable(writer));
       /* send structure */
       sleep(2);
       log_verbose(" =================== c qeocore_writer_write(writer, &_type_qdm_version1) \n");
       assert(QEO_OK == qeocore_writer_write(writer, &_type_qdm_version1));
       sleep(2);
       /* clean up */
       qeocore_writer_close(writer);
       qeocore_type_free(type1);
       qeocore_factory_close(factory);
       _exit(EXIT_SUCCESS);
    }
    else {
       log_verbose("=================== READER of type 2 \n");

       qeo_factory_t *factory;
       qeocore_type_t *type2;
       qeocore_reader_t *reader;
       qeocore_reader_listener_t listener = { .on_data = on_data_available };

       /* initialize */
       sem_init(&_sync, 0, 0);
       sem_init(&_sync_nodata, 0, 0);
       assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
       init_factory(factory);
       log_verbose(" =================== p qeocore_type_register_tsm(factory, _tsm_type_qdm_version2, _tsm_type_qdm_version2[0].name) \n");
       assert(NULL != (type2 = qeocore_type_register_tsm(factory, _tsm_type_qdm_version2, _tsm_type_qdm_version2[0].name)));
       log_verbose(" =================== p qeocore_reader_open(factory, type2, NULL, QEOCORE_EFLAG_EVENT_DATA, &listener, NULL)  \n");
       assert(NULL != (reader = qeocore_reader_open(factory, type2, NULL, QEOCORE_EFLAG_EVENT_DATA, &listener, NULL)));
       /* test late enabling of readers/writers */
       log_verbose(" =================== p qeocore_reader_enable(reader) \n");
       assert(QEO_OK == qeocore_reader_enable(reader));
       /* wait for reception */
       log_verbose(" =================== p sem_wait(&_sync) \n");
       sem_wait(&_sync);
       log_verbose(" =================== p sem_wait(&_sync_nodata) \n");
       sem_wait(&_sync_nodata);
       /* clean up */
       qeocore_reader_close(reader);
       qeocore_type_free(type2);
       qeocore_factory_close(factory);
       sem_destroy(&_sync);

       int status;
       (void)waitpid(pid, &status, 0);
    }
    return EXIT_SUCCESS;



}
예제 #10
0
    sem_init(&_notify_sync, 0, 0);
    assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_OPEN)));
    init_factory(factory);


    assert(NULL != (type[0] = qeocore_type_register_tsm(factory, org_qeo_system_RegistrationRequest_type, org_qeo_system_RegistrationRequest_type[0].name)));
    assert(NULL != (writer[0] = qeocore_writer_open(factory, type[0], NULL,
                                                    QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE, NULL, NULL)));
        /* send registration request */
    log_verbose("send registration request 1");
    _current_regreq = &_regreq[0];
    /* Already write before creating the readers. (see DE2772) */
    qeocore_writer_write(writer[0], _current_regreq);

    assert(NULL != (reader[0] = qeocore_reader_open(factory, type[0], NULL,
                                                    QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE, &listener[0],
                                                    NULL)));
    assert(NULL != (change[0] = qeocore_reader_open(factory, type[0], NULL,
                                                    QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE, &listener[0],
                                                    NULL)));
    assert(NULL != (type[1] = qeocore_type_register_tsm(factory, org_qeo_system_RegistrationCredentials_type, org_qeo_system_RegistrationCredentials_type[0].name)));
    assert(NULL != (reader[1] = qeocore_reader_open(factory, type[1], NULL,
                                                    QEOCORE_EFLAG_STATE_UPDATE | QEOCORE_EFLAG_ENABLE, &listener[1],
                                                    NULL)));
    assert(NULL != (change[1] = qeocore_reader_open(factory, type[1], NULL,
                                                    QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE, &listener[1],
                                                    NULL)));
    assert(NULL != (writer[1] = qeocore_writer_open(factory, type[1], NULL,
                                                    QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE, NULL, NULL)));
    log_verbose("initialization done");
예제 #11
0
static qeojson_reader_t *qeojson_reader_open(const qeo_factory_t    *factory,
                                             qeojson_reader_type_t  reader_type,
                                             void                   *listener,
                                             const char             *json_type,
                                             uintptr_t              userdata)
{
    qeo_retcode_t                   ret                 = QEO_EFAIL;
    qeojson_reader_t                *jsonreader         = NULL;
    qeocore_type_t                  *typedesc           = NULL;
    json_reader_dispatcher_cookie_t *dc                 = NULL;
    json_t                          *jsonTypeDesc       = NULL;
    json_t                          *behavior           = NULL;
    const char                      *expected_behaviour = NULL;
    int                             flags               = QEOCORE_EFLAG_NONE;
    qeocore_reader_listener_t       l = { 0 };

    if ((NULL == factory) || (NULL == json_type)) {
        return NULL;
    }


    do {
        dc = calloc(1, sizeof(json_reader_dispatcher_cookie_t));
        if (NULL == dc) {
            break;
        }

        dc->userdata = userdata;

        switch (reader_type) {
            case QEOJSON_READER_TYPE_EVENT_READER:
                flags = QEOCORE_EFLAG_EVENT_DATA;
                expected_behaviour = "event";
                qeo_json_event_reader_listener_t *event_listener = (qeo_json_event_reader_listener_t *) listener;
                dc->etype           = QEO_ETYPE_EVENT_DATA;
                dc->listener.event  = *event_listener;
                if (NULL != event_listener->on_policy_update) {
                    l.on_policy_update = qeojson_core_reader_policy_update_callback_dispatcher;
                }
                break;

            case QEOJSON_READER_TYPE_STATE_READER:
                flags = QEOCORE_EFLAG_STATE_UPDATE;
                expected_behaviour = "state";
                qeo_json_state_reader_listener_t *state_listener = (qeo_json_state_reader_listener_t *)listener;
                dc->etype           = QEO_ETYPE_STATE_UPDATE;
                dc->listener.state  = *state_listener;
                if (NULL != state_listener->on_policy_update) {
                    l.on_policy_update = qeojson_core_reader_policy_update_callback_dispatcher;
                }
                if (NULL != state_listener->on_update) {
                    l.on_data = qeojson_core_callback_dispatcher;
                }

                break;

            case QEOJSON_READER_TYPE_STATE_CHANGE_READER:
                flags = QEOCORE_EFLAG_STATE_DATA;
                expected_behaviour = "state";
                qeo_json_state_change_reader_listener_t *state_change_listener = (qeo_json_state_change_reader_listener_t *) listener;
                dc->etype = QEO_ETYPE_STATE_DATA;
                dc->listener.state_change = *state_change_listener;
                if (NULL != state_change_listener->on_policy_update) {
                    l.on_policy_update = qeojson_core_reader_policy_update_callback_dispatcher;
                }
                l.on_data = qeojson_core_callback_dispatcher;

                break;
        }

        jsonTypeDesc = json_loads(json_type, 0, NULL);
        if (NULL == jsonTypeDesc) {
            qeo_log_e("Could not parse json");
            break;
        }

        if (!json_is_object(jsonTypeDesc)) {
            break;
        }

        behavior = json_object_get(jsonTypeDesc, KEY_BEHAVIOR);

        if (!json_is_string(behavior)) {
            break;
        }


        if (0 != strcmp(json_string_value(behavior), expected_behaviour)) {
            break;
        }

        jsonreader = calloc(1, sizeof(qeojson_reader_t));
        if (jsonreader == NULL) {
            break;
        }

        jsonreader->policy_cache = json_object();
        json_object_set_new(jsonreader->policy_cache, "users", json_array());

        jsonreader->policy = json_object();
        json_object_set_new(jsonreader->policy, "users", json_array());

#ifdef __USE_GNU
        /* compile with -D_GNU_SOURCE */
#ifndef NDEBUG
        jsonreader->policy_mutex = (pthread_mutex_t)PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
#else
        jsonreader->policy_mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
#endif
#else
        jsonreader->policy_mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
#endif

        typedesc = types_from_json(factory, jsonTypeDesc);
        if (NULL == typedesc) {
            qeo_log_e("typedesc == NULL");
            break;
        }

        dc->typedesc        = jsonTypeDesc;
        l.on_data           = qeojson_core_callback_dispatcher;
        l.userdata          = (uintptr_t)dc;
        dc->jsonreader      = jsonreader;
        jsonreader->reader  = qeocore_reader_open(factory,                          // factory
                                                  typedesc,                         // type
                                                  NULL,                             // callback dispatcher
                                                  flags,                            // flags
                                                  &l,                               // callback cookie
                                                  NULL);                            // return code
        qeocore_type_free(typedesc);
        if (NULL == jsonreader->reader) {
            break;
        }

        ret = QEO_OK;
    } while (0);

    if (QEO_OK != ret) {
        json_decref(jsonTypeDesc);
        qeojson_reader_close(jsonreader);
        jsonreader = NULL;
        free(dc);
    }


    return jsonreader;
}