From: Bert Vermeulen Date: Mon, 16 Jul 2012 01:52:14 +0000 (+0200) Subject: sr/drivers: use sr_dev_inst instead of device index for dev_config_set() X-Git-Tag: dsupstream~788 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6f4b1868e8ec8c132878d8b6d558f4af054cbd91;p=libsigrok.git sr/drivers: use sr_dev_inst instead of device index for dev_config_set() All driver API calls using device index as a parameter will instead use a const struct sr_dev_inst. --- diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 42526214..4f802cac 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -633,7 +633,7 @@ static int hw_dev_open(int dev_index) return SR_OK; } -static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) +static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { int i, ret; struct context *ctx = sdi->priv; @@ -674,7 +674,7 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) * The Sigma supports complex triggers using boolean expressions, but this * has not been implemented yet. */ -static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes) +static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes) { struct context *ctx = sdi->priv; const struct sr_probe *probe; @@ -829,15 +829,12 @@ static int hw_dev_status_get(int dev_index) return SR_ST_NOT_FOUND; } -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; int ret; - if (!(sdi = sr_dev_inst_get(adi->instances, dev_index))) - return SR_ERR; - ctx = sdi->priv; if (hwcap == SR_HWCAP_SAMPLERATE) { diff --git a/hardware/chronovu-la8/api.c b/hardware/chronovu-la8/api.c index 219cb6c8..4b8d9d39 100644 --- a/hardware/chronovu-la8/api.c +++ b/hardware/chronovu-la8/api.c @@ -330,23 +330,16 @@ static int hw_dev_status_get(int dev_index) 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(cdi->instances, dev_index))) { - sr_err("la8: %s: sdi was NULL", __func__); - return SR_ERR_BUG; - } - if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR_BUG; } - sr_spew("la8: %s: dev_index %d, hwcap %d", __func__, dev_index, hwcap); - switch (hwcap) { case SR_HWCAP_SAMPLERATE: if (set_samplerate(sdi, *(const uint64_t *)value) == SR_ERR) { diff --git a/hardware/chronovu-la8/driver.c b/hardware/chronovu-la8/driver.c index e49c0973..168bb73a 100644 --- a/hardware/chronovu-la8/driver.c +++ b/hardware/chronovu-la8/driver.c @@ -378,7 +378,7 @@ SR_PRIV int configure_probes(struct context *ctx, const GSList *probes) return SR_OK; } -SR_PRIV int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) +SR_PRIV int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { struct context *ctx; diff --git a/hardware/chronovu-la8/driver.h b/hardware/chronovu-la8/driver.h index 0da07e47..ea89645a 100644 --- a/hardware/chronovu-la8/driver.h +++ b/hardware/chronovu-la8/driver.h @@ -116,7 +116,7 @@ SR_PRIV int la8_close(struct context *ctx); SR_PRIV int la8_close_usb_reset_sequencer(struct context *ctx); SR_PRIV int la8_reset(struct context *ctx); SR_PRIV int configure_probes(struct context *ctx, const GSList *probes); -SR_PRIV int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate); +SR_PRIV int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate); SR_PRIV int la8_read_block(struct context *ctx); SR_PRIV void send_block_to_session_bus(struct context *ctx, int block); diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index e6e168fc..24c91838 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -237,13 +237,13 @@ static int hw_dev_status_get(int dev_index) return SR_ST_ACTIVE; } -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) { int ret; const char *stropt; - /* Avoid compiler warnings. */ - (void)dev_index; + (void)sdi; if (hwcap == SR_HWCAP_PROBECONFIG) { /* Nothing to do, but must be supported */ diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index d7fdf2f5..2cf9c0f5 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -143,7 +143,8 @@ static libusb_context *usb_context = NULL; SR_PRIV struct sr_dev_driver fx2lafw_driver_info; static struct sr_dev_driver *fdi = &fx2lafw_driver_info; -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); static int hw_dev_acquisition_stop(int dev_index, void *cb_data); /** @@ -575,7 +576,7 @@ static int hw_dev_open(int dev_index) if (ctx->cur_samplerate == 0) { /* Samplerate hasn't been set; default to the slowest one. */ - if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE, + if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE, &supported_samplerates[0]) == SR_ERR) return SR_ERR; } @@ -666,14 +667,12 @@ static int hw_dev_status_get(int dev_index) 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; int ret; - if (!(sdi = sr_dev_inst_get(fdi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; if (hwcap == SR_HWCAP_SAMPLERATE) { diff --git a/hardware/genericdmm/api.c b/hardware/genericdmm/api.c index 2dab4b87..f29aafd1 100644 --- a/hardware/genericdmm/api.c +++ b/hardware/genericdmm/api.c @@ -488,23 +488,16 @@ static int hw_dev_status_get(int dev_index) 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) { diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 4fd07eab..d1b2f9b6 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -444,9 +444,9 @@ static int hw_dev_status_get(int dev_index) 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; struct sr_rational tmp_rat; float tmp_float; @@ -454,9 +454,6 @@ static int hw_dev_config_set(int dev_index, int hwcap, const void *value) int ret, i; char **targets; - if (!(sdi = sr_dev_inst_get(hdi->instances, dev_index))) - return SR_ERR; - if (sdi->status != SR_ST_ACTIVE) return SR_ERR; diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index d2cda236..b1bcfa55 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -632,7 +632,7 @@ static int hw_dev_status_get(int dev_index) return sdi->status; } -static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) +static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { struct context *ctx; @@ -664,15 +664,13 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) 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; int ret; const uint64_t *tmp_u64; - if (!(sdi = sr_dev_inst_get(odi->instances, dev_index))) - return SR_ERR; ctx = sdi->priv; if (sdi->status != SR_ST_ACTIVE) diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index dd484a58..a029a3cb 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -159,7 +159,8 @@ struct context { struct sr_usb_dev_inst *usb; }; -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); static unsigned int get_memory_size(int type) { @@ -284,7 +285,7 @@ static void close_dev(struct sr_dev_inst *sdi) sdi->status = SR_ST_INACTIVE; } -static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes) +static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes) { struct context *ctx; const struct sr_probe *probe; @@ -482,7 +483,7 @@ static int hw_dev_open(int dev_index) if (ctx->cur_samplerate == 0) { /* Samplerate hasn't been set. Default to the slowest one. */ - if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE, + if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE, &samplerates.list[0]) == SR_ERR) return SR_ERR; } @@ -578,7 +579,7 @@ static int hw_dev_status_get(int dev_index) return SR_ST_NOT_FOUND; } -static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) +static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate) { struct context *ctx; @@ -606,16 +607,11 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) 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(zdi->instances, dev_index))) { - sr_err("zp: %s: sdi was NULL", __func__); - return SR_ERR; - } - if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; diff --git a/libsigrok.h b/libsigrok.h index 641ca912..9a6ec097 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -497,7 +497,8 @@ struct sr_dev_driver { int (*info_get) (int dev_info_id, const void **data, const struct sr_dev_inst *sdi); int (*dev_status_get) (int dev_index); - int (*dev_config_set) (int dev_index, int hwcap, const void *value); + int (*dev_config_set) (const struct sr_dev_inst *sdi, int hwcap, + const void *value); int (*dev_acquisition_start) (int dev_index, void *session_dev_id); int (*dev_acquisition_stop) (int dev_index, void *session_dev_id); diff --git a/session_driver.c b/session_driver.c index 64ec06d1..ce5c665c 100644 --- a/session_driver.c +++ b/session_driver.c @@ -224,13 +224,13 @@ static int hw_dev_status_get(int dev_index) return SR_ERR; } -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 session_vdev *vdev; const uint64_t *tmp_u64; - if (!(vdev = get_vdev_by_index(dev_index))) - return SR_ERR; + vdev = sdi->priv; switch (hwcap) { case SR_HWCAP_SAMPLERATE: