in source/device_defender.c [1232:1264]
int aws_iotdevice_defender_config_register_number_metric(
struct aws_iotdevice_defender_task_config *task_config,
const struct aws_byte_cursor *metric_name,
aws_iotdevice_defender_get_number_fn *supplier,
void *userdata) {
AWS_PRECONDITION(task_config != NULL);
AWS_PRECONDITION(metric_name != NULL);
AWS_PRECONDITION(supplier != NULL);
struct aws_allocator *allocator = task_config->allocator;
struct defender_custom_metric *custom_metric = aws_mem_calloc(allocator, 1, sizeof(struct defender_custom_metric));
if (custom_metric) {
custom_metric->type = DD_METRIC_NUMBER;
custom_metric->metric_name = aws_string_new_from_cursor(allocator, metric_name);
custom_metric->supplier_fn.get_number_fn = supplier;
custom_metric->metric_cb_userdata = userdata;
if (AWS_OP_SUCCESS != aws_array_list_push_back(&task_config->custom_metrics, &custom_metric)) {
AWS_LOGF_ERROR(
AWS_LS_IOTDEVICE_DEFENDER_TASK,
"id=%p: Failed to add number custom metric " PRInSTR,
(void *)task_config,
AWS_BYTE_CURSOR_PRI(*metric_name)); /* wrong subject */
aws_string_destroy(custom_metric->metric_name);
aws_mem_release(allocator, custom_metric);
return AWS_OP_ERR;
}
task_config->custom_metrics_len++;
return AWS_OP_SUCCESS;
}
return AWS_OP_ERR;
}