From 7dc8e88d64716831a1553d402571fb7b1ade3d30 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 24 Nov 2017 13:53:33 +0100 Subject: ctrl: make response easier to parse Previously ctrl request for all counters in group (e. g. 'rate_ctr.abs.msc.0') will result in human-readable description which is not regular enough and is hard to both parse and generate. The ctrl interface is intended for m2m, not for human interaction. Let's simplify things by making response similar to counter group request ('rate_ctr.*'). Reply now looks as follows: GET_REPLY 9084354783926137287 rate_ctr.abs.msc.0 loc_update_type:attach 0;loc_update_type:normal 0; Previously it was: GET_REPLY 9084354783926137287 rate_ctr.abs.msc.0 All counters in msc.0 loc_update_type:attach 0 loc_update_type:normal 0 Change-Id: I7a24cc307450efdcd28168fffe477320c59fcd36 Related: OS#2550 --- src/ctrl/control_if.c | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) (limited to 'src/ctrl') diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c index 38e7aef4..015c55e9 100644 --- a/src/ctrl/control_if.c +++ b/src/ctrl/control_if.c @@ -499,42 +499,19 @@ static uint64_t get_rate_ctr_value(const struct rate_ctr *ctr, int intv, const c } } -static char *get_all_rate_ctr_in_group(void *ctx, const struct rate_ctr_group *ctrg, int intv) -{ - int i; - char *counters = talloc_strdup(ctx, ""); - if (!counters) - return NULL; - - for (i=0;idesc->num_ctr;i++) { - counters = talloc_asprintf_append(counters, "\n%s.%u.%s %"PRIu64, - ctrg->desc->group_name_prefix, ctrg->idx, - ctrg->desc->ctr_desc[i].name, - get_rate_ctr_value(&ctrg->ctr[i], intv, ctrg->desc->group_name_prefix)); - if (!counters) - return NULL; - } - return counters; -} - static int get_rate_ctr_group_idx(const struct rate_ctr_group *ctrg, int intv, struct ctrl_cmd *cmd) { - char *counters; - - counters = get_all_rate_ctr_in_group(cmd, ctrg, intv); - if (!counters) - goto oom; - - cmd->reply = talloc_asprintf(cmd, "All counters in %s.%u%s", - ctrg->desc->group_name_prefix, ctrg->idx, counters); - talloc_free(counters); - if (!cmd->reply) - goto oom; + unsigned int i; + for (i = 0; i < ctrg->desc->num_ctr; i++) { + ctrl_cmd_reply_printf(cmd, "%s %"PRIu64";", ctrg->desc->ctr_desc[i].name, + get_rate_ctr_value(&ctrg->ctr[i], intv, ctrg->desc->group_name_prefix)); + if (!cmd->reply) { + cmd->reply = "OOM"; + return CTRL_CMD_ERROR; + } + } return CTRL_CMD_REPLY; -oom: - cmd->reply = "OOM."; - return CTRL_CMD_ERROR; } static int ctrl_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *data) -- cgit v1.2.3