]> sigrok.org Git - libsigrok.git/blobdiff - hardware/genericdmm/api.c
sr/drivers: remove driver API call dev_status_get()
[libsigrok.git] / hardware / genericdmm / api.c
index 5bcf11dd39437670eb46758d629005df77afa22c..a8e13beeff7c119e29608cb5aec049ea4de733ff 100644 (file)
@@ -150,7 +150,7 @@ static GSList *connect_usb(const char *conn)
 
                devcnt = g_slist_length(gdi->instances);
                if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_ACTIVE,
-                               "Generic DMM", NULL, NULL))) {
+                               NULL, NULL, NULL))) {
                        sr_err("genericdmm: sr_dev_inst_new returned NULL.");
                        return NULL;
                }
@@ -233,6 +233,7 @@ static GSList *hw_scan(GSList *options)
        GSList *l, *ldef, *defopts, *newopts, *devices;
        struct sr_hwopt *opt, *defopt;
        struct dev_profile *pr, *profile;
+       struct sr_dev_inst *sdi;
        const char *model;
 
        /* Separate model from the options list. */
@@ -247,7 +248,7 @@ static GSList *hw_scan(GSList *options)
                        newopts = g_slist_append(newopts, opt);
        }
        if (!model) {
-               sr_err("Need a model to scan for.");
+               /* This driver only works when a model is specified. */
                return NULL;
        }
 
@@ -305,24 +306,29 @@ static GSList *hw_scan(GSList *options)
 
        if (devices) {
                /* TODO: need to fix up sdi->index fields */
-               /* Add a copy of these new devices to the driver instances. */
-               for (l = devices; l; l = l->next)
+               for (l = devices; l; l = l->next) {
+                       /* The default connection-based scanner doesn't really
+                        * know about profiles, so it never filled in the vendor
+                        * or model. Do that now.
+                        */
+                       sdi = l->data;
+                       sdi->driver = gdi;
+                       if (!sdi->vendor)
+                               sdi->vendor = g_strdup(profile->vendor);
+                       if (!sdi->model)
+                               sdi->model = g_strdup(profile->model);
+                       /* Add a copy of these new devices to the driver instances. */
                        gdi->instances = g_slist_append(gdi->instances, l->data);
+               }
        }
 
        return devices;
 }
 
-static int hw_dev_open(int dev_index)
+static int hw_dev_open(struct sr_dev_inst *sdi)
 {
-       struct sr_dev_inst *sdi;
        struct context *ctx;
 
-       if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
-               sr_err("genericdmm: sdi was NULL.");
-               return SR_ERR_BUG;
-       }
-
        if (!(ctx = sdi->priv)) {
                sr_err("genericdmm: sdi->priv was NULL.");
                return SR_ERR_BUG;
@@ -351,23 +357,15 @@ static int hw_dev_open(int dev_index)
        return SR_OK;
 }
 
-static int hw_dev_close(int dev_index)
+static int hw_dev_close(struct sr_dev_inst *sdi)
 {
-       struct sr_dev_inst *sdi;
        struct context *ctx;
 
-       if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
-               sr_err("genericdmm: %s: sdi was NULL.", __func__);
-               return SR_ERR_BUG;
-       }
-
        if (!(ctx = sdi->priv)) {
                sr_err("genericdmm: %s: sdi->priv was NULL.", __func__);
                return SR_ERR_BUG;
        }
 
-       /* TODO: Check for != NULL. */
-
        switch (ctx->profile->transport) {
        case DMM_TRANSPORT_USBHID:
                /* TODO */
@@ -428,12 +426,12 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static int hw_info_get(int dev_info_id, const void **data,
+static int hw_info_get(int info_id, const void **data,
                const struct sr_dev_inst *sdi)
 {
        struct context *ctx;
 
-       switch (dev_info_id) {
+       switch (info_id) {
        case SR_DI_INST:
                *data = sdi;
                sr_spew("genericdmm: Returning sdi.");
@@ -462,37 +460,16 @@ static int hw_info_get(int dev_info_id, const void **data,
        return SR_OK;
 }
 
-static int hw_dev_status_get(int dev_index)
-{
-       struct sr_dev_inst *sdi;
-
-       if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
-               sr_err("genericdmm: sdi was NULL, device not found.");
-               return SR_ST_NOT_FOUND;
-       }
-
-       sr_dbg("genericdmm: Returning status: %d.", sdi->status);
-
-       return sdi->status;
-}
-
-static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
+static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
+               const void *value)
 {
-       struct sr_dev_inst *sdi;
        struct context *ctx;
 
-       if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
-               sr_err("genericdmm: sdi was NULL.");
-               return SR_ERR_BUG;
-       }
-
        if (!(ctx = sdi->priv)) {
                sr_err("genericdmm: sdi->priv was NULL.");
                return SR_ERR_BUG;
        }
 
-       sr_spew("genericdmm: dev_index %d, hwcap %d.", dev_index, hwcap);
-
        switch (hwcap) {
        case SR_HWCAP_LIMIT_MSEC:
                if (*(const uint64_t *)value == 0) {
@@ -545,19 +522,14 @@ static int receive_data(int fd, int revents, void *cb_data)
        return TRUE;
 }
 
-static int hw_dev_acquisition_start(int dev_index, void *cb_data)
+static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
+               void *cb_data)
 {
        struct sr_datafeed_packet packet;
        struct sr_datafeed_header header;
        struct sr_datafeed_meta_analog meta;
-       struct sr_dev_inst *sdi;
        struct context *ctx;
 
-       if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
-               sr_err("genericdmm: sdi was NULL.");
-               return SR_ERR_BUG;
-       }
-
        if (!(ctx = sdi->priv)) {
                sr_err("genericdmm: sdi->priv was NULL.");
                return SR_ERR_BUG;
@@ -596,12 +568,13 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
        return SR_OK;
 }
 
-static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
+static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
+               void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
        /* Avoid compiler warnings. */
-       (void)dev_index;
+       (void)sdi;
 
        sr_dbg("genericdmm: Stopping acquisition.");
 
@@ -623,7 +596,6 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info = {
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .info_get = hw_info_get,
-       .dev_status_get = hw_dev_status_get,
        .dev_config_set = hw_dev_config_set,
        .dev_acquisition_start = hw_dev_acquisition_start,
        .dev_acquisition_stop = hw_dev_acquisition_stop,