[PATCH 19/25] libusbg: Add getter for binding name and target.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add usbg_get_binding_target() to avoid direct binding
structure members access. Add also usbg_get_binding_name_len()
and usbg_get_binding_name() to allow getting binding name.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 include/usbg/usbg.h |   23 +++++++++++++++++++++++
 src/usbg.c          |   15 +++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 8dad4fa..4955acc 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -562,6 +562,29 @@ extern void usbg_set_config_string(struct config *c, int lang, char *string);
  */
 extern int usbg_add_config_function(struct config *c, char *name, struct function *f);
 
+/**
+ * @brief Get target function of given binding
+ * @param b Binding between configuration and function
+ * @return Pointer to USB function which is target for this binding
+ */
+extern struct function *usbg_get_binding_target(struct binding *b);
+
+/**
+ * @brief Get binding name length
+ * @param b Binding which name length should be returned
+ * @return Length of name string or -1 if error occurred.
+ */
+extern size_t usbg_get_binding_name_len(struct binding *b);
+
+/**
+ * @brief Get binding name
+ * @param b Pointer to binding
+ * @param buf Buffer where name should be copied
+ * @param len Length of given buffer
+ * @return Pointer to destination or NULL if error occurred.
+ */
+extern char *usbg_get_binding_name(struct binding *b, char *buf, size_t len);
+
 /* USB gadget setup and teardown */
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 5fb3c3a..1ce9db7 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1083,6 +1083,21 @@ int usbg_add_config_function(struct config *c, char *name, struct function *f)
 	return 0;
 }
 
+struct function *usbg_get_binding_target(struct binding* b)
+{
+	return b ? b->target : NULL;
+}
+
+size_t usbg_get_binding_name_len(struct binding *b)
+{
+	return b ? strlen(b->name) : -1;
+}
+
+char *usbg_get_binding_name(struct binding* b, char *buf, size_t len)
+{
+	return b ? strncpy(buf,b->name, len): NULL;
+}
+
 int usbg_get_udcs(struct dirent ***udc_list)
 {
 	return scandir("/sys/class/udc", udc_list, file_select, alphasort);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux