X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fstd.c;h=a03e509c732b4c0693ef6ee69638bffa9acc236a;hb=7e2f42214a72bb3ad2b4ce1767ff8945fa83fe97;hp=b66ed8f0b4884c603d4e235a972775c1a1ab40c6;hpb=700d6b64d578ce10e57f6a2289e37a5564eccf1c;p=libsigrok.git diff --git a/src/std.c b/src/std.c index b66ed8f0..a03e509c 100644 --- a/src/std.c +++ b/src/std.c @@ -39,22 +39,15 @@ * It creates a new 'struct drv_context' (drvc), assigns sr_ctx to it, and * then 'drvc' is assigned to the 'struct sr_dev_driver' (di) that is passed. * - * @param sr_ctx The libsigrok context to assign. * @param di The driver instance to use. - * @param[in] prefix A driver-specific prefix string used for log messages. + * @param sr_ctx The libsigrok context to assign. * * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments. */ -SR_PRIV int std_init(struct sr_context *sr_ctx, struct sr_dev_driver *di, - const char *prefix) +SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { struct drv_context *drvc; - if (!di) { - sr_err("%s: Invalid driver, cannot initialize.", prefix); - return SR_ERR_ARG; - } - drvc = g_malloc0(sizeof(struct drv_context)); drvc->sr_ctx = sr_ctx; drvc->instances = NULL; @@ -337,3 +330,22 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver, return ret; } + +/** + * Standard implementation for the driver dev_list() callback + * + * This function can be used as the dev_list callback by most drivers that use + * the standard helper functions. It returns the devices contained in the driver + * context instances list. + * + * @param di The driver instance to use. + * + * @return The list of devices/instances of this driver, or NULL upon errors + * or if the list is empty. + */ +SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di) +{ + struct drv_context *drvc = di->context; + + return drvc->instances; +}