summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVipul Rahane <vipul@runtime.io>2016-04-27 18:28:50 -0700
committerVipul Rahane <vipul@runtime.io>2016-05-17 12:29:40 -0700
commite13bfdce65973bd046f09e5c0765511383637450 (patch)
tree61c10b6dbb14b037cdd4a0ccbb8450a99a59175b /sys
parent426bb1f4f305ab48910007bf92bcfe601ba4d5dd (diff)
Adding Stats List command and LED toggle stats
- Adding Stats List command and LED toggle stats - Making Stats package use stat names - Addinf stats to slinky
Diffstat (limited to 'sys')
-rw-r--r--sys/stats/src/stats_nmgr.c59
1 files changed, 45 insertions, 14 deletions
diff --git a/sys/stats/src/stats_nmgr.c b/sys/stats/src/stats_nmgr.c
index 300b872f..c7b8dff7 100644
--- a/sys/stats/src/stats_nmgr.c
+++ b/sys/stats/src/stats_nmgr.c
@@ -6,7 +6,7 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
@@ -23,30 +23,33 @@
#include <stdio.h>
-#ifdef NEWTMGR_PRESENT
+#ifdef NEWTMGR_PRESENT
-#include "newtmgr/newtmgr.h"
-#include "json/json.h"
+#include "newtmgr/newtmgr.h"
+#include "json/json.h"
#include "stats/stats.h"
/* Source code is only included if the newtmgr library is enabled. Otherwise
* this file is compiled out for code size.
*/
static int stats_nmgr_read(struct nmgr_jbuf *njb);
+static int stats_nmgr_list(struct nmgr_jbuf *njb);
static struct nmgr_group shell_nmgr_group;
-#define STATS_NMGR_ID_READ (0)
+#define STATS_NMGR_ID_READ (0)
+#define STATS_NMGR_ID_LIST (1)
/* ORDER MATTERS HERE.
* Each element represents the command ID, referenced from newtmgr.
*/
static struct nmgr_handler shell_nmgr_group_handlers[] = {
[STATS_NMGR_ID_READ] = {stats_nmgr_read, stats_nmgr_read},
+ [STATS_NMGR_ID_LIST] = {stats_nmgr_list, stats_nmgr_list}
};
-static int
-stats_nmgr_walk_func(struct stats_hdr *hdr, void *arg, char *sname,
+static int
+stats_nmgr_walk_func(struct stats_hdr *hdr, void *arg, char *sname,
uint16_t stat_off)
{
struct json_encoder *encoder;
@@ -62,7 +65,7 @@ stats_nmgr_walk_func(struct stats_hdr *hdr, void *arg, char *sname,
case sizeof(uint16_t):
JSON_VALUE_UINT(&jv, *(uint16_t *) stat_val);
break;
- case sizeof(uint32_t):
+ case sizeof(uint32_t):
JSON_VALUE_UINT(&jv, *(uint32_t *) stat_val);
break;
case sizeof(uint64_t):
@@ -74,20 +77,33 @@ stats_nmgr_walk_func(struct stats_hdr *hdr, void *arg, char *sname,
if (rc != 0) {
goto err;
}
-
+
return (0);
err:
return (rc);
}
-static int
+static int
+stats_nmgr_encode_name(struct stats_hdr *hdr, void *arg)
+{
+ struct json_encoder *encoder;
+ struct json_value jv;
+
+ encoder = (struct json_encoder *)arg;
+ JSON_VALUE_STRING(&jv, hdr->s_name);
+ json_encode_array_value(encoder, &jv);
+
+ return (0);
+}
+
+static int
stats_nmgr_read(struct nmgr_jbuf *njb)
{
struct stats_hdr *hdr;
#define STATS_NMGR_NAME_LEN (32)
char stats_name[STATS_NMGR_NAME_LEN];
struct json_attr_t attrs[] = {
- { "name", t_string, .addr.string = &stats_name[0],
+ { "name", t_string, .addr.string = &stats_name[0],
.len = sizeof(stats_name) },
{ NULL },
};
@@ -126,11 +142,27 @@ err:
return (0);
}
+static int
+stats_nmgr_list(struct nmgr_jbuf *njb)
+{
+ struct json_value jv;
+
+ json_encode_object_start(&njb->njb_enc);
+ JSON_VALUE_INT(&jv, NMGR_ERR_EOK);
+ json_encode_object_entry(&nmgr_task_jbuf.njb_enc, "rc", &jv);
+ json_encode_array_name(&nmgr_task_jbuf.njb_enc, "stat_list");
+ json_encode_array_start(&nmgr_task_jbuf.njb_enc);
+ stats_group_walk(stats_nmgr_encode_name, &nmgr_task_jbuf.njb_enc);
+ json_encode_array_finish(&njb->njb_enc);
+ json_encode_object_finish(&njb->njb_enc);
+
+ return (0);
+}
/**
- * Register nmgr group handlers.
+ * Register nmgr group handlers
*/
-int
+int
stats_nmgr_register_group(void)
{
int rc;
@@ -148,5 +180,4 @@ err:
return (rc);
}
-
#endif /* NEWTMGR_PRESENT */