summaryrefslogtreecommitdiffstats
path: root/src/ctrl
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-11-24 13:53:33 +0100
committerHarald Welte <laforge@gnumonks.org>2017-11-27 16:44:25 +0000
commit7dc8e88d64716831a1553d402571fb7b1ade3d30 (patch)
treeb42c178226d738843a52445ec74f1233f7b5ce3f /src/ctrl
parent19ec7b948322bbc9457a2b22219c93558a6f931e (diff)
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
Diffstat (limited to 'src/ctrl')
-rw-r--r--src/ctrl/control_if.c41
1 files changed, 9 insertions, 32 deletions
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;i<ctrg->desc->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)