libusbgx-0.2.0
Data Structures | Macros | Typedefs | Functions
usbg_internal.h File Reference
#include <sys/queue.h>
#include <string.h>
#include <usbg/usbg.h>
#include <malloc.h>
#include <sys/types.h>
#include "usbg_internal_none.h"

Go to the source code of this file.

Data Structures

struct  usbg_function_type
 
struct  usbg_state
 
struct  usbg_gadget
 
struct  usbg_config
 
struct  usbg_function
 
struct  usbg_binding
 
struct  usbg_udc
 

Macros

#define offsetof(type, member)   __builtin_offsetof (type, member)
 
#define container_of(ptr, type, field)
 
#define USBG_MAX_PATH_LENGTH   PATH_MAX
 
#define USBG_MAX_FILE_SIZE   4096
 
#define ARRAY_SIZE(array)   (sizeof(array)/sizeof(*array))
 
#define ARRAY_SIZE_SENTINEL(array, size)
 
#define ERROR(msg, ...)
 
#define ERRORNO(msg, ...)
 
#define INSERT_TAILQ_STRING_ORDER(HeadPtr, HeadType, NameField, ToInsert, NodeField)
 
#define STRINGS_DIR   "strings"
 
#define CONFIGS_DIR   "configs"
 
#define FUNCTIONS_DIR   "functions"
 
#define GADGETS_DIR   "usb_gadget"
 
#define OS_DESC_DIR   "os_desc"
 
#define usbg_read_dec(p, n, f, d)   usbg_read_int(p, n, f, 10, d)
 
#define usbg_read_hex(p, n, f, d)   usbg_read_int(p, n, f, 16, d)
 
#define usbg_write_dec(p, n, f, v)   usbg_write_int(p, n, f, v, "%d\n")
 
#define usbg_write_hex(p, n, f, v)   usbg_write_int(p, n, f, v, "0x%x\n")
 
#define usbg_write_hex16(p, n, f, v)   usbg_write_int(p, n, f, v, "0x%04x\n")
 
#define usbg_write_hex8(p, n, f, v)   usbg_write_int(p, n, f, v, "0x%02x\n")
 
#define usbg_write_bool(p, n, f, v)   usbg_write_dec(p, n, f, !!v)
 
#define usbg_config_is_int(node)   (config_setting_type(node) == CONFIG_TYPE_INT)
 
#define usbg_config_is_string(node)    (config_setting_type(node) == CONFIG_TYPE_STRING)
 
#define GENERIC_ALLOC_INST(prefix, _type, _member)
 
#define GENERIC_FREE_INST(prefix, _type, _member)
 

Typedefs

typedef int(* usbg_attr_get_func) (const char *, const char *, const char *, void *)
 
typedef int(* usbg_attr_set_func) (const char *, const char *, const char *, void *)
 
typedef int(* usbg_import_node_func) (config_setting_t *root, const char *node_name, void *val)
 
typedef int(* usbg_export_node_func) (config_setting_t *root, const char *node_name, void *val)
 

Functions

int usbg_translate_error (int error)
 
char * usbg_ether_ntoa_r (const struct ether_addr *addr, char *buf)
 
int usbg_read_buf (const char *path, const char *name, const char *file, char *buf)
 
int usbg_read_buf_limited (const char *path, const char *name, const char *file, char *buf, int len)
 
int usbg_read_int (const char *path, const char *name, const char *file, int base, int *dest)
 
int usbg_read_bool (const char *path, const char *name, const char *file, bool *dest)
 
int usbg_read_string (const char *path, const char *name, const char *file, char *buf)
 
int usbg_read_string_limited (const char *path, const char *name, const char *file, char *buf, int len)
 
int usbg_read_string_alloc (const char *path, const char *name, const char *file, char **dest)
 
int usbg_write_buf (const char *path, const char *name, const char *file, const char *buf, int len)
 
int usbg_write_int (const char *path, const char *name, const char *file, int value, const char *str)
 
int usbg_write_string (const char *path, const char *name, const char *file, const char *buf)
 
int usbg_rm_file (const char *path, const char *name)
 
int usbg_rm_dir (const char *path, const char *name)
 
