mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Daniel Schultz <d.schultz@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH v3 5/7] common: state: Add variable type as enum
Date: Fri, 3 Nov 2017 11:48:27 +0100	[thread overview]
Message-ID: <1509706109-41478-5-git-send-email-d.schultz@phytec.de> (raw)
In-Reply-To: <1509706109-41478-1-git-send-email-d.schultz@phytec.de>

The variable_type struct holds a name of its type. Checking the type of
a variable with this string needs much resources.

This patch introduce a enum of the variable type for better type
checking.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
---
Changes:
	v3: New patch.

 common/state/state.h           |  9 +++++++++
 common/state/state_variables.c | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/common/state/state.h b/common/state/state.h
index 7dd163c..fcc6b9f 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -9,6 +9,14 @@ enum state_flags {
 	STATE_FLAG_NO_AUTHENTIFICATION = (1 << 0),
 };
 
+enum state_variable_type {
+	STATE_VARIABLE_TYPE_UINT8,
+	STATE_VARIABLE_TYPE_UINT32,
+	STATE_VARIABLE_TYPE_ENUM32,
+	STATE_VARIABLE_TYPE_MAC,
+	STATE_VARIABLE_TYPE_STRING
+};
+
 /**
  * state_backend_storage_bucket - This class describes a single backend storage
  * object copy
@@ -119,6 +127,7 @@ struct state_variable;
 /* A variable type (uint32, enum32) */
 struct variable_type {
 	const char *type_name;
+	enum state_variable_type type;
 	struct list_head list;
 	int (*export) (struct state_variable *, struct device_node *,
 		       enum state_convert);
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 688467d..de9ba4a 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -450,26 +450,31 @@ static struct state_variable *state_string_create(struct state *state,
 static struct variable_type types[] = {
 	{
 		.type_name = "uint8",
+		.type = STATE_VARIABLE_TYPE_UINT8,
 		.export = state_uint32_export,
 		.import = state_uint32_import,
 		.create = state_uint8_create,
 	}, {
 		.type_name = "uint32",
+		.type = STATE_VARIABLE_TYPE_UINT32,
 		.export = state_uint32_export,
 		.import = state_uint32_import,
 		.create = state_uint32_create,
 	}, {
 		.type_name = "enum32",
+		.type = STATE_VARIABLE_TYPE_ENUM32,
 		.export = state_enum32_export,
 		.import = state_enum32_import,
 		.create = state_enum32_create,
 	}, {
 		.type_name = "mac",
+		.type = STATE_VARIABLE_TYPE_MAC,
 		.export = state_mac_export,
 		.import = state_mac_import,
 		.create = state_mac_create,
 	}, {
 		.type_name = "string",
+		.type = STATE_VARIABLE_TYPE_STRING,
 		.export = state_string_export,
 		.import = state_string_import,
 		.create = state_string_create,
@@ -489,6 +494,19 @@ struct variable_type *state_find_type_by_name(const char *name)
 	return NULL;
 }
 
+struct variable_type *state_find_type(const enum state_variable_type type)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(types); i++) {
+		if (type == types[i].type) {
+			return &types[i];
+		}
+	}
+
+	return NULL;
+}
+
 struct state_variable *state_find_var(struct state *state, const char *name)
 {
 	struct state_variable *sv;
-- 
2.7.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-11-03 10:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03 10:48 [PATCH v3 1/7] ARM: boards: phytec-som-am335x: Add unified MLO Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 2/7] ARM: dts: AM335x: Add state framework Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 3/7] ARM: configs: am335x_defconfig: Add state config Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 4/7] common: state: Add variable_type to state_variable Daniel Schultz
2017-11-03 10:48 ` Daniel Schultz [this message]
2017-11-03 10:48 ` [PATCH v3 6/7] common: state: Add function to read state MAC Daniel Schultz
2017-11-03 10:48 ` [PATCH v3 7/7] ARM: phytec-som-am335x: Set MAC addresses from state Daniel Schultz
2017-11-07  6:47 ` [PATCH v3 1/7] ARM: boards: phytec-som-am335x: Add unified MLO Sascha Hauer

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=1509706109-41478-5-git-send-email-d.schultz@phytec.de \
    --to=d.schultz@phytec.de \
    --cc=barebox@lists.infradead.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