[PATCH v2 25/26] libusbg: Rename all public structures to usbg convention.

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

 



Switch form struct * to typedef usbg_* to provide convenient
API for user.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 examples/show-gadgets.c |   10 ++---
 include/usbg/usbg.h     |  100 +++++++++++++++++++++++------------------------
 src/usbg.c              |   58 +++++++++++++--------------
 3 files changed, 84 insertions(+), 84 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 3f72a96..9814039 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -30,8 +30,8 @@
 void show_gadget(usbg_gadget *g)
 {
 	char buf[USBG_MAX_STR_LENGTH];
-	struct gadget_attrs g_attrs;
-	struct gadget_strs g_strs;
+	usbg_gadget_attrs g_attrs;
+	usbg_gadget_strs g_strs;
 
 	usbg_get_gadget_name(g, buf, USBG_MAX_STR_LENGTH);
 	usbg_get_gadget_attrs(g, &g_attrs);
@@ -60,7 +60,7 @@ void show_gadget(usbg_gadget *g)
 void show_function(usbg_function *f)
 {
 	char buf[USBG_MAX_STR_LENGTH];
-	union attrs f_attrs;
+	usbg_function_attrs f_attrs;
 
 	usbg_get_function_name(f, buf, USBG_MAX_STR_LENGTH);
 	usbg_get_function_attrs(f, &f_attrs);
@@ -98,8 +98,8 @@ void show_config(usbg_config *c)
 	usbg_binding *b;
 	usbg_function *f;
 	char buf[USBG_MAX_STR_LENGTH], buf2[USBG_MAX_STR_LENGTH];
-	struct config_attrs c_attrs;
-	struct config_strs c_strs;
+	usbg_config_attrs c_attrs;
+	usbg_config_strs c_strs;
 
 	usbg_get_config_name(c, buf, USBG_MAX_STR_LENGTH);
 	fprintf(stdout, "  Configuration '%s'\n", buf);
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 1698312..71845cd 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -76,10 +76,10 @@ typedef struct usbg_function usbg_function;
 typedef struct usbg_binding usbg_binding;
 
 /**
- * @struct gadget_attrs
+ * @typedef usbg_gadget_attrs
  * @brief USB gadget device attributes
  */
-struct gadget_attrs
+typedef struct
 {
 	uint16_t bcdUSB;
 	uint8_t bDeviceClass;
@@ -89,43 +89,43 @@ struct gadget_attrs
 	uint16_t idVendor;
 	uint16_t idProduct;
 	uint16_t bcdDevice;
-};
+} usbg_gadget_attrs;
 
 /**
- * @struct gadget_strs
+ * @typedef usbg_gadget_strs
  * @brief USB gadget device strings
  */
-struct gadget_strs
+typedef struct
 {
 	char str_ser[USBG_MAX_STR_LENGTH];
 	char str_mnf[USBG_MAX_STR_LENGTH];
 	char str_prd[USBG_MAX_STR_LENGTH];
-};
+} usbg_gadget_strs;
 
 /**
- * @struct config_attrs
+ * @typedef usbg_config_attrs
  * @brief USB configuration attributes
  */
-struct config_attrs
+typedef struct
 {
 	uint8_t bmAttributes;
 	uint8_t bMaxPower;
-};
+} usbg_config_attrs;
 
 /**
- * @struct config_strs
+ * @typedef usbg_config_strs
  * @brief USB configuration strings
  */
-struct config_strs
+typedef struct
 {
 	char configuration[USBG_MAX_STR_LENGTH];
-};
+} usbg_config_strs;
 
 /**
- * @enum function_type
+ * @typedef usbg_function_type
  * @brief Supported USB function types
  */
-enum function_type
+typedef enum
 {
 	F_SERIAL,
 	F_ACM,
@@ -136,44 +136,44 @@ enum function_type
 	F_EEM,
 	F_RNDIS,
 	F_PHONET,
-};
+} usbg_function_type;
 
 /**
- * @struct serial_attrs
+ * @typedef usbg_f_serial_attrs
  * @brief Attributes for Serial, ACM, and OBEX USB functions
  */
-struct serial_attrs {
+typedef struct {
 	int port_num;
-};
+} usbg_f_serial_attrs;
 
 /**
- * @struct net_attrs
+ * @typedef net_attrs
  * @brief Attributes for ECM, ECM subset, NCM, EEM, and RNDIS USB functions
  */
-struct net_attrs {
+typedef struct {
 	struct ether_addr dev_addr;
 	struct ether_addr host_addr;
 	char ifname[USBG_MAX_STR_LENGTH];
 	int qmult;
-};
+} usbg_f_net_attrs;
 
 /**
- * @struct phonet_attrs
+ * @typedef usbg_f_phonet_attrs
  * @brief Attributes for the phonet USB function
  */
-struct phonet_attrs {
+typedef struct {
 	char ifname[USBG_MAX_STR_LENGTH];
-};
+} usbg_f_phonet_attrs;
 
 /**
- * @union attrs
+ * @typedef attrs
  * @brief Attributes for a given function type
  */
-union attrs {
-	struct serial_attrs serial;
-	struct net_attrs net;
-	struct phonet_attrs phonet;
-};
+typedef union {
+	usbg_f_serial_attrs serial;
+	usbg_f_net_attrs net;
+	usbg_f_phonet_attrs phonet;
+} usbg_function_attrs;
 
 /* Library init and cleanup */
 
@@ -256,7 +256,7 @@ extern usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name,
  * @return Pointer to gadget or NULL if the gadget cannot be created
  */
 extern usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
-		struct gadget_attrs *g_attrs, struct gadget_strs *g_strs);
+		usbg_gadget_attrs *g_attrs, usbg_gadget_strs *g_strs);
 
 /**
  * @brief Set the USB gadget attributes
@@ -264,7 +264,7 @@ extern usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
  * @param g_attrs Gadget attributes
  */
 extern void usbg_set_gadget_attrs(usbg_gadget *g,
-		struct gadget_attrs *g_attrs);
+		usbg_gadget_attrs *g_attrs);
 
 /**
  * @brief Get the USB gadget strings
@@ -272,8 +272,8 @@ extern void usbg_set_gadget_attrs(usbg_gadget *g,
  * @param g_attrs Structure to be filled
  * @retur Pointer to filled structure or NULL if error occurred.
  */
-extern struct gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-		struct gadget_attrs *g_attrs);
+extern usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
+		usbg_gadget_attrs *g_attrs);
 
 /**
  * @brief Get gadget name length
@@ -358,8 +358,8 @@ extern void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
  * @param g_sttrs Structure to be filled
  * @retur Pointer to filled structure or NULL if error occurred.
  */
-extern struct gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
-		struct gadget_strs *g_strs);
+extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
+		usbg_gadget_strs *g_strs);
 
 /**
  * @brief Set the USB gadget strings
@@ -368,7 +368,7 @@ extern struct gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
  * @param g_sttrs Gadget attributes
  */
 extern void usbg_set_gadget_strs(usbg_gadget *g, int lang,
-		struct gadget_strs *g_strs);
+		usbg_gadget_strs *g_strs);
 
 /**
  * @brief Set the serial number for a gadget
@@ -404,8 +404,8 @@ extern void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
  * @param f_attrs Function attributes to be set. If NULL setting is omitted.
  * @return Pointer to function or NULL if it cannot be created
  */
-extern usbg_function *usbg_create_function(usbg_gadget *g, enum function_type type,
-		char *instance, union attrs *f_attrs);
+extern usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type type,
+		char *instance, usbg_function_attrs *f_attrs);
 
 /**
  * @brief Get function name length
@@ -434,7 +434,7 @@ extern char *usbg_get_function_name(usbg_function *f, char *buf, size_t len);
  * @return Pointer to configuration or NULL if it cannot be created
  */
 extern usbg_config *usbg_create_config(usbg_gadget *g, char *name,
-		struct config_attrs *c_attrs, struct config_strs *c_strs);
+		usbg_config_attrs *c_attrs, usbg_config_strs *c_strs);
 
 /**
  * @brief Get config name length
@@ -458,7 +458,7 @@ extern char *usbg_get_config_name(usbg_config *c, char *buf, size_t len);
  * @param c_attrs Configuration attributes
  */
 extern void usbg_set_config_attrs(usbg_config *c,
-		struct config_attrs *c_attrs);
+		usbg_config_attrs *c_attrs);
 
 /**
  * @brief Get the USB configuration strings
@@ -466,8 +466,8 @@ extern void usbg_set_config_attrs(usbg_config *c,
  * @param c_attrs Structure to be filled
  * @retur Pointer to filled structure or NULL if error occurred.
  */
-extern struct config_attrs *usbg_get_config_attrs(usbg_config *c,
-		struct config_attrs *c_attrs);
+extern usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
+		usbg_config_attrs *c_attrs);
 
 /**
  * @brief Set the configuration maximum power
@@ -489,8 +489,8 @@ extern void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
  * @param c_sttrs Structure to be filled
  * @retur Pointer to filled structure or NULL if error occurred.
  */
-extern struct config_strs *usbg_get_config_strs(usbg_config *c,
-		struct config_strs *c_strs);
+extern usbg_config_strs *usbg_get_config_strs(usbg_config *c,
+		usbg_config_strs *c_strs);
 
 /**
  * @brief Set the USB configuration strings
@@ -499,7 +499,7 @@ extern struct config_strs *usbg_get_config_strs(usbg_config *c,
  * @param c_sttrs Configuration strings
  */
 extern void usbg_set_config_strs(usbg_config *c, int lang,
-		struct config_strs *c_strs);
+		usbg_config_strs *c_strs);
 
 /**
  * @brief Set the configuration string
@@ -591,7 +591,7 @@ extern char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len);
  * @return Type of function
  * @warning Pointer to function has to be valid.
  */
-extern enum function_type usbg_get_function_type(usbg_function *f);
+extern usbg_function_type usbg_get_function_type(usbg_function *f);
 
 /**
  * @brief Get attributes of given function
@@ -599,15 +599,15 @@ extern enum function_type usbg_get_function_type(usbg_function *f);
  * @param f_attrs Union to be filled
  * @return Pointer to filled structure or NULL if error occurred.
  */
-extern union attrs *usbg_get_function_attrs(usbg_function *f,
-		union attrs *f_attrs);
+extern usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
+		usbg_function_attrs *f_attrs);
 
 /**
  * @brief Set attributes of given function
  * @param f Pointer to function
  * @param f_attrs Attributes to be set
  */
-extern void usbg_set_function_attrs(usbg_function *f, union attrs *f_attrs);
+extern void usbg_set_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs);
 
 /**
  * @brief Set USB function network device address
diff --git a/src/usbg.c b/src/usbg.c
index b792c97..5e803f1 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -49,8 +49,8 @@ struct usbg_gadget
 	char path[USBG_MAX_PATH_LENGTH];
 	char udc[USBG_MAX_STR_LENGTH];
 
-	struct gadget_attrs attrs;
-	struct gadget_strs strs;
+	usbg_gadget_attrs attrs;
+	usbg_gadget_strs strs;
 
 	TAILQ_ENTRY(usbg_gadget) gnode;
 	TAILQ_HEAD(chead, usbg_config) configs;
@@ -66,8 +66,8 @@ struct usbg_config
 
 	char name[USBG_MAX_NAME_LENGTH];
 	char path[USBG_MAX_PATH_LENGTH];
-	struct config_attrs attrs;
-	struct config_strs strs;
+	usbg_config_attrs attrs;
+	usbg_config_strs strs;
 };
 
 struct usbg_function
@@ -78,8 +78,8 @@ struct usbg_function
 	char name[USBG_MAX_NAME_LENGTH];
 	char path[USBG_MAX_PATH_LENGTH];
 
-	enum function_type type;
-	union attrs attr;
+	usbg_function_type type;
+	usbg_function_attrs attr;
 };
 
 struct usbg_binding
@@ -339,14 +339,14 @@ static int usbg_parse_functions(char *path, usbg_gadget *g)
 }
 
 static void usbg_parse_config_attrs(char *path, char *name,
-		struct config_attrs *c_attrs)
+		usbg_config_attrs *c_attrs)
 {
 	c_attrs->bMaxPower = usbg_read_dec(path, name, "MaxPower");
 	c_attrs->bmAttributes = usbg_read_hex(path, name, "bmAttributes");
 }
 
 static void usbg_parse_config_strs(char *path, char *name,
-		struct config_strs *c_attrs)
+		usbg_config_strs *c_attrs)
 {
 	/* Hardcoded to US English right now*/
 	int lang = LANG_US_ENG;
@@ -425,7 +425,7 @@ static int usbg_parse_configs(char *path, usbg_gadget *g)
 }
 
 static void usbg_parse_gadget_attrs(char *path, char *name,
-		struct gadget_attrs *g_attrs)
+		usbg_gadget_attrs *g_attrs)
 {
 	/* Actual attributes */
 	g_attrs->bcdUSB = (uint16_t)usbg_read_hex(path, name, "bcdUSB");
@@ -438,7 +438,7 @@ static void usbg_parse_gadget_attrs(char *path, char *name,
 	g_attrs->bcdDevice = (uint16_t)usbg_read_hex(path, name, "bcdDevice");
 }
 
-static void usbg_parse_strings(char *path, char *name, struct gadget_strs *g_strs)
+static void usbg_parse_strings(char *path, char *name, usbg_gadget_strs *g_strs)
 {
 	/* Strings - hardcoded to U.S. English only for now */
 	int lang = LANG_US_ENG;
@@ -686,7 +686,7 @@ usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name,
 }
 
 usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
-		struct gadget_attrs *g_attrs, struct gadget_strs *g_strs)
+		usbg_gadget_attrs *g_attrs, usbg_gadget_strs *g_strs)
 {
 	usbg_gadget *g;
 
@@ -719,8 +719,8 @@ usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
 	return g;
 }
 
