]> sigrok.org Git - libsigrok.git/blobdiff - hardware/genericdmm/api.c
sr: remove obsolete SR_DI_INST
[libsigrok.git] / hardware / genericdmm / api.c
index cc0059fc6778da1922cbab64150f95f7151d036d..ef5c144d1e5b05b4823973436ad7d9a0e970ff46 100644 (file)
@@ -41,14 +41,18 @@ static struct dev_profile dev_profiles[] = {
        { NULL, NULL, NULL, NULL, 0, NULL }
 };
 
+static const int hwopts[] = {
+       SR_HWOPT_MODEL,
+       SR_HWOPT_CONN,
+       SR_HWOPT_SERIALCOMM,
+       0,
+};
+
 static const int hwcaps[] = {
        SR_HWCAP_MULTIMETER,
        SR_HWCAP_LIMIT_SAMPLES,
        SR_HWCAP_LIMIT_MSEC,
        SR_HWCAP_CONTINUOUS,
-       SR_HWOPT_MODEL,
-       SR_HWOPT_CONN,
-       SR_HWOPT_SERIALCOMM,
        0,
 };
 
@@ -146,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;
                }
@@ -229,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. */
@@ -243,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;
        }
 
@@ -301,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;
@@ -347,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 */
@@ -424,91 +426,49 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static const void *hw_dev_info_get(int dev_index, int dev_info_id)
+static int hw_info_get(int info_id, const void **data,
+               const struct sr_dev_inst *sdi)
 {
-       struct sr_dev_inst *sdi;
        struct context *ctx;
-       const void *info;
 
-       if (!(sdi = sr_dev_inst_get(gdi->instances, dev_index))) {
-               sr_err("genericdmm: sdi was NULL.");
-               return NULL;
-       }
+       (void)sdi;
+       (void)ctx;
 
-       if (!(ctx = sdi->priv)) {
-               sr_err("genericdmm: sdi->priv was NULL.");
-               return NULL;
-       }
-
-               sr_spew("genericdmm: dev_index %d, dev_info_id %d.",
-                               dev_index, dev_info_id);
-
-       switch (dev_info_id) {
-       case SR_DI_INST:
-               info = sdi;
-               sr_spew("genericdmm: Returning sdi.");
+       switch (info_id) {
+       case SR_DI_HWOPTS:
+               *data = hwopts;
+               break;
+       case SR_DI_HWCAPS:
+               *data = hwcaps;
                break;
        case SR_DI_NUM_PROBES:
-               info = GINT_TO_POINTER(1);
-               sr_spew("genericdmm: Returning number of probes: 1.");
+               *data = GINT_TO_POINTER(1);
                break;
        case SR_DI_PROBE_NAMES:
-               info = probe_names;
-               sr_spew("genericdmm: Returning probenames.");
+               *data = probe_names;
                break;
        case SR_DI_CUR_SAMPLERATE:
                /* TODO get rid of this */
-               info = NULL;
-               sr_spew("genericdmm: Returning samplerate: 0.");
+               *data = NULL;
                break;
        default:
                /* Unknown device info ID. */
-               sr_err("genericdmm: Unknown device info ID: %d.", dev_info_id);
-               info = NULL;
-               break;
+               return SR_ERR_ARG;
        }
 
-       return info;
-}
-
-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 const int *hw_hwcap_get_all(void)
-{
-       sr_spew("genericdmm: Returning list of device capabilities.");
-
-       return hwcaps;
+       return SR_OK;
 }
 
-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) {
@@ -561,19 +521,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;
@@ -612,12 +567,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.");
 
@@ -638,9 +594,7 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info = {
        .scan = hw_scan,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
-       .dev_info_get = hw_dev_info_get,
-       .dev_status_get = hw_dev_status_get,
-       .hwcap_get_all = hw_hwcap_get_all,
+       .info_get = hw_info_get,
        .dev_config_set = hw_dev_config_set,
        .dev_acquisition_start = hw_dev_acquisition_start,
        .dev_acquisition_stop = hw_dev_acquisition_stop,