summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPawel Szewczyk <p.szewczyk@samsung.com>2015-07-06 14:12:06 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-08-19 14:29:49 +0200
commit2817eb2390cd9557c5677b04ad905734d7b480ec (patch)
treef25b4f2fea1db75ce4cd2fc94e65099a0caa3ead /src
parent514cfb156a6447a16ce668d00e66f1beee9da753 (diff)
downloadlibusbg-2817eb2390cd9557c5677b04ad905734d7b480ec.tar.gz
libusbg-2817eb2390cd9557c5677b04ad905734d7b480ec.tar.bz2
libusbg-2817eb2390cd9557c5677b04ad905734d7b480ec.zip
libusbg: Add enum for gadget strings
This commit provides functionality for gadget strings similar to existing gadget attributes api. It allows to iterate over gadget strings and to write cleaner and more flexible code. Signed-off-by: Pawel Szewczyk <p.szewczyk@samsung.com> Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/usbg.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/usbg.c b/src/usbg.c
index 0ae82ec..cc6a73a 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -70,6 +70,15 @@ const char *gadget_attr_names[] =
ARRAY_SIZE_SENTINEL(gadget_attr_names, USBG_GADGET_ATTR_MAX);
+const char *gadget_str_names[] =
+{
+ "product",
+ "manufacturer",
+ "serialnumber",
+};
+
+ARRAY_SIZE_SENTINEL(gadget_str_names, USBG_GADGET_STR_MAX);
+
int usbg_translate_error(int error)
{
int ret;
@@ -311,6 +320,22 @@ int usbg_lookup_gadget_attr(const char *name)
return USBG_ERROR_NOT_FOUND;
}
+int usbg_lookup_gadget_str(const char *name)
+{
+ int i = USBG_GADGET_STR_MIN;
+
+ if (!name)
+ return USBG_ERROR_INVALID_PARAM;
+
+ do {
+ if (!strcmp(name, gadget_str_names[i]))
+ return i;
+ i++;
+ } while (i != USBG_GADGET_STR_MAX);
+
+ return USBG_ERROR_NOT_FOUND;
+}
+
const char *usbg_get_gadget_attr_str(usbg_gadget_attr attr)
{
return attr >= USBG_GADGET_ATTR_MIN &&
@@ -318,6 +343,13 @@ const char *usbg_get_gadget_attr_str(usbg_gadget_attr attr)
gadget_attr_names[attr] : NULL;
}
+const char *usbg_get_gadget_str_name(usbg_gadget_str str)
+{
+ return str >= USBG_GADGET_STR_MIN &&
+ str < USBG_GADGET_STR_MAX ?
+ gadget_str_names[str] : NULL;
+}
+
static usbg_error usbg_split_function_instance_type(const char *full_name,
usbg_function_type *f_type, const char **instance)
{
@@ -2401,6 +2433,38 @@ static int usbg_check_dir(const char *path)
return ret;
}
+int usbg_set_gadget_str(usbg_gadget *g, usbg_gadget_str str, int lang,
+ const char *val)
+{
+ const char *str_name;
+ int ret = USBG_ERROR_INVALID_PARAM;
+ char path[USBG_MAX_PATH_LENGTH];
+ int nmb;
+
+ if (!g)
+ goto out;
+
+ str_name = usbg_get_gadget_str_name(str);
+ if (!str_name)
+ goto out;
+
+ nmb = snprintf(path, sizeof(path), "%s/%s/%s/0x%x", g->path, g->name,
+ STRINGS_DIR, lang);
+ if (nmb >= sizeof(path)) {
+ ret = USBG_ERROR_PATH_TOO_LONG;
+ goto out;
+ }
+
+ ret = usbg_check_dir(path);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ ret = usbg_write_string(path, "", str_name, val);
+
+out:
+ return ret;
+}
+
int usbg_set_gadget_strs(usbg_gadget *g, int lang,
const usbg_gadget_strs *g_strs)
{