Exemplo n.º 1
0
static void qeojson_writer_close(qeojson_writer_t *jsonwriter)
{
    json_writer_dispatcher_cookie_t *dc   = NULL;

    if (jsonwriter == NULL) {
        return;
    }

    do {
        if (NULL != jsonwriter->writer) {
            dc = (json_writer_dispatcher_cookie_t *)qeocore_writer_get_userdata(jsonwriter->writer);
            if (dc == NULL) {
                break;
            }

            if (NULL != dc->typedesc) {
                json_decref(dc->typedesc);
                dc->typedesc = NULL;
            }
            qeocore_writer_close(jsonwriter->writer);
            free(dc);
        }

        if (NULL != jsonwriter->policy_cache) {
            json_decref(jsonwriter->policy_cache);
        }

        if (NULL != jsonwriter->policy) {
            json_decref(jsonwriter->policy);
        }

        free(jsonwriter);
    } while (0);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
void fwd_destroy(qeo_factory_t *factory)
{
    lock(&factory->mutex);
    if (true == factory->fwd.rqst_pending) {
        /* Wait untill the fwd request is finished before continuing. */
        qeo_log_i("waiting for the fwd request to finish.");
        pthread_cond_wait(&factory->fwd.wait_rqst_finished, &factory->mutex);
    }
    unlock(&factory->mutex);
    if (factory->flags.is_forwarder) {
        fwd_server_unregister(factory);
        if (FWD_STATE_ENABLED == factory->fwd.u.server.state) {
            if (QEO_OK != fwd_server_instance_remove(factory)) {
                qeo_log_e("failed to remove instance from forwarder topic");
            }
        }
        if (NULL != factory->fwd.u.server.writer) {
            qeocore_writer_close(factory->fwd.u.server.writer);
        }
    }
    if (NULL != factory->fwd.reader) {
        qeocore_reader_close(factory->fwd.reader);
    }
    if (NULL != factory->fwd.timer) {
        DDS_Timer_delete(factory->fwd.timer);
    }
    pthread_cond_destroy(&factory->fwd.wait_rqst_finished);
    fwd_locator_destroy(factory);
}
Exemplo n.º 4
0
void qeo_state_writer_close(qeo_state_writer_t *writer)
{
    if (NULL != writer) {
        writer_dispatcher_cookie *dc = (writer_dispatcher_cookie *)qeocore_writer_get_userdata((qeocore_writer_t *)writer);

        qeocore_writer_close((qeocore_writer_t *)writer);
        free(dc);
    }
}
Exemplo n.º 5
0
static void run_writer(pid_t peer)
{
    // writer is a type_nest_i writer
    qeo_factory_t *factory;
    qeocore_type_t *type_nest_i;
    qeocore_writer_t *writer;
    qeocore_data_t *outer=NULL;
    qeocore_data_t *inner=NULL;

    int status;

    /* initialize */
    assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
    init_factory(factory);
    assert(NULL != (type_nest_i = type_nest_i_register(factory)));
    assert(NULL != (writer = qeocore_writer_open(factory, type_nest_i, NULL,
                                                 QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                                                 NULL, NULL)));
    log_pid("=================================== writer initialized");
    assert(NULL != (outer = qeocore_writer_data_new(writer)));
    /* fill outer struct */
    assert(QEO_OK == qeocore_data_set_member(outer, _outer_int32_id, &_outer_int32_value));
    assert(QEO_OK == qeocore_data_set_member(outer, _outer_int8_id, &_outer_int8_value));
    assert(QEO_OK == qeocore_data_set_member(outer, _outer_string_id, &_outer_string_value));
    assert(QEO_OK == qeocore_data_set_member(outer, _outer_int16_id, &_outer_int16_value));
    assert(QEO_OK == qeocore_data_set_member(outer, _outer_int64_id, &_outer_int64_value));

    /* fill inner struct */
    assert(QEO_OK == qeocore_data_get_member(outer, _inner_id, &inner));
    assert(QEO_OK == qeocore_data_set_member(inner, _inner_int32_id, &_inner_int32_value));
    assert(QEO_OK == qeocore_data_set_member(inner, _inner_int8_id, &_inner_int8_value));
    assert(QEO_OK == qeocore_data_set_member(inner, _inner_string_id, &_inner_string_value));
    assert(QEO_OK == qeocore_data_set_member(inner, _inner_int16_id, &_inner_int16_value));
    assert(QEO_OK == qeocore_data_set_member(inner, _inner_int64_id, &_inner_int64_value));
    assert(QEO_OK == qeocore_data_set_member(outer, _inner_id, &inner));
    log_verbose(" =================== _outer_int32_value = %u \n", _outer_int32_value );
    log_verbose(" =================== _outer_int8_value = %u \n", _outer_int8_value );
    log_verbose(" =================== _outer_int16_value = %u \n", _outer_int16_value );
    log_verbose(" =================== _outer_int64_value = %"PRIu64" \n", _outer_int64_value );
    log_verbose(" =================== _inner_int32_value = %u \n", _inner_int32_value );
    log_verbose(" =================== _inner_int8_value = %u \n", _inner_int8_value );
    log_verbose(" =================== _inner_int16_value = %u \n", _inner_int16_value );
    log_verbose(" =================== _inner_int64_value = %"PRIu64" \n", _inner_int64_value );
    /* write */
    assert(QEO_OK == qeocore_writer_write(writer, outer));
    log_pid("===================================== writer wrote outer data");
    assert(peer == waitpid(peer, &status, 0));
    assert(0 == status);
    log_pid("===================================== writer done");
    /* clean up */
    qeocore_data_free(inner);
    qeocore_data_free(outer);
    qeocore_writer_close(writer);
    qeocore_type_free(type_nest_i);
    qeocore_factory_close(factory);
}
Exemplo n.º 6
0
static void run_writer(pid_t peer)
{
    qeo_factory_t *factory;
    qeocore_type_t *type;
    qeocore_writer_t *writer;
    qeocore_data_t *data, *seqdata;
    byte_array_t array;
    int status, i;

    /* initialize */
    assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT)));
    init_factory(factory);
    assert(NULL != (type = type_register(factory)));
    assert(NULL != (writer = qeocore_writer_open(factory, type, NULL,
                                                 QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE,
                                                 NULL, NULL)));
    log_pid("writer initialized");
    assert(NULL != (data = qeocore_writer_data_new(writer)));
    assert(QEO_OK == qeocore_data_set_member(data, _size_id, &_test_size));
    /* init sequence */
    DDS_SEQ_INIT(array);
    assert(NULL != (DDS_SEQ_DATA(array) = malloc(_test_size * sizeof(char))));
    DDS_SEQ_LENGTH(array) = DDS_SEQ_MAXIMUM(array) = _test_size;
    for (i = 0; i < _test_size; i++) {
        DDS_SEQ_ITEM(array, i) = i & 0xff;
    }
    assert(QEO_OK == qeocore_data_get_member(data, _buf_id, &seqdata));
    assert(QEO_OK == qeocore_data_sequence_set(seqdata, (const qeo_sequence_t *)&array, 0));
    assert(QEO_OK == qeocore_data_set_member(data, _buf_id, &seqdata));
    /* write */
    assert(QEO_OK == qeocore_writer_write(writer, data));
    log_pid("writer wrote data");
    assert(peer == waitpid(peer, &status, 0));
    assert(0 == status);
    log_pid("writer done");
    /* clean up */
    free(DDS_SEQ_DATA(array));
    qeocore_data_free(seqdata);
    qeocore_data_free(data);
    qeocore_writer_close(writer);
    qeocore_type_free(type);
    qeocore_factory_close(factory);
}
Exemplo n.º 7
0
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);
    }
}
Exemplo n.º 8
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);
}
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;



}