-struct gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-		struct gadget_attrs *g_attrs)
+usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
+		usbg_gadget_attrs *g_attrs)
 {
 	if (g && g_attrs)
 		*g_attrs = g->attrs;
@@ -750,7 +750,7 @@ char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len)
 	return g ? strncpy(buf, g->udc, len) : NULL;
 }
 
-void usbg_set_gadget_attrs(usbg_gadget *g, struct gadget_attrs *g_attrs)
+void usbg_set_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs)
 {
 	if (!g || !g_attrs)
 		return;
@@ -814,8 +814,8 @@ void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
 	usbg_write_hex16(g->path, g->name, "bcdUSB", bcdUSB);
 }
 
-struct gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
-		struct gadget_strs *g_strs)
+usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
+		usbg_gadget_strs *g_strs)
 {
 	if (g && g_strs)
 		*g_strs = g->strs;
@@ -826,7 +826,7 @@ struct gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
 }
 
 void usbg_set_gadget_strs(usbg_gadget *g, int lang,
-		struct gadget_strs *g_strs)
+		usbg_gadget_strs *g_strs)
 {
 	char path[USBG_MAX_PATH_LENGTH];
 
@@ -888,8 +888,8 @@ void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd)
 	usbg_write_string(path, "", "product", prd);
 }
 
-usbg_function *usbg_create_function(usbg_gadget *g, enum function_type type,
-		char *instance, union attrs *f_attrs)
+usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type type,
+		char *instance, usbg_function_attrs *f_attrs)
 {
 	char fpath[USBG_MAX_PATH_LENGTH];
 	char name[USBG_MAX_STR_LENGTH];
@@ -939,7 +939,7 @@ usbg_function *usbg_create_function(usbg_gadget *g, enum function_type type,
 }
 
 usbg_config *usbg_create_config(usbg_gadget *g, char *name,
-		struct config_attrs *c_attrs, struct config_strs *c_strs)
+		usbg_config_attrs *c_attrs, usbg_config_strs *c_strs)
 {
 	char cpath[USBG_MAX_PATH_LENGTH];
 	usbg_config *c;
@@ -1011,7 +1011,7 @@ char *usbg_get_function_name(usbg_function *f, char *buf, size_t len)
 	return f ? strncpy(buf, f->name, len) : NULL;
 }
 
-void usbg_set_config_attrs(usbg_config *c, struct config_attrs *c_attrs)
+void usbg_set_config_attrs(usbg_config *c, usbg_config_attrs *c_attrs)
 {
 	if (!c || !c_attrs)
 		return;
@@ -1022,8 +1022,8 @@ void usbg_set_config_attrs(usbg_config *c, struct config_attrs *c_attrs)
 	usbg_write_hex8(c->path, c->name, "bmAttributes", c_attrs->bmAttributes);
 }
 
-struct config_attrs *usbg_get_config_attrs(usbg_config *c,
-		struct config_attrs *c_attrs)
+usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
+		usbg_config_attrs *c_attrs)
 {
 	if (c && c_attrs)
 		*c_attrs = c->attrs;
@@ -1045,8 +1045,8 @@ void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
 	usbg_write_hex8(c->path, c->name, "bmAttributes", bmAttributes);
 }
 
-struct config_strs *usbg_get_config_strs(usbg_config *c,
-		struct config_strs *c_strs)
+usbg_config_strs *usbg_get_config_strs(usbg_config *c,
+		usbg_config_strs *c_strs)
 {
 	if (c && c_strs)
 		*c_strs = c->strs;
@@ -1057,7 +1057,7 @@ struct config_strs *usbg_get_config_strs(usbg_config *c,
 }
 
 void usbg_set_config_strs(usbg_config *c, int lang,
-		struct config_strs *c_strs)
+		usbg_config_strs *c_strs)
 {
 	usbg_set_config_string(c, lang, c_strs->configuration);
 }
@@ -1175,12 +1175,12 @@ void usbg_disable_gadget(usbg_gadget *g)
  * USB function-specific attribute configuration
  */
 
-enum function_type usbg_get_function_type(usbg_function *f)
+usbg_function_type usbg_get_function_type(usbg_function *f)
 {
 	return f->type;
 }
 
-union attrs *usbg_get_function_attrs(usbg_function *f, union attrs *f_attrs)
+usbg_function_attrs *usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
 {
 	if (f && f_attrs)
 		*f_attrs = f->attr;
@@ -1190,7 +1190,7 @@ union attrs *usbg_get_function_attrs(usbg_function *f, union attrs *f_attrs)
 	return f_attrs;
 }
 
-void usbg_set_function_attrs(usbg_function *f, union attrs *f_attrs)
+void usbg_set_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
 {
 	char *addr;
 
-- 
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