Hide definition of state structure to avoid direct access to its fields. Rename it to usbg_state. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- examples/gadget-acm-ecm.c | 2 +- examples/show-gadgets.c | 2 +- include/usbg/usbg.h | 31 +++++++++++++++---------------- src/usbg.c | 33 ++++++++++++++++++++------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c index b6f0c94..672d4b5 100644 --- a/examples/gadget-acm-ecm.c +++ b/examples/gadget-acm-ecm.c @@ -29,7 +29,7 @@ int main(void) { - struct state *s; + usbg_state *s; struct gadget *g; struct function *f; struct config *c; diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index b9c5948..a53c355 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -89,7 +89,7 @@ void show_config(struct config *c) int main(void) { - struct state *s; + usbg_state *s; struct gadget *g; struct function *f; struct config *c; diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 603a4a3..5cad066 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -41,16 +41,15 @@ #define USBG_MAX_PATH_LENGTH 256 #define USBG_MAX_NAME_LENGTH 40 +/* + * Internal structures + */ +struct usbg_state; + /** - * @struct state * @brief State of the gadget devices in the system */ -struct state -{ - char path[USBG_MAX_PATH_LENGTH]; - - TAILQ_HEAD(ghead, gadget) gadgets; -}; +typedef struct usbg_state usbg_state; /** * @struct gadget_attrs @@ -95,7 +94,7 @@ struct gadget TAILQ_ENTRY(gadget) gnode; TAILQ_HEAD(chead, config) configs; TAILQ_HEAD(fhead, function) functions; - struct state *parent; + usbg_state *parent; }; /** @@ -226,20 +225,20 @@ struct binding * @param configfs_path Path to the mounted configfs filesystem * @return Pointer to a state structure */ -extern struct state *usbg_init(char *configfs_path); +extern usbg_state *usbg_init(char *configfs_path); /** * @brief Clean up the libusbg library state * @param s Pointer to state */ -extern void usbg_cleanup(struct state *s); +extern void usbg_cleanup(usbg_state *s); /** * @brief Get ConfigFS path length * @param s Pointer to state * @return Length of path or -1 if error occurred. */ -extern size_t usbg_get_configfs_path_len(struct state *s); +extern size_t usbg_get_configfs_path_len(usbg_state *s); /** * @brieg Get ConfigFS path @@ -248,7 +247,7 @@ extern size_t usbg_get_configfs_path_len(struct state *s); * @param len Length of given buffer * @return Pointer to destination or NULL if error occurred. */ -extern char *usbg_get_configfs_path(struct state *s, char *buf, size_t len); +extern char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len); /* USB gadget queries */ @@ -258,7 +257,7 @@ extern char *usbg_get_configfs_path(struct state *s, char *buf, size_t len); * @param name Name of the gadget device * @return Pointer to gadget or NULL if a matching gadget isn't found */ -extern struct gadget *usbg_get_gadget(struct state *s, const char *name); +extern struct gadget *usbg_get_gadget(usbg_state *s, const char *name); /** * @brief Get a function by name @@ -286,7 +285,7 @@ extern struct config *usbg_get_config(struct gadget *g, const char *name); * @param idProduct Gadget product ID * @return Pointer to gadget or NULL if the gadget cannot be created */ -extern struct gadget *usbg_create_gadget_vid_pid(struct state *s, char *name, +extern struct gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, uint16_t idVendor, uint16_t idProduct); /** @@ -299,7 +298,7 @@ extern struct gadget *usbg_create_gadget_vid_pid(struct state *s, char *name, * @note Given strings are assumed to be in US English * @return Pointer to gadget or NULL if the gadget cannot be created */ -extern struct gadget *usbg_create_gadget(struct state *s, char *name, +extern struct gadget *usbg_create_gadget(usbg_state *s, char *name, struct gadget_attrs *g_attrs, struct gadget_strs *g_strs); /** @@ -716,7 +715,7 @@ extern void usbg_set_net_qmult(struct function *f, int qmult); * @return Pointer to gadget or NULL if list is empty. * @note Gadgets are sorted in strings (name) order */ -extern struct gadget *usbg_get_first_gadget(struct state *s); +extern struct gadget *usbg_get_first_gadget(usbg_state *s); /** * @brief Get first function in function list diff --git a/src/usbg.c b/src/usbg.c index b160822..5649621 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -36,6 +36,13 @@ * @todo Error checking and return code propagation */ +struct usbg_state +{ + char path[USBG_MAX_PATH_LENGTH]; + + TAILQ_HEAD(ghead, gadget) gadgets; +}; + /** * @var function_names * @brief Name strings for supported USB function types @@ -395,7 +402,7 @@ static void usbg_parse_strings(char *path, char *name, struct gadget_strs *g_str usbg_read_string(spath, "", "product", g_strs->str_prd); } -static int usbg_parse_gadgets(char *path, struct state *s) +static int usbg_parse_gadgets(char *path, usbg_state *s) { struct gadget *g; int i, n; @@ -423,7 +430,7 @@ static int usbg_parse_gadgets(char *path, struct state *s) return 0; } -static int usbg_init_state(char *path, struct state *s) +static int usbg_init_state(char *path, usbg_state *s) { strcpy(s->path, path); @@ -439,12 +446,12 @@ static int usbg_init_state(char *path, struct state *s) * User API */ -struct state *usbg_init(char *configfs_path) +usbg_state *usbg_init(char *configfs_path) { int ret; struct stat sts; char path[USBG_MAX_PATH_LENGTH]; - struct state *s = NULL; + usbg_state *s = NULL; strcpy(path, configfs_path); ret = stat(strcat(path, "/usb_gadget"), &sts); @@ -458,7 +465,7 @@ struct state *usbg_init(char *configfs_path) goto out; } - s = malloc(sizeof(struct state)); + s = malloc(sizeof(usbg_state)); if (s) usbg_init_state(path, s); else @@ -468,7 +475,7 @@ out: return s; } -void usbg_cleanup(struct state *s) +void usbg_cleanup(usbg_state *s) { struct gadget *g; struct config *c; @@ -499,17 +506,17 @@ void usbg_cleanup(struct state *s) free(s); } -size_t usbg_get_configfs_path_len(struct state *s) +size_t usbg_get_configfs_path_len(usbg_state *s) { return s ? strlen(s->path) : -1; } -char *usbg_get_configfs_path(struct state *s, char *buf, size_t len) +char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len) { return s ? strncpy(buf, s->path, len) : NULL; } -struct gadget *usbg_get_gadget(struct state *s, const char *name) +struct gadget *usbg_get_gadget(usbg_state *s, const char *name) { struct gadget *g; @@ -564,7 +571,7 @@ struct binding *usbg_get_link_binding(struct config *c, struct function *f) return NULL; } -static struct gadget *usbg_create_empty_gadget(struct state *s, char *name) +static struct gadget *usbg_create_empty_gadget(usbg_state *s, char *name) { char gpath[USBG_MAX_PATH_LENGTH]; struct gadget *g; @@ -599,7 +606,7 @@ static struct gadget *usbg_create_empty_gadget(struct state *s, char *name) -struct gadget *usbg_create_gadget_vid_pid(struct state *s, char *name, +struct gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name, uint16_t idVendor, uint16_t idProduct) { struct gadget *g; @@ -629,7 +636,7 @@ struct gadget *usbg_create_gadget_vid_pid(struct state *s, char *name, return g; } -struct gadget *usbg_create_gadget(struct state *s, char *name, +struct gadget *usbg_create_gadget(usbg_state *s, char *name, struct gadget_attrs *g_attrs, struct gadget_strs *g_strs) { struct gadget *g; @@ -1198,7 +1205,7 @@ void usbg_set_net_qmult(struct function *f, int qmult) usbg_write_dec(f->path, f->name, "qmult", qmult); } -struct gadget *usbg_get_first_gadget(struct state *s) +struct gadget *usbg_get_first_gadget(usbg_state *s) { return s ? TAILQ_FIRST(&s->gadgets) : 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