int usbg_rm_all_dirs (const char *path)
 
int usbg_check_dir (const char *path)
 
int usbg_init_function (struct usbg_function *f, struct usbg_function_type *ops, usbg_function_type type, const char *type_name, const char *instance, const char *path, struct usbg_gadget *parent)
 
void usbg_cleanup_function (struct usbg_function *f)
 
int usbg_get_ether_addr (const char *path, const char *name, const char *attr, void *val)
 
int usbg_set_ether_addr (const char *path, const char *name, const char *attr, void *val)
 
int usbg_get_dev (const char *path, const char *name, const char *attr, void *val)
 

Macro Definition Documentation

◆ ARRAY_SIZE_SENTINEL

#define ARRAY_SIZE_SENTINEL (   array,
  size 
)
Value:
static void __attribute__ ((unused)) array##_size_sentinel() \
{ \
char array##_smaller_than_expected[ \
(int)(ARRAY_SIZE(array) - size)] \
__attribute__ ((unused)); \
\
char array##_larger_than_expected[ \
(int)(size - ARRAY_SIZE(array))] \
__attribute__ ((unused)); \
}

◆ container_of

#define container_of (   ptr,
  type,
  field 
)
Value:
({ \
const typeof(((type *)0)->field) *member = (ptr); \
(type *)( (char *)member - offsetof(type, field) ); \
})

◆ ERROR

#define ERROR (   msg,
  ... 
)
Value:
do {\
fprintf(stderr, "%s() "msg" \n", \
__func__, ##__VA_ARGS__);\
fflush(stderr);\
} while (0)

◆ ERRORNO

#define ERRORNO (   msg,
  ... 
)
Value:
do {\
fprintf(stderr, "%s() %s: "msg" \n", \
__func__, strerror(errno), ##__VA_ARGS__);\
fflush(stderr);\
} while (0)

◆ GENERIC_ALLOC_INST

#define GENERIC_ALLOC_INST (   prefix,
  _type,
  _member 
)
Value:
static int prefix##_alloc_inst(struct usbg_function_type *type, \
usbg_function_type type_code, \
const char *instance, const char *path, \
struct usbg_gadget *parent, \
struct usbg_function **f) \
{ \
_type *ff; \
int ret; \
\
ff = malloc(sizeof(*ff)); \
if (!ff) \
return USBG_ERROR_NO_MEM; \
\
ret = usbg_init_function(&ff->_member, type, type_code, \
type->name, instance, path, parent); \
if (ret != USBG_SUCCESS) \
goto free_func; \
\
*f = &ff->_member; \
\
return ret; \
\
free_func: \
free(ff); \
return ret; \
}
Definition: usbg_internal.h:51
Definition: usbg_internal.h:129
Definition: usbg_internal.h:103

◆ GENERIC_FREE_INST

#define GENERIC_FREE_INST (   prefix,
  _type,
  _member 
)
Value:
static void prefix##_free_inst(struct usbg_function_type *type, \
struct usbg_function *f) \
{ \
_type *ff = container_of(f, _type, _member); \
\
usbg_cleanup_function(&ff->_member); \
free(ff); \
}

◆ INSERT_TAILQ_STRING_ORDER

#define INSERT_TAILQ_STRING_ORDER (   HeadPtr,
  HeadType,
  NameField,
  ToInsert,
  NodeField 
)
Value:
do { \
if (TAILQ_EMPTY((HeadPtr)) || \
(strcmp((ToInsert)->NameField, TAILQ_FIRST((HeadPtr))->NameField) < 0)) \
TAILQ_INSERT_HEAD((HeadPtr), (ToInsert), NodeField); \
else if (strcmp((ToInsert)->NameField, TAILQ_LAST((HeadPtr), HeadType)->NameField) > 0) \
TAILQ_INSERT_TAIL((HeadPtr), (ToInsert), NodeField); \
else { \
typeof(ToInsert) _cur; \
TAILQ_FOREACH(_cur, (HeadPtr), NodeField) { \
if (strcmp((ToInsert)->NameField, _cur->NameField) > 0) \
continue; \
TAILQ_INSERT_BEFORE(_cur, (ToInsert), NodeField); \
break; \
} \
} \
} while (0)