int s_copy_task_config()

in source/device_defender.c [995:1032]


int s_copy_task_config(
    struct aws_iotdevice_defender_task_config *dest_config,
    const struct aws_iotdevice_defender_task_config *src_config) {
    AWS_PRECONDITION(dest_config != NULL);
    AWS_PRECONDITION(src_config != NULL);

    struct aws_allocator *allocator = src_config->allocator;
    dest_config->allocator = src_config->allocator;
    dest_config->custom_metrics_len = src_config->custom_metrics_len;
    dest_config->thing_name = aws_string_new_from_string(src_config->allocator, src_config->thing_name);

    dest_config->callback_userdata = src_config->callback_userdata;
    dest_config->task_canceled_fn = src_config->task_canceled_fn;
    dest_config->accepted_report_fn = src_config->accepted_report_fn;
    dest_config->rejected_report_fn = src_config->rejected_report_fn;
    dest_config->task_period_ns = src_config->task_period_ns;

    if (AWS_OP_SUCCESS != aws_array_list_init_dynamic(
                              &dest_config->custom_metrics,
                              dest_config->allocator,
                              dest_config->custom_metrics_len,
                              sizeof(struct defender_custom_metric *))) {
        return AWS_OP_ERR;
    }

    for (size_t metric_index = 0; metric_index < dest_config->custom_metrics_len; ++metric_index) {
        struct defender_custom_metric *metric_dest =
            aws_mem_calloc(allocator, 1, sizeof(struct defender_custom_metric));
        struct defender_custom_metric *metric_src = NULL;
        aws_array_list_get_at(&src_config->custom_metrics, (void **)&metric_src, metric_index);
        metric_dest->metric_name = aws_string_new_from_string(allocator, metric_src->metric_name);
        metric_dest->metric_cb_userdata = metric_src->metric_cb_userdata;
        metric_dest->type = metric_src->type;
        metric_dest->supplier_fn = metric_src->supplier_fn;
        aws_array_list_push_back(&dest_config->custom_metrics, &metric_dest);
    }
    return AWS_OP_SUCCESS;
}