Verified Commit ce832455 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add ADM_qos_limit_list_t plus creation and destruction functions

parent 1a8d1d0e
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -91,6 +91,9 @@ typedef struct adm_dataset_info* ADM_dataset_info_t;
/** A list of datasets */
typedef struct adm_dataset_list* ADM_dataset_list_t;

/** A list of QoS limits */
typedef struct adm_qos_limit_list* ADM_qos_limit_list_t;


/* ----------------------------------------------------- */
/*              Storage tiers                            */
@@ -497,6 +500,30 @@ ADM_qos_limit_create(ADM_qos_entity_t entity, ADM_qos_class_t cls,
ADM_return_t
ADM_qos_limit_destroy(ADM_qos_limit_t limit);

/**
 * Create a list of QoS limits from an array of ADM_QOS_LIMITs and its
 * length.
 *
 * @remark QoS limit lists need to be freed by calling
 * ADM_qos_limit_list_destroy().
 *
 * @param[in] limits The array of QoS limits.
 * @param[in] len The length of the array.
 * @return A valid ADM_qos_limit_list_t if successful or NULL in case of
 * failure.
 */
ADM_qos_limit_list_t
ADM_qos_limit_list_create(ADM_qos_limit_t limits[], size_t len);

/**
 * Destroy a QoS limit list created by ADM_qos_limit_list_create().
 *
 * @param[in] list A valid ADM_qos_limit_list_t
 * @return ADM_SUCCESS or corresponding ADM error code
 */
ADM_return_t
ADM_qos_limit_list_destroy(ADM_qos_limit_list_t list);


/* ----------------------------------------------------- */
/*              Data operations                          */
+69 −0
Original line number Diff line number Diff line
@@ -743,6 +743,75 @@ ADM_transfer_destroy(ADM_transfer_t tx) {
    return ret;
}

ADM_qos_limit_list_t
ADM_qos_limit_list_create(ADM_qos_limit_t limits[], size_t length) {

    ADM_qos_limit_list_t p = (ADM_qos_limit_list_t) malloc(sizeof(*p));

    if(!p) {
        LOGGER_ERROR("Could not allocate ADM_qos_limit_list_t")
        return NULL;
    }

    const char* error_msg = NULL;

    p->l_length = length;
    p->l_limits = (struct adm_qos_limit*) calloc(length, sizeof(adm_qos_limit));

    if(!p->l_limits) {
        error_msg = "Could not allocate ADM_qos_limit_list_t";
        goto cleanup_on_error;
    }

    for(size_t i = 0; i < length; ++i) {
        memcpy(&p->l_limits[i], limits[i], sizeof(adm_qos_limit));
    }

    return p;

cleanup_on_error:
    if(p->l_limits) {
        free(p->l_limits);
    }
    free(p);

    if(error_msg) {
        LOGGER_ERROR(error_msg);
    }

    return NULL;
}

ADM_return_t
ADM_qos_limit_list_destroy(ADM_qos_limit_list_t list) {

    ADM_return_t ret = ADM_SUCCESS;

    if(!list) {
        LOGGER_ERROR("Invalid ADM_qos_limit_list_t")
        return ADM_EBADARGS;
    }

    // We cannot call ADM_qos_limit_destroy here because adm_limits
    // are stored as a consecutive array in memory. Thus, we free
    // the entities themselves and then the array.
    if(list->l_limits) {
        for(size_t i = 0; i < list->l_length; ++i) {

            ADM_qos_entity_t entity = list->l_limits[i].l_entity;

            if(entity) {
                ADM_qos_entity_destroy(entity);
            }
        }
        free(list->l_limits);
    }

    free(list);
    return ret;
}


/******************************************************************************/
/* C++ Type definitions and related functions                                 */
/******************************************************************************/
+2 −2
Original line number Diff line number Diff line
@@ -88,11 +88,11 @@ struct adm_qos_entity {

// TODO: encoder/decoder

struct adm_qos_limit {
typedef struct adm_qos_limit {
    ADM_qos_entity_t l_entity;
    ADM_qos_class_t l_class;
    uint64_t l_value;
};
} adm_qos_limit;

// TODO: encoder/decoder