Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 13/13] shared/sec: refactor comments for JSON formatter
Date: Mon, 24 Jun 2019 13:36:13 +0900	[thread overview]
Message-ID: <20190624043613.19271-14-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190624043613.19271-1-yasufum.o@gmail.com>

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to refactor comments for JSON formatter.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 .../spp_worker_th/cmd_res_formatter.c         | 68 ++++++++++++-------
 1 file changed, 43 insertions(+), 25 deletions(-)

diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
index 24b5608..21024b9 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -88,7 +88,7 @@ struct cmd_response response_info_list[] = {
 	{ "", NULL }
 };
 
-/* append a command result for JSON format */
+/* Append a command result in JSON format. */
 static int
 append_result_value(const char *name, char **output, void *tmp)
 {
@@ -96,7 +96,7 @@ append_result_value(const char *name, char **output, void *tmp)
 	return append_json_str_value(output, name, result->result);
 }
 
-/* append error details for JSON format */
+/* Append error details in JSON format. */
 static int
 append_error_details_value(const char *name, char **output, void *tmp)
 {
@@ -110,9 +110,7 @@ append_error_details_value(const char *name, char **output, void *tmp)
 	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
 	if (unlikely(tmp_buff == NULL)) {
 		RTE_LOG(ERR, WK_CMD_RES_FMT,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
-				name);
+				"Fail to alloc buf for `%s`.\n", name);
 		return SPP_RET_NG;
 	}
 
@@ -135,7 +133,7 @@ is_port_flushed(enum port_type iface_type, int iface_no)
 	return port->ethdev_port_id >= 0;
 }
 
-/* append a list of interface numbers */
+/* Append index number as comma separated format such as `0, 1, ...`. */
 int
 append_interface_array(char **output, const enum port_type type)
 {
@@ -151,14 +149,12 @@ append_interface_array(char **output, const enum port_type type)
 		*output = spp_strbuf_append(*output, tmp_str, strlen(tmp_str));
 		if (unlikely(*output == NULL)) {
 			RTE_LOG(ERR, WK_CMD_RES_FMT,
-					"Interface number failed to add. "
-					"(type = %d)\n", type);
+				/* TODO(yasufum) replace %d to string. */
+				"Failed to add index for type `%d`.\n", type);
 			return SPP_RET_NG;
 		}
-
 		port_cnt++;
 	}
-
 	return SPP_RET_OK;
 }
 
@@ -519,7 +515,10 @@ append_response_list_value(char **output, struct cmd_response *responses,
 	return SPP_RET_OK;
 }
 
-/* append a list of command results for JSON format. */
+/**
+ * Setup `results` section in JSON msg. This is an example.
+ *   "results": [ { "result": "success" } ]
+ */
 int
 append_command_results_value(const char *name, char **output,
 		int num, struct cmd_result *results)
@@ -527,27 +526,26 @@ append_command_results_value(const char *name, char **output,
 	int ret = SPP_RET_NG;
 	int i;
 	char *tmp_buff1, *tmp_buff2;
+
+	/* Setup result statement step by step with two buffers. */
 	tmp_buff1 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
 	if (unlikely(tmp_buff1 == NULL)) {
 		RTE_LOG(ERR, WK_CMD_RES_FMT,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s, buff=1)\n",
-				name);
+				"Faield to alloc 1st buf for `%s`.\n", name);
 		return SPP_RET_NG;
 	}
