Hide definition of binding structure to avoid direct access to its fields. Rename it to usbg_binding. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- examples/show-gadgets.c | 9 +++++---- include/usbg/usbg.h | 31 +++++++++++-------------------- src/usbg.c | 40 +++++++++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index f0dc182..3f72a96 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -95,7 +95,7 @@ void show_function(usbg_function *f) void show_config(usbg_config *c) { - struct binding *b; + usbg_binding *b; usbg_function *f; char buf[USBG_MAX_STR_LENGTH], buf2[USBG_MAX_STR_LENGTH]; struct config_attrs c_attrs; @@ -112,9 +112,10 @@ void show_config(usbg_config *c) fprintf(stdout, " configuration\t%s\n", c_strs.configuration); usbg_for_each_binding(b, c) { - f = b->target; + usbg_get_binding_name(b, buf, USBG_MAX_STR_LENGTH); + f = usbg_get_binding_target(b); usbg_get_function_name(f, buf2, USBG_MAX_STR_LENGTH); - fprintf(stdout, " %s -> %s\n", b->name, buf2); + fprintf(stdout, " %s -> %s\n", buf, buf2); } } @@ -124,7 +125,7 @@ int main(void) usbg_gadget *g; usbg_function *f; usbg_config *c; - struct binding *b; + usbg_binding *b; s = usbg_init("/sys/kernel/config"); if (!s) { diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 2f16fc2..1698312 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -48,6 +48,7 @@ struct usbg_state; struct usbg_gadget; struct usbg_config; struct usbg_function; +struct usbg_binding; /** * @brief State of the gadget devices in the system @@ -70,6 +71,11 @@ typedef struct usbg_config usbg_config; typedef struct usbg_function usbg_function; /** + * @brief USB function to config binding + */ +typedef struct usbg_binding usbg_binding; + +/** * @struct gadget_attrs * @brief USB gadget device attributes */ @@ -169,21 +175,6 @@ union attrs { struct phonet_attrs phonet; }; -/** - * @struct binding - * @brief Describes a binding between a USB gadget configuration - * and a USB gadget function - */ -struct binding -{ - TAILQ_ENTRY(binding) bnode; - usbg_config *parent; - usbg_function *target; - - char name[USBG_MAX_NAME_LENGTH]; - char path[USBG_MAX_PATH_LENGTH]; -}; - /* Library init and cleanup */ /** @@ -532,14 +523,14 @@ extern int usbg_add_config_function(usbg_config *c, char *name, usbg_function *f * @param b Binding between configuration and function * @return Pointer to USB function which is target for this binding */ -extern usbg_function *usbg_get_binding_target(struct binding *b); +extern usbg_function *usbg_get_binding_target(usbg_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); +extern size_t usbg_get_binding_name_len(usbg_binding *b); /** * @brief Get binding name @@ -548,7 +539,7 @@ extern size_t usbg_get_binding_name_len(struct binding *b); * @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); +extern char *usbg_get_binding_name(usbg_binding *b, char *buf, size_t len); /* USB gadget setup and teardown */ @@ -705,7 +696,7 @@ extern usbg_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(usbg_config *c); +extern usbg_binding *usbg_get_first_binding(usbg_config *c); /** * @brief Get the next gadget on a list. @@ -733,7 +724,7 @@ extern usbg_config *usbg_get_next_config(usbg_config *c); * @pram g Pointer to current binding * @return Next binding or NULL if end of list. */ -extern struct binding *usbg_get_next_binding(struct binding *b); +extern usbg_binding *usbg_get_next_binding(usbg_binding *b); /** * @} diff --git a/src/usbg.c b/src/usbg.c index 96a4cf3..b792c97 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -61,7 +61,7 @@ struct usbg_gadget struct usbg_config { TAILQ_ENTRY(usbg_config) cnode; - TAILQ_HEAD(bhead, binding) bindings; + TAILQ_HEAD(bhead, usbg_binding) bindings; usbg_gadget *parent; char name[USBG_MAX_NAME_LENGTH]; @@ -82,6 +82,16 @@ struct usbg_function union attrs attr; }; +struct usbg_binding +{ + TAILQ_ENTRY(usbg_binding) bnode; + usbg_config *parent; + usbg_function *target; + + char name[USBG_MAX_NAME_LENGTH]; + char path[USBG_MAX_PATH_LENGTH]; +}; + /** * @var function_names * @brief Name strings for supported USB function types @@ -352,7 +362,7 @@ static void usbg_parse_config_bindings(usbg_config *c) struct dirent **dent; char bpath[USBG_MAX_PATH_LENGTH]; usbg_gadget *g = c->parent; - struct binding *b; + usbg_binding *b; usbg_function *f; sprintf(bpath, "%s/%s", c->path, c->name); @@ -373,7 +383,7 @@ static void usbg_parse_config_bindings(usbg_config *c) ERRORNO("bytes %d contents %s\n", n, contents); strcpy(fname, f->name); if (strstr(contents, strtok(fname, "."))) { - b = malloc(sizeof(struct binding)); + b = malloc(sizeof(usbg_binding)); strcpy(b->name, dent[i]->d_name); strcpy(b->path, bpath); b->target = f; @@ -518,7 +528,7 @@ void usbg_cleanup(usbg_state *s) { usbg_gadget *g; usbg_config *c; - struct binding *b; + usbg_binding *b; usbg_function *f; while (!TAILQ_EMPTY(&s->gadgets)) { @@ -588,9 +598,9 @@ usbg_config *usbg_get_config(usbg_gadget *g, const char *name) return NULL; } -struct binding *usbg_get_binding(usbg_config *c, const char *name) +usbg_binding *usbg_get_binding(usbg_config *c, const char *name) { - struct binding *b; + usbg_binding *b; TAILQ_FOREACH(b, &c->bindings, bnode) if (!strcmp(b->name, name)) @@ -599,9 +609,9 @@ struct binding *usbg_get_binding(usbg_config *c, const char *name) return NULL; } -struct binding *usbg_get_link_binding(usbg_config *c, usbg_function *f) +usbg_binding *usbg_get_link_binding(usbg_config *c, usbg_function *f) { - struct binding *b; + usbg_binding *b; TAILQ_FOREACH(b, &c->bindings, bnode) if (b->target == f) @@ -1071,7 +1081,7 @@ int usbg_add_config_function(usbg_config *c, char *name, usbg_function *f) { char bpath[USBG_MAX_PATH_LENGTH]; char fpath[USBG_MAX_PATH_LENGTH]; - struct binding *b; + usbg_binding *b; int ret = -1; if (!c || !f) @@ -1092,7 +1102,7 @@ int usbg_add_config_function(usbg_config *c, char *name, usbg_function *f) sprintf(bpath, "%s/%s/%s", c->path, c->name, name); sprintf(fpath, "%s/%s", f->path, f->name); - b = malloc(sizeof(struct binding)); + b = malloc(sizeof(usbg_binding)); if (!b) { ERRORNO("allocating binding\n"); return -1; @@ -1114,17 +1124,17 @@ int usbg_add_config_function(usbg_config *c, char *name, usbg_function *f) return 0; } -usbg_function *usbg_get_binding_target(struct binding *b) +usbg_function *usbg_get_binding_target(usbg_binding *b) { return b ? b->target : NULL; } -size_t usbg_get_binding_name_len(struct binding *b) +size_t usbg_get_binding_name_len(usbg_binding *b) { return b ? strlen(b->name) : -1; } -char *usbg_get_binding_name(struct binding *b, char *buf, size_t len) +char *usbg_get_binding_name(usbg_binding *b, char *buf, size_t len) { return b ? strncpy(buf, b->name, len) : NULL; } @@ -1259,7 +1269,7 @@ usbg_config *usbg_get_first_config(usbg_gadget *g) return g ? TAILQ_FIRST(&g->configs) : NULL; } -struct binding *usbg_get_first_binding(usbg_config *c) +usbg_binding *usbg_get_first_binding(usbg_config *c) { return c ? TAILQ_FIRST(&c->bindings) : NULL; } @@ -1279,7 +1289,7 @@ usbg_config *usbg_get_next_config(usbg_config *c) return c ? TAILQ_NEXT(c, cnode) : NULL; } -struct binding *usbg_get_next_binding(struct binding *b) +usbg_binding *usbg_get_next_binding(usbg_binding *b) { return b ? TAILQ_NEXT(b, bnode) : NULL; } -- 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