Soft Patch Panel
 help / color / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 03/10] spp_pcap: revise command response codes
Date: Fri, 31 May 2019 17:52:35 +0900
Message-ID: <1559292762-27042-4-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1559292762-27042-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

This update is to revise the name of enum of response codes,
structs and variables for refactoring.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/pcap/cmd_runner.c                         | 58 +++++++++----------
 .../secondary/spp_worker_th/cmd_runner.c      |  2 +-
 2 files changed, 27 insertions(+), 33 deletions(-)

diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c
index 9e4f4cf..9d63bde 100644
--- a/src/pcap/cmd_runner.c
+++ b/src/pcap/cmd_runner.c
@@ -29,31 +29,25 @@
 #define JSON_APPEND_BLOCK         "%s\"%s\": { %s }"
 #define JSON_APPEND_BLOCK_NONAME  "%s%s{ %s }"
 
-/* command execution result type */
-enum command_result_type {
+/* TODO(yasufum) merge it to the same definition in shared/.../cmd_runner.c */
+enum cmd_res_code {
 	CMD_SUCCESS = 0,
 	CMD_FAILURE,
 	CMD_INVALID,
 };
 
 /* command execution result information */
-struct command_result {
-	/* Response code */
-	int code;
-
-	/* Response message */
-	char msg[SPPWK_NAME_BUFSZ];
-
-	/* Detailed response message */
-	char error_message[CMD_RES_ERR_MSG_SIZE];
+/* TODO(yasufum) merge it to the same definition in shared/.../cmd_runner.c */
+struct cmd_result {
+	int code;  /* Response code */
+	char msg[SPPWK_NAME_BUFSZ];  /* Response msg in short. */
+	char err_msg[CMD_RES_ERR_MSG_SIZE];  /* Used only if cmd is failed. */
 };
 
 /* command response list control structure */
-struct command_response_list {
-	/* JSON Tag name */
-	char tag_name[SPPWK_NAME_BUFSZ];
-
-	/* Pointer to handling function */
+/* TODO(yasufum) merge it to the same definition in shared/.../cmd_runner.c */
+struct cmd_response {
+	char tag_name[SPPWK_NAME_BUFSZ];  /* JSON Tag name */
 	int (*func)(const char *name, char **output, void *tmp);
 };
 
@@ -296,30 +290,30 @@ parse_error_message(
 
 /* set the command result */
 static inline void
-set_command_results(struct command_result *result,
+set_command_results(struct cmd_result *result,
 		int code, const char *error_messege)
 {
 	result->code = code;
 	switch (code) {
 	case CMD_SUCCESS:
 		strcpy(result->msg, "success");
-		memset(result->error_message, 0x00, CMD_RES_ERR_MSG_SIZE);
+		memset(result->err_msg, 0x00, CMD_RES_ERR_MSG_SIZE);
 		break;
 	case CMD_FAILURE:
 		strcpy(result->msg, "error");
-		strcpy(result->error_message, error_messege);
+		strcpy(result->err_msg, error_messege);
 		break;
 	case CMD_INVALID: /* FALLTHROUGH */
 	default:
 		strcpy(result->msg, "invalid");
-		memset(result->error_message, 0x00, CMD_RES_ERR_MSG_SIZE);
+		memset(result->err_msg, 0x00, CMD_RES_ERR_MSG_SIZE);
 		break;
 	}
 }
 
 /* set parse error to command result */
 static void
-set_parse_error_to_results(struct command_result *results,
+set_parse_error_to_results(struct cmd_result *results,
 		const struct spp_command_request *request,
 		const struct sppwk_parse_err_msg *wk_err_msg)
 {
@@ -345,7 +339,7 @@ set_parse_error_to_results(struct command_result *results,
 static int
 append_result_value(const char *name, char **output, void *tmp)
 {
-	const struct command_result *result = tmp;
+	const struct cmd_result *result = tmp;
 	return append_json_str_value(name, output, result->msg);
 }
 
@@ -354,10 +348,10 @@ static int
 append_error_details_value(const char *name, char **output, void *tmp)
 {
 	int ret = SPPWK_RET_NG;
-	const struct command_result *result = tmp;
+	const struct cmd_result *result = tmp;
 	char *tmp_buff;
 	/* string is empty, except for errors */
-	if (result->error_message[0] == '\0')
+	if (result->err_msg[0] == '\0')
 		return SPPWK_RET_OK;
 
 	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
@@ -369,7 +363,7 @@ append_error_details_value(const char *name, char **output, void *tmp)
 	}
 
 	ret = append_json_str_value("message", &tmp_buff,
-			result->error_message);
+			result->err_msg);
 	if (unlikely(ret < 0)) {
 		spp_strbuf_free(tmp_buff);
 		return SPPWK_RET_NG;
@@ -553,7 +547,7 @@ append_core_value(const char *name, char **output,
 /* append string of command response list for JSON format */
 static int
 append_response_list_value(char **output,
-		struct command_response_list *list,
+		struct cmd_response *list,
 		void *tmp)
 {
 	int ret = SPPWK_RET_NG;
@@ -612,14 +606,14 @@ append_response_list_value(char **output,
 #define COMMAND_RESP_TAG_LIST_EMPTY { "", NULL }
 
 /* command response result string list */
-struct command_response_list response_result_list[] = {
+struct cmd_response response_result_list[] = {
 	{ "result",        append_result_value },
 	{ "error_details", append_error_details_value },
 	COMMAND_RESP_TAG_LIST_EMPTY
 };
 
 /* command response status information string list */
-struct command_response_list response_info_list[] = {
+struct cmd_response response_info_list[] = {
 	{ "client-id",        append_client_id_value },
 	{ "status",           append_capture_status_value },
 	{ "master-lcore",     append_master_lcore_value },
@@ -630,7 +624,7 @@ struct command_response_list response_info_list[] = {
 /* append a list of command results for JSON format. */
 static int
 append_command_results_value(const char *name, char **output,
-		int num, struct command_result *results)
+		int num, struct cmd_result *results)
 {
 	int ret = SPPWK_RET_NG;
 	int i;
@@ -706,7 +700,7 @@ append_info_value(const char *name, char **output)
 static void
 send_parse_error_response(int *sock,
 		const struct spp_command_request *request,
-		struct command_result *command_results)
+		struct cmd_result *command_results)
 {
 	int ret = SPPWK_RET_NG;
 	char *msg, *tmp_buff;
@@ -762,7 +756,7 @@ send_parse_error_response(int *sock,
 static void
 send_command_result_response(int *sock,
 		const struct spp_command_request *request,
-		struct command_result *command_results)
+		struct cmd_result *command_results)
 {
 	int ret = SPPWK_RET_NG;
 	char *msg, *tmp_buff;
@@ -863,7 +857,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len)
 
 	struct spp_command_request request;
 	struct sppwk_parse_err_msg parse_error;
-	struct command_result command_results[SPPWK_MAX_CMDS];
+	struct cmd_result command_results[SPPWK_MAX_CMDS];
 
 	memset(&request, 0, sizeof(struct spp_command_request));
 	memset(&parse_error, 0, sizeof(struct sppwk_parse_err_msg));
diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c
index 8672a25..ba3fdc6 100644
--- a/src/shared/secondary/spp_worker_th/cmd_runner.c
+++ b/src/shared/secondary/spp_worker_th/cmd_runner.c
@@ -34,7 +34,7 @@
 #define JSON_APPEND_BLOCK         "%s\"%s\": { %s }"
 #define JSON_APPEND_BLOCK_NONAME  "%s%s{ %s }"
 
-enum cmd_res_codes {
+enum cmd_res_code {
 	CMD_SUCCESS = 0,
 	CMD_FAILED,
 	CMD_INVALID,
-- 
2.17.1


  parent reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31  8:52 [spp] [PATCH 00/10] Refactor cmd parser in spp_pcap ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 01/10] spp_pcap: rename enum spp_command_type ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 02/10] spp_pcap: rename struct spp_command ogawa.yasufumi
2019-05-31  8:52 ` ogawa.yasufumi [this message]
2019-05-31  8:52 ` [spp] [PATCH 04/10] spp_pcap: revise parser functions ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 05/10] spp_pcap: refactor func for splitting cmd tokens ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 06/10] spp_pcap: revise log msgs in parser func ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 07/10] spp_pcap: remove unused string list ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 08/10] spp_pcap: refactor comments of spp_pcap ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 09/10] spp_pcap: rename spp_get_core_status ogawa.yasufumi
2019-05-31  8:52 ` [spp] [PATCH 10/10] spp_pcap: revise name of vars for parser error ogawa.yasufumi

Reply instructions:

You may reply publically 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=1559292762-27042-4-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --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

Soft Patch Panel

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ http://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/ public-inbox