Hide definition of config structure to avoid direct
access to its fields. Rename it to usbg_confg.

Signed-off-by: Krzysztof Opasiak <[email protected]>
---
 examples/gadget-acm-ecm.c |    2 +-
 examples/show-gadgets.c   |    4 +--
 include/usbg/usbg.h       |   54 ++++++++++++++++-----------------------
 src/usbg.c                |   62 +++++++++++++++++++++++++++------------------
 4 files changed, 62 insertions(+), 60 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 633f482..2a37f14 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -32,7 +32,7 @@ int main(void)
        usbg_state *s;
        usbg_gadget *g;
        struct function *f;
-       struct config *c;
+       usbg_config *c;
        struct function *f_acm0, *f_acm1, *f_ecm;
        int ret = -EINVAL;
 
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index bea3e08..f7bd3c1 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -87,7 +87,7 @@ void show_function(struct function *f)
        }
 }
 
-void show_config(struct config *c)
+void show_config(usbg_config *c)
 {
        struct binding *b;
        struct function *f;
@@ -114,7 +114,7 @@ int main(void)
        usbg_state *s;
        usbg_gadget *g;
        struct function *f;
-       struct config *c;
+       usbg_config *c;
        struct binding *b;
        struct function *f_acm0, *f_acm1, *f_ecm;
 
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ad67876..4d25cc9 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -46,6 +46,7 @@
  */
 struct usbg_state;
 struct usbg_gadget;
+struct usbg_config;
 
 /**
  * @brief State of the gadget devices in the system
@@ -58,6 +59,11 @@ typedef struct usbg_state usbg_state;
 typedef struct usbg_gadget usbg_gadget;
 
 /**
+ * @brief USB configuration
+ */
+typedef struct usbg_config usbg_config;
+
+/**
  * @struct gadget_attrs
  * @brief USB gadget device attributes
  */
@@ -104,22 +110,6 @@ struct config_strs
 };
 
 /**
- * @struct config
- * @brief USB gadget configuration attributes
- */
-struct config
-{
-       TAILQ_ENTRY(config) cnode;
-       TAILQ_HEAD(bhead, binding) bindings;
-       usbg_gadget *parent;
-
-       char name[USBG_MAX_NAME_LENGTH];
-       char path[USBG_MAX_PATH_LENGTH];
-       struct config_attrs attrs;
-       struct config_strs strs;
-};
-
-/**
  * @enum function_type
  * @brief Supported USB function types
  */