-
 	tmp_buff2 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
 	if (unlikely(tmp_buff2 == NULL)) {
 		spp_strbuf_free(tmp_buff1);
 		RTE_LOG(ERR, WK_CMD_RES_FMT,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s, buff=2)\n",
-				name);
+				"Faield to alloc 2nd buf for `%s`.\n", name);
 		return SPP_RET_NG;
 	}
 
 	for (i = 0; i < num; i++) {
 		tmp_buff1[0] = '\0';
+
+		/* Setup key-val pair such as `"result": "success"` */
 		ret = append_response_list_value(&tmp_buff1,
 				response_result_list, &results[i]);
 		if (unlikely(ret < 0)) {
@@ -556,22 +554,41 @@ append_command_results_value(const char *name, char **output,
 			return SPP_RET_NG;
 		}
 
+		/* Surround key-val pair such as `{ "result": "success" }`. */
 		ret = append_json_block_brackets(&tmp_buff2, "", tmp_buff1);
 		if (unlikely(ret < 0)) {
 			spp_strbuf_free(tmp_buff1);
 			spp_strbuf_free(tmp_buff2);
 			return SPP_RET_NG;
 		}
-
 	}
 
+	/**
+	 * Setup result statement such as
+	 * `"results": [ { "result": "success" } ]`.
+	 */
 	ret = append_json_array_brackets(output, name, tmp_buff2);
+
 	spp_strbuf_free(tmp_buff1);
 	spp_strbuf_free(tmp_buff2);
 	return ret;
 }
 
-/* append a list of status information for JSON format. */
+/**
+ * Setup response of `status` command.
+ *
+ * This is an example of the response.
+ *   "results": [ { "result": "success" } ],
+ *   "info": {
+ *       "client-id": 2,
+ *       "phy": [ 0, 1 ], "vhost": [  ], "ring": [  ],
+ *       "master-lcore": 1,
+ *       "core": [
+ *           {"core": 2, "type": "unuse"}, {"core": 3, "type": "unuse"}, ...
+ *       ],
+ *       "classifier_table": [  ]
+ *   }
+ */
 int
 append_info_value(const char *name, char **output)
 {
@@ -579,19 +596,19 @@ append_info_value(const char *name, char **output)
 	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
 	if (unlikely(tmp_buff == NULL)) {
 		RTE_LOG(ERR, WK_CMD_RES_FMT,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
+				"Failed to get empty buf for append `%s`.\n",
 				name);
 		return SPP_RET_NG;
 	}
 
-	ret = append_response_list_value(&tmp_buff,
-			response_info_list, NULL);
+	/* Setup JSON msg in value of `info` key. */
+	ret = append_response_list_value(&tmp_buff, response_info_list, NULL);
 	if (unlikely(ret < SPP_RET_OK)) {
 		spp_strbuf_free(tmp_buff);
 		return SPP_RET_NG;
 	}
 
+	/* Setup response of JSON msg. */
 	ret = append_json_block_brackets(output, name, tmp_buff);
 	spp_strbuf_free(tmp_buff);
 	return ret;
@@ -674,7 +691,8 @@ wk_get_client_id(void)
  * of struct `cmd_response` which are for making each of parts of command
  * response.
  */
-/* Add entry of client ID to a response in JSON. */
+
+/* Add entry of client ID such as `"client-id": 1` to a response in JSON. */
 int
 add_client_id(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
-- 
2.17.1


      parent reply	other threads:[~2019-06-24  4:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24  4:36 [spp] [PATCH 00/13] Move JSON utils from libs for running cmds yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 01/13] shared/sec: rename ops for setup cmd response yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 02/13] shared/sec: rename functions for spp_mirror yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 03/13] shared/sec: move principle JSON formatter funcs yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 04/13] shared/sec: change order of args of JSON fmtters yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 05/13] shared/sec: move JSON formatter to shard/secondary yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 06/13] shared/sec: revise including headers yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 07/13] shared/sec: move JSON formatters from cmd_runner yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 08/13] shared/sec: move rest of JSON formatters yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 09/13] shared/sec: move lcore funcs in response_info_list yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 10/13] shared/sec: move ope cli-id " yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 11/13] shared/sec: move rest of ops " yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 12/13] shared/sec: remove local funcs from header yasufum.o
2019-06-24  4:36 ` yasufum.o [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190624043613.19271-14-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).