static int s_init_custom_metric_data()

in source/device_defender.c [579:614]


static int s_init_custom_metric_data(
    struct defender_custom_metric_data *custom_metric_data,
    struct aws_iotdevice_defender_task *defender_task) {
    AWS_PRECONDITION(defender_task != NULL);

    if (custom_metric_data) {
        struct aws_allocator *allocator = defender_task->allocator;
        const size_t custom_metrics_len = defender_task->config.custom_metrics_len;

        for (size_t metric_index = 0; metric_index < custom_metrics_len; ++metric_index) {
            struct defender_custom_metric_data *metric_data = &custom_metric_data[metric_index];
            aws_array_list_get_at(&defender_task->config.custom_metrics, (void **)&metric_data->metric, metric_index);

            struct defender_custom_metric *metric = metric_data->metric;
            switch (metric->type) {
                case DD_METRIC_NUMBER: /* nothing to do here */
                    break;
                case DD_METRIC_NUMBER_LIST:
                    aws_array_list_init_dynamic(
                        &custom_metric_data[metric_index].data.list, allocator, 0, sizeof(int64_t));
                    break;
                case DD_METRIC_STRING_LIST:
                    /* fall through */
                case DD_METRIC_IP_LIST:
                    aws_array_list_init_dynamic(
                        &custom_metric_data[metric_index].data.list, allocator, 0, sizeof(struct aws_string *));
                    break;
                case DD_METRIC_UNKNOWN:
                default:
                    return aws_raise_error(AWS_ERROR_IOTDEVICE_DEFENDER_UNKNOWN_CUSTOM_METRIC_TYPE);
            }
        }
    }

    return AWS_OP_SUCCESS;
}