@@ -198,7 +188,7 @@ struct function
 struct binding
 {
        TAILQ_ENTRY(binding) bnode;
-       struct config *parent;
+       usbg_config *parent;
        struct function *target;
 
        char name[USBG_MAX_NAME_LENGTH];
@@ -260,7 +250,7 @@ extern struct function *usbg_get_function(usbg_gadget *g, 
const char *name);
  * @param name Name of the configuration
  * @return Pointer to config or NULL if a matching config isn't found
  */
-extern struct config *usbg_get_config(usbg_gadget *g, const char *name);
+extern usbg_config *usbg_get_config(usbg_gadget *g, const char *name);
 
 /* USB gadget allocation and configuration */
 
@@ -463,7 +453,7 @@ extern char *usbg_get_function_name(struct function *f, 
char *buf, size_t len);
  * @param c_strs Configuration strings to be set
  * @return Pointer to configuration or NULL if it cannot be created
  */
-extern struct config *usbg_create_config(usbg_gadget *g, char *name,
+extern usbg_config *usbg_create_config(usbg_gadget *g, char *name,
                struct config_attrs *c_attrs, struct config_strs *c_strs);
 
 /**
@@ -471,7 +461,7 @@ extern struct config *usbg_create_config(usbg_gadget *g, 
char *name,
  * @param c Config which name length should be returned
  * @return Length of name string or -1 if error occurred.
  */
-extern size_t usbg_get_config_name_len(struct config *c);
+extern size_t usbg_get_config_name_len(usbg_config *c);
 
 /**
  * @brieg Get config name
@@ -480,14 +470,14 @@ extern size_t usbg_get_config_name_len(struct config *c);
  * @param len Length of given buffer
  * @return Pointer to destination or NULL if error occurred.
  */
-extern char *usbg_get_config_name(struct config *c, char *buf, size_t len);
+extern char *usbg_get_config_name(usbg_config *c, char *buf, size_t len);
 
 /**
  * @brief Set the USB configuration attributes
  * @param c Pointer to configuration
  * @param c_attrs Configuration attributes
  */
-extern void usbg_set_config_attrs(struct config *c,
+extern void usbg_set_config_attrs(usbg_config *c,
                struct config_attrs *c_attrs);
 
 /**
@@ -496,7 +486,7 @@ extern void usbg_set_config_attrs(struct 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(struct config *c,
+extern struct config_attrs *usbg_get_config_attrs(usbg_config *c,
                struct config_attrs *c_attrs);
 
 /**
@@ -504,14 +494,14 @@ extern struct config_attrs *usbg_get_config_attrs(struct 
config *c,
  * @param c Pointer to config
  * @param bMaxPower Maximum power (in 2 mA units)
  */
-extern void usbg_set_config_max_power(struct config *c, int bMaxPower);
+extern void usbg_set_config_max_power(usbg_config *c, int bMaxPower);
 
 /**
  * @brief Set the configuration bitmap attributes
  * @param c Pointer to config
  * @param bmAttributes Configuration characteristics
  */
-extern void usbg_set_config_bm_attrs(struct config *c, int bmAttributes);
+extern void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
 
 /**
  * @brief Get the USB configuration strings
@@ -519,7 +509,7 @@ extern void usbg_set_config_bm_attrs(struct 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(struct config *c,
+extern struct config_strs *usbg_get_config_strs(usbg_config *c,
                struct config_strs *c_strs);
 
 /**
@@ -528,7 +518,7 @@ extern struct config_strs *usbg_get_config_strs(struct 
config *c,
  * @param lang USB language ID
  * @param c_sttrs Configuration strings
  */
-extern void usbg_set_config_strs(struct config *c, int lang,
+extern void usbg_set_config_strs(usbg_config *c, int lang,
                struct config_strs *c_strs);
 
 /**
@@ -537,7 +527,7 @@ extern void usbg_set_config_strs(struct config *c, int lang,
  * @param lang USB language ID
  * @param string Configuration description
  */
-extern void usbg_set_config_string(struct config *c, int lang, char *string);
+extern void usbg_set_config_string(usbg_config *c, int lang, char *string);
 
 /**
  * @brief Add a function to a configuration
@@ -546,7 +536,7 @@ extern void usbg_set_config_string(struct config *c, int 
lang, char *string);
  * @param f Pointer to function
  * @return 0 on success, -1 on failure.
  */
-extern int usbg_add_config_function(struct config *c, char *name, struct 
function *f);
+extern int usbg_add_config_function(usbg_config *c, char *name, struct 
function *f);
 
 /**
  * @brief Get target function of given binding
@@ -718,7 +708,7 @@ extern struct function *usbg_get_first_function(usbg_gadget 
*g);
  * @return Pointer to configuration or NULL if list is empty.
  * @note Configs are sorted in strings (name) order
  */
-extern struct config *usbg_get_first_config(usbg_gadget *g);
+extern usbg_config *usbg_get_first_config(usbg_gadget *g);
 
 /**
  * @brief Get first binding in binding list
@@ -726,7 +716,7 @@ extern struct config *usbg_get_first_config(usbg_gadget *g);
  * @return Pointer to binding or NULL if list is empty.
  * @note Bindings are sorted in strings (name) order
  */
-extern struct binding *usbg_get_first_binding(struct config *c);
+extern struct binding *usbg_get_first_binding(usbg_config *c);
 
 /**
  * @brief Get the next gadget on a list.
@@ -747,7 +737,7 @@ extern struct function *usbg_get_next_function(struct 
function *f);
  * @pram g Pointer to current config
  * @return Next config or NULL if end of list.
  */
-extern struct config *usbg_get_next_config(struct config *c);
+extern usbg_config *usbg_get_next_config(usbg_config *c);
 
 /**
  * @brief Get the next binding on a list.
diff --git a/src/usbg.c b/src/usbg.c
index a05d5ac..fc9cd46 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -53,11 +53,23 @@ struct usbg_gadget
        struct gadget_strs strs;
 
        TAILQ_ENTRY(usbg_gadget) gnode;
-       TAILQ_HEAD(chead, config) configs;
+       TAILQ_HEAD(chead, usbg_config) configs;
        TAILQ_HEAD(fhead, function) functions;
        usbg_state *parent;
 };
 
+struct usbg_config
+{
+       TAILQ_ENTRY(usbg_config) cnode;
+       TAILQ_HEAD(bhead, binding) bindings;
+       usbg_gadget *parent;
+
+       char name[USBG_MAX_NAME_LENGTH];
+       char path[USBG_MAX_PATH_LENGTH];
+       struct config_attrs attrs;
+       struct config_strs strs;
+};
+
 /**
  * @var function_names
  * @brief Name strings for supported USB function types
@@ -322,7 +334,7 @@ static void usbg_parse_config_strs(char *path, char *name,
        usbg_read_string(spath, "", "configuration", c_attrs->configuration);
 }
 
-static void usbg_parse_config_bindings(struct config *c)
+static void usbg_parse_config_bindings(usbg_config *c)
 {
        int i, n;
        struct dirent **dent;
@@ -364,7 +376,7 @@ static void usbg_parse_config_bindings(struct config *c)
 
 static int usbg_parse_configs(char *path, usbg_gadget *g)
 {
-       struct config *c;
+       usbg_config *c;
        int i, n;
        struct dirent **dent;
        char cpath[USBG_MAX_PATH_LENGTH];
@@ -375,7 +387,7 @@ static int usbg_parse_configs(char *path, usbg_gadget *g)
 
        n = scandir(cpath, &dent, file_select, alphasort);
        for (i=0; i < n; i++) {
-               c = malloc(sizeof(struct config));
+               c = malloc(sizeof(usbg_config));
                c->parent = g;
                strcpy(c->name, dent[i]->d_name);
                strcpy(c->path, cpath);
@@ -493,7 +505,7 @@ out:
 void usbg_cleanup(usbg_state *s)
 {
        usbg_gadget *g;
-       struct config *c;
+       usbg_config *c;
        struct binding *b;
        struct function *f;
 
@@ -553,9 +565,9 @@ struct function *usbg_get_function(usbg_gadget *g, const 
char *name)
        return NULL;
 }
 
-struct config *usbg_get_config(usbg_gadget *g, const char *name)
+usbg_config *usbg_get_config(usbg_gadget *g, const char *name)
 {
-       struct config *c;
+       usbg_config *c;
 
        TAILQ_FOREACH(c, &g->configs, cnode)
                if (!strcmp(c->name, name))
@@ -564,7 +576,7 @@ struct config *usbg_get_config(usbg_gadget *g, const char 
*name)
        return NULL;
 }
 
-struct binding *usbg_get_binding(struct config *c, const char *name)
+struct binding *usbg_get_binding(usbg_config *c, const char *name)
 {
        struct binding *b;
 
@@ -575,7 +587,7 @@ struct binding *usbg_get_binding(struct config *c, const 
char *name)
        return NULL;
 }
 
-struct binding *usbg_get_link_binding(struct config *c, struct function *f)
+struct binding *usbg_get_link_binding(usbg_config *c, struct function *f)
 {
        struct binding *b;
 
@@ -904,11 +916,11 @@ struct function *usbg_create_function(usbg_gadget *g, 
enum function_type type,
        return f;
 }
 
-struct config *usbg_create_config(usbg_gadget *g, char *name,
+usbg_config *usbg_create_config(usbg_gadget *g, char *name,
                struct config_attrs *c_attrs, struct config_strs *c_strs)
 {
        char cpath[USBG_MAX_PATH_LENGTH];
-       struct config *c;
+       usbg_config *c;
        int ret;
 
        if (!g)
@@ -925,7 +937,7 @@ struct config *usbg_create_config(usbg_gadget *g, char 
*name,
 
        sprintf(cpath, "%s/%s/%s/%s", g->path, g->name, CONFIGS_DIR, name);
 
-       c = malloc(sizeof(struct config));
+       c = malloc(sizeof(usbg_config));
        if (!c) {
                ERRORNO("allocating configuration\n");
                return NULL;
@@ -957,12 +969,12 @@ struct config *usbg_create_config(usbg_gadget *g, char 
*name,
        return c;
 }
 
-size_t usbg_get_config_name_len(struct config *c)
+size_t usbg_get_config_name_len(usbg_config *c)
 {
        return c ? strlen(c->name) : -1;
 }
 
-char *usbg_get_config_name(struct config *c, char *buf, size_t len)
+char *usbg_get_config_name(usbg_config *c, char *buf, size_t len)
 {
        return c ? strncpy(buf, c->name, len) : NULL;
 }
@@ -977,7 +989,7 @@ char *usbg_get_function_name(struct function *f, char *buf, 
size_t len)
        return f ? strncpy(buf, f->name, len) : NULL;
 }
 
-void usbg_set_config_attrs(struct config *c, struct config_attrs *c_attrs)
+void usbg_set_config_attrs(usbg_config *c, struct config_attrs *c_attrs)
 {
        if (!c || !c_attrs)
                return;
@@ -988,7 +1000,7 @@ void usbg_set_config_attrs(struct 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(struct config *c,
+struct config_attrs *usbg_get_config_attrs(usbg_config *c,
                struct config_attrs *c_attrs)
 {
        if (c && c_attrs)
@@ -999,19 +1011,19 @@ struct config_attrs *usbg_get_config_attrs(struct config 
*c,
        return c_attrs;
 }
 
-void usbg_set_config_max_power(struct config *c, int bMaxPower)
+void usbg_set_config_max_power(usbg_config *c, int bMaxPower)
 {
        c->attrs.bMaxPower = bMaxPower;
        usbg_write_dec(c->path, c->name, "MaxPower", bMaxPower);
 }
 
-void usbg_set_config_bm_attrs(struct config *c, int bmAttributes)
+void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
 {
        c->attrs.bmAttributes = bmAttributes;
        usbg_write_hex8(c->path, c->name, "bmAttributes", bmAttributes);
 }
 
-struct config_strs *usbg_get_config_strs(struct config *c,
+struct config_strs *usbg_get_config_strs(usbg_config *c,
                struct config_strs *c_strs)
 {
        if (c && c_strs)
@@ -1022,13 +1034,13 @@ struct config_strs *usbg_get_config_strs(struct config 
*c,
        return c_strs;
 }
 
-void usbg_set_config_strs(struct config *c, int lang,
+void usbg_set_config_strs(usbg_config *c, int lang,
                struct config_strs *c_strs)
 {
        usbg_set_config_string(c, lang, c_strs->configuration);
 }
 
-void usbg_set_config_string(struct config *c, int lang, char *str)
+void usbg_set_config_string(usbg_config *c, int lang, char *str)
 {
        char path[USBG_MAX_PATH_LENGTH];
 
@@ -1043,7 +1055,7 @@ void usbg_set_config_string(struct config *c, int lang, 
char *str)
        usbg_write_string(path, "", "configuration", str);
 }
 
-int usbg_add_config_function(struct config *c, char *name, struct function *f)
+int usbg_add_config_function(usbg_config *c, char *name, struct function *f)
 {
        char bpath[USBG_MAX_PATH_LENGTH];
        char fpath[USBG_MAX_PATH_LENGTH];
@@ -1230,12 +1242,12 @@ struct function *usbg_get_first_function(usbg_gadget *g)
        return g ? TAILQ_FIRST(&g->functions) : NULL;
 }
 
-struct config *usbg_get_first_config(usbg_gadget *g)
+usbg_config *usbg_get_first_config(usbg_gadget *g)
 {
        return g ? TAILQ_FIRST(&g->configs) : NULL;
 }
 
-struct binding *usbg_get_first_binding(struct config *c)
+struct binding *usbg_get_first_binding(usbg_config *c)
 {
        return c ? TAILQ_FIRST(&c->bindings) : NULL;
 }
@@ -1250,7 +1262,7 @@ struct function *usbg_get_next_function(struct function 
*f)
        return f ? TAILQ_NEXT(f, fnode) : NULL;
 }
 
-struct config *usbg_get_next_config(struct config *c)
+usbg_config *usbg_get_next_config(usbg_config *c)
 {
        return c ? TAILQ_NEXT(c, cnode) : NULL;
 }
-- 
1.7.9.5

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

Reply via email to