Esempio n. 1
0
kaa_error_t kaa_extension_logging_request_serialize(void *context, uint32_t request_id,
        uint8_t *buffer, size_t *size, bool *need_resync)
{
    (void)request_id;

    // TODO(KAA-982): Use asserts
    if (!context || !size || !need_resync) {
        return KAA_ERR_BADPARAM;
    }

    kaa_error_t error;

    size_t size_needed;
    error = kaa_logging_request_get_size(context, &size_needed);
    if (error) {
        return error;
    }

    *need_resync = false;
    error = kaa_logging_need_logging_resync(context, need_resync);
    if (error) {
        return error;
    }

    if (!*need_resync) {
        *size = 0;
        return KAA_ERR_NONE;
    }

    if (!buffer || *size < size_needed) {
        *size = size_needed;
        return KAA_ERR_BUFFER_IS_NOT_ENOUGH;
    }

    *size = size_needed;

    kaa_platform_message_writer_t writer = KAA_MESSAGE_WRITER(buffer, *size);
    error = kaa_logging_request_serialize(context, &writer);
    if (error) {
        return error;
    }

    *size = writer.current - buffer;
    return KAA_ERR_NONE;
}
Esempio n. 2
0
static kaa_error_t kaa_client_sync_serialize(kaa_platform_protocol_t *self
        , const kaa_service_t services[]
        , size_t services_count
        , char* buffer
        , size_t *size)
{
    kaa_platform_message_writer_t *writer = NULL;
    kaa_error_t error_code = kaa_platform_message_writer_create(&writer, buffer, *size);
    KAA_RETURN_IF_ERR(error_code);

    uint16_t total_services_count = services_count + 1 /* Meta extension */;

    error_code = kaa_platform_message_header_write(writer, KAA_PLATFORM_PROTOCOL_ID, KAA_PLATFORM_PROTOCOL_VERSION);
    if (error_code) {
        KAA_LOG_ERROR(self->logger, error_code, "Failed to write the client sync header");
        return error_code;
    }
    char *extension_count_p = writer->current;
    writer->current += KAA_PROTOCOL_EXTENSIONS_COUNT_SIZE;

    error_code = kaa_meta_data_request_serialize(self->status, writer, self->request_id);

    while (!error_code && services_count--) {
        switch (services[services_count]) {
        case KAA_SERVICE_BOOTSTRAP: {
            error_code = kaa_channel_manager_bootstrap_request_serialize(self->kaa_context->channel_manager
                         , writer);
            if (error_code)
                KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the bootstrap extension");
            break;
        }
        case KAA_SERVICE_PROFILE: {
            bool need_resync = false;
            error_code = kaa_profile_need_profile_resync(self->kaa_context->profile_manager
                         , &need_resync);
            if (!error_code) {
                if (need_resync) {
                    error_code = kaa_profile_request_serialize(self->kaa_context->profile_manager, writer);
                    if (error_code)
                        KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the profile extension");
                } else {
                    --total_services_count;
                }
            } else {
                KAA_LOG_ERROR(self->logger, error_code, "Failed to read profile's 'need_resync' flag");
            }
            break;
        }
        case KAA_SERVICE_USER: {
            error_code = kaa_user_request_serialize(self->kaa_context->user_manager, writer);
            if (error_code)
                KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the user extension");
            break;
        }
        case KAA_SERVICE_EVENT: {
#ifndef KAA_DISABLE_FEATURE_EVENTS
            error_code = kaa_event_request_serialize(self->kaa_context->event_manager, self->request_id, writer);
            if (error_code)
                KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the event extension");
#else
            --total_services_count;
#endif
            break;
        }
        case KAA_SERVICE_LOGGING: {
#ifndef KAA_DISABLE_FEATURE_LOGGING
            bool need_resync = false;
            error_code = kaa_logging_need_logging_resync(self->kaa_context->log_collector, &need_resync);
            if (!error_code) {
                if (need_resync) {
                    error_code = kaa_logging_request_serialize(self->kaa_context->log_collector, writer);
                    if (error_code)
                        KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the logging extension");
                } else {
                    --total_services_count;
                }
            } else {
                KAA_LOG_ERROR(self->logger, error_code, "Failed to read logging's 'need_resync' flag");
            }
#else
            --total_services_count;
#endif
            break;
        }
        case KAA_SERVICE_CONFIGURATION: {
#ifndef KAA_DISABLE_FEATURE_CONFIGURATION
            error_code = kaa_configuration_manager_request_serialize(self->kaa_context->configuration_manager, writer);
            if (error_code)
                KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the configuration extension");
#else
            --total_services_count;
#endif
            break;
        }
        case KAA_SERVICE_NOTIFICATION: {
#ifndef KAA_DISABLE_FEATURE_NOTIFICATION
            error_code = kaa_notification_manager_request_serialize(self->kaa_context->notification_manager, writer);
            if (error_code)
                KAA_LOG_ERROR(self->logger, error_code, "Failed to serialize the configuration extension");
#else
            --total_services_count;
#endif
            break;
        }
        default:
            break;
        }
    }
    *(uint16_t *) extension_count_p = KAA_HTONS(total_services_count);
    *size = writer->current - writer->begin;
    kaa_platform_message_writer_destroy(writer);

    return error_code;
}