コード例 #1
0
ファイル: kaa_logging.c プロジェクト: xwiz/kaa
static bool is_timeout(kaa_log_collector_t *self)
{
    KAA_RETURN_IF_NIL2(self, self->timeouts, false);

    bool is_timeout = false;
    kaa_time_t now = KAA_TIME();

    kaa_list_node_t *it = kaa_list_begin(self->timeouts);
    while (it) {
        timeout_info_t *info = (timeout_info_t *)kaa_list_get_data(it);
        if (now >= info->timeout) {
            KAA_LOG_WARN(self->logger, KAA_ERR_TIMEOUT, "Log delivery timeout occurred (bucket_id %u)", info->log_bucket_id);
            is_timeout = true;
            break;
        }
        it = kaa_list_next(it);
    }

    if (is_timeout) {
        it = kaa_list_begin(self->timeouts);
        while (it) {
            timeout_info_t *info = (timeout_info_t *)kaa_list_get_data(it);
            ext_log_storage_unmark_by_bucket_id(self->log_storage_context, info->log_bucket_id);
            it = kaa_list_next(it);
        }

        kaa_list_clear(self->timeouts, NULL);
        ext_log_upload_strategy_on_timeout(self->log_upload_strategy_context);
    }

    return is_timeout;
}
コード例 #2
0
ファイル: test_kaa_list.c プロジェクト: Acarus/kaa
static void test_list_sort()
{
    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    uint64_t node_number = 100;
    for (uint64_t i = 0; i < node_number; ++i) {
        test_list_node_t *node = KAA_MALLOC(sizeof(test_list_node_t));
        ASSERT_NOT_NULL(node);
        node->id = (uint64_t) rand();
        kaa_list_push_back(list, node);
    }

    ASSERT_EQUAL(kaa_list_get_size(list), node_number);

    kaa_list_sort(list,&test_kaa_list_predicate);
    kaa_list_node_t *it,*next;
    it = kaa_list_begin(list);
    next = kaa_list_next(it);
    while (it && next) {
        ASSERT_TRUE(((test_list_node_t*)kaa_list_get_data(it))->id <=
                ((test_list_node_t*)kaa_list_get_data(next))->id);
        it = next;
        next = kaa_list_next(it);
    }
    kaa_list_destroy(list, NULL);
}
コード例 #3
0
ファイル: test_kaa_log.c プロジェクト: Oleh-Kravchenko/kaa
kaa_error_t ext_log_storage_write_next_record(void *context, char *buffer, size_t buffer_len,
        uint16_t *bucket_id, size_t *record_len)
{
    mock_storage_context_t *self = context;
    KAA_RETURN_IF_NIL2(self, self->logs, KAA_ERR_NOT_FOUND);

    kaa_list_node_t *node = kaa_list_find_next(kaa_list_begin(self->logs),
            match_unprocessed, NULL);

    if (!node) {
        return KAA_ERR_NOT_FOUND;
    }

    test_log_record_t *record = kaa_list_get_data(node);

    if (buffer_len < record->rec.size) {
        return KAA_ERR_INSUFFICIENT_BUFFER;
    }

    *record_len = record->rec.size;
    *bucket_id = record->rec.bucket_id;
    memcpy(buffer, record->rec.data, *record_len);
    record->processed = true;
    return KAA_ERR_NONE;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: BillTheBest/sample-apps
void checkFencingPosition(rfid_t rfid)
{
    kaa_context_t *kaa_context = kaa_client_get_context(kaa_client);
    const kaa_root_configuration_t *configuration = kaa_configuration_manager_get_configuration(kaa_context->configuration_manager);

    if (configuration) {
        int new_zone_id = UNKNOWN_GEOFENCING_ZONE_ID;

        kaa_list_node_t *zones_it = kaa_list_begin(configuration->zones);
        while (zones_it && (new_zone_id == UNKNOWN_GEOFENCING_ZONE_ID)) {
            kaa_configuration_geo_fencing_zone_t *zone = (kaa_configuration_geo_fencing_zone_t *)kaa_list_get_data(zones_it);
            kaa_list_node_t *zone_tag_it = kaa_list_begin(zone->tags);

            while (zone_tag_it && (new_zone_id == UNKNOWN_GEOFENCING_ZONE_ID)) {
                int64_t *tag = (int64_t *)kaa_list_get_data(zone_tag_it);
                if (*tag == rfid) {
                    new_zone_id = zone->id;
                }

                zone_tag_it = kaa_list_next(zone_tag_it);
            }
            zones_it = kaa_list_next(zones_it);
        }

        notifyOfNewFencingZone(new_zone_id);
    } else {
        debug("Skip check fencing position: configuration is null\r\n");
    }
}
コード例 #5
0
ファイル: kaa_logging.c プロジェクト: Kirill380/kaa
/** Handles timeout event. Must be called if timeout is occurred. */
static void handle_timeout(kaa_log_collector_t *self)
{
    // TODO(KAA-982): Use asserts
    if (!self || !self->timeouts) {
        return;
    }

    kaa_error_t err = ext_log_upload_strategy_on_timeout(self->log_upload_strategy_context);

    bool expire_every_entry = (err == KAA_ERR_EVENT_NOT_ATTACHED);

    if (expire_every_entry) {
        /* Upload strategy decided to switch an access point. All pending logs are now deemed as
         * timeouted.
         */
        KAA_LOG_INFO(self->logger, KAA_ERR_NONE, "Access point has been switched. All buckets are expired.");
    }

    for (kaa_list_node_t *it = kaa_list_begin(self->timeouts); it; it = kaa_list_next(it)) {
        timeout_info_t *info = kaa_list_get_data(it);

        if (expire_every_entry || !info->deadline) {
            ext_log_storage_unmark_by_bucket_id(self->log_storage_context, info->log_bucket_id);
            if (self->log_delivery_listeners.on_timeout) {
                kaa_log_bucket_info_t log_bucket_info = {
                    .bucket_id = info->log_bucket_id,
                    .log_count = info->log_count,
                };

                self->log_delivery_listeners.on_timeout(self->log_delivery_listeners.ctx,
                        &log_bucket_info);
            }
        }
    }
コード例 #6
0
ファイル: application.c プロジェクト: Limpinho0/sample-apps
kaa_error_t kaa_on_configuration_updated(void *context, const kaa_root_configuration_t *configuration)
{
    int i = 0;
    sndc_printf("Configuration updated\n");
    kaa_list_node_t *it = kaa_list_begin(configuration->light_zones);
    while (it) {
        kaa_configuration_light_zone_t *zone = (kaa_configuration_light_zone_t *) kaa_list_get_data(it);
        if (zone->zone_id >= 0 && zone->zone_id < LIGHT_ZONES_COUNT) {
            switch (zone->zone_status) {
            case ENUM_ZONE_STATUS_ENABLE:
                if (light_states[i] != LIGHT_ON) {
                    sndc_io_write(light_zones[zone->zone_id], LIGHT_ON);
                    light_states[i] = LIGHT_ON;
                }
                break;
            case ENUM_ZONE_STATUS_DISABLE:
                if (light_states[i] != LIGHT_OFF) {
                    sndc_io_write(light_zones[zone->zone_id], LIGHT_OFF);
                    light_states[i] = LIGHT_OFF;
                }
                break;
            }
        }
        it = kaa_list_next(it);
        i++;
    }
    for(; i < LIGHT_ZONES_COUNT; ++i) {
        if (light_states[i] != LIGHT_OFF) {
             sndc_io_write(light_zones[i], LIGHT_OFF);
             light_states[i] = LIGHT_OFF;
        }
    }

    return KAA_ERR_NONE;
}
コード例 #7
0
ファイル: test_kaa_list.c プロジェクト: nthevu/kaa
void test_list_push_front()
{
    KAA_TRACE_IN(logger);

    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    int32_t *number;
    int node_number = 2;
    for (int i = 0; i < node_number; ++i) {
        number = (int32_t *)KAA_MALLOC(sizeof(int32_t *));
        ASSERT_NOT_NULL(number);
        *number = rand();
        kaa_list_push_front(list, number);
    }

    ASSERT_EQUAL(kaa_list_get_size(list), node_number);

    ASSERT_NOT_NULL(kaa_list_begin(list));
    ASSERT_NULL(kaa_list_prev(kaa_list_begin(list)));

    ASSERT_EQUAL((*(int32_t *)kaa_list_get_data(kaa_list_begin(list))), *number);

    kaa_list_destroy(list, NULL);

    KAA_TRACE_OUT(logger);
}
コード例 #8
0
ファイル: test_kaa_list.c プロジェクト: nthevu/kaa
void test_list_for_each()
{
    KAA_TRACE_IN(logger);

    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    int32_t *number1_ptr;
    int node_number = 4;
    for (int i = 0; i < node_number; ++i) {
        number1_ptr = (int32_t *)KAA_MALLOC(sizeof(int32_t *));
        ASSERT_NOT_NULL(number1_ptr);
        *number1_ptr = rand();
        kaa_list_push_back(list, number1_ptr);
    }

    int number2 = rand();
    kaa_list_for_each(kaa_list_begin(list), kaa_list_back(list), (process_data)&test_process_data, &number2);

    kaa_list_node_t *it = kaa_list_begin(list);
    while (it) {
        ASSERT_EQUAL(*(int32_t *)kaa_list_get_data(kaa_list_begin(list)), number2);
        it = kaa_list_next(it);
    }

    kaa_list_destroy(list, NULL);

    KAA_TRACE_OUT(logger);
}
コード例 #9
0
ファイル: kaa_demo.c プロジェクト: Limpinho0/sample-apps
void kaa_demo_print_configuration_message(const kaa_root_configuration_t *configuration)
{
    if (configuration->address_list->type == KAA_CONFIGURATION_UNION_ARRAY_LINK_OR_NULL_BRANCH_0) {
        DEMO_LOG("Configuration body:");

        kaa_list_node_t *it = kaa_list_begin((kaa_list_t*) configuration->address_list->data);
        while (it) {
            kaa_configuration_link_t* current_link = (kaa_configuration_link_t*) kaa_list_get_data(it);
            DEMO_LOG("%s - %s", current_link->label->data,current_link->url->data);
            it = kaa_list_next(it);
        }
    } else {
        DEMO_LOG("Configuration body: null");
    }
}
コード例 #10
0
ファイル: test_kaa_list.c プロジェクト: Acarus/kaa
static void test_list_push_back()
{
    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    int32_t *number;
    int node_number = 2;
    for (int i = 0; i < node_number; ++i) {
        number = KAA_MALLOC(sizeof(int32_t *));
        ASSERT_NOT_NULL(number);
        *number = rand();
        kaa_list_push_back(list, number);
    }

    ASSERT_EQUAL(kaa_list_get_size(list), node_number);
    ASSERT_EQUAL((*(int32_t *)kaa_list_get_data(kaa_list_back(list))), *number);

    kaa_list_destroy(list, NULL);
}
コード例 #11
0
ファイル: kaa_logging.c プロジェクト: Kirill380/kaa
/* Returns amount of logs in bucket */
static size_t remove_request(kaa_log_collector_t *self, uint16_t bucket_id)
{
    kaa_list_node_t     *node;
    timeout_info_t      *info;
    size_t              logs_sent = 0;

    node = kaa_list_find_next(kaa_list_begin(self->timeouts), find_by_bucket_id, &bucket_id);

    if (node) {
        info = kaa_list_get_data(node);

        if (info) {
            logs_sent = info->log_count;
        }

        kaa_list_remove_at(self->timeouts, node, NULL);
    }

    return logs_sent;
}
コード例 #12
0
static void test_array_deserialize_w_ctx(void **state)
{
    (void)state;

    const uint8_t plain_fixed[] = { 0x0, 0x1, 0x2, 0x3, 0x4 };
    size_t plain_fixed_size = sizeof(plain_fixed) / sizeof(char);

    size_t array_size = 1 + rand() % 10;

    kaa_list_t *avro_array1 = kaa_list_create();
    size_t i = 0;
    for (i = 0; i < array_size; ++i) {
        kaa_list_push_back(avro_array1, kaa_fixed_copy_create(plain_fixed, plain_fixed_size));
    }

    size_t buffer_size = kaa_array_get_size(avro_array1, kaa_fixed_get_size);
    char buffer[buffer_size];
    avro_writer_t avro_writer = avro_writer_memory(buffer, buffer_size);

    kaa_array_serialize(avro_writer, avro_array1, kaa_fixed_serialize);

    avro_reader_t avro_reader = avro_reader_memory(buffer, buffer_size);
    kaa_list_t *avro_array2 = kaa_array_deserialize_w_ctx(avro_reader, (deserialize_w_ctx_fn)kaa_fixed_deserialize, &plain_fixed_size);

    ASSERT_NOT_NULL(avro_array2);
    ASSERT_EQUAL(kaa_list_get_size(avro_array2), array_size);

    kaa_list_node_t *it = kaa_list_begin(avro_array2);
    while (it) {
        kaa_bytes_t *fixed = kaa_list_get_data(it);
        ASSERT_NOT_NULL(fixed);
        ASSERT_EQUAL((size_t)fixed->size, plain_fixed_size);
        ASSERT_EQUAL(memcmp(fixed->buffer, plain_fixed, plain_fixed_size), 0);
        it  = kaa_list_next(it);
    }

    kaa_list_destroy(avro_array2, kaa_fixed_destroy);
    avro_reader_free(avro_reader);
    avro_writer_free(avro_writer);
    kaa_list_destroy(avro_array1, kaa_fixed_destroy);
}
コード例 #13
0
static void test_array_deserialize_wo_ctx(void **state)
{
    (void)state;

    size_t array_size = 1 + rand() % 10;

    kaa_list_t *avro_array1 = kaa_list_create();
    size_t i = 0;
    for (i = 0; i < array_size; ++i) {
        kaa_list_push_back(avro_array1, create_float());
    }

    size_t buffer_size = kaa_array_get_size(avro_array1, kaa_float_get_size);
    char buffer[buffer_size];
    avro_writer_t avro_writer = avro_writer_memory(buffer, buffer_size);

    kaa_array_serialize(avro_writer, avro_array1, kaa_float_serialize);

    avro_reader_t avro_reader = avro_reader_memory(buffer, buffer_size);
    kaa_list_t *avro_array2 = kaa_array_deserialize_wo_ctx(avro_reader, (deserialize_wo_ctx_fn)kaa_float_deserialize);

    ASSERT_NOT_NULL(avro_array2);
    ASSERT_EQUAL(kaa_list_get_size(avro_array2), array_size);

//    /*
//     * Deserialized array has a back order, so reverse the original.
//     */
//    kaa_list_t *reverse_avro_array = NULL;
//    kaa_list_t *it = avro_array1;
//    while (it) {
//        if (reverse_avro_array) {
//            reverse_avro_array = kaa_list_push_front(reverse_avro_array, kaa_list_get_data(it));
//        } else {
//            reverse_avro_array = kaa_list_create(kaa_list_get_data(it));
//        }
//        it  = kaa_list_next(it);
//    }
//
//    kaa_list_destroy(avro_array1, kaa_null_destroy);
//    avro_array1 = reverse_avro_array;

    /*
     * Compare origin and deserialized arrays.
     */
    kaa_list_node_t *it1 = kaa_list_begin(avro_array1);
    kaa_list_node_t *it2 = kaa_list_begin(avro_array2);
    while (it1 && it2) {
        float *float_value1 = kaa_list_get_data(it1);
        float *float_value2 = kaa_list_get_data(it2);

        ASSERT_NOT_NULL(float_value1);
        ASSERT_NOT_NULL(float_value2);
        ASSERT_EQUAL(*float_value2, *float_value1);

        it1  = kaa_list_next(it1);
        it2  = kaa_list_next(it2);
    }

    kaa_list_destroy(avro_array2, kaa_data_destroy);
    avro_reader_free(avro_reader);
    avro_writer_free(avro_writer);
    kaa_list_destroy(avro_array1, kaa_data_destroy);
}