chronovu-la8: use driver struct-based device instance list

This commit is contained in:
Bert Vermeulen 2012-07-13 14:15:54 +02:00
parent dcf03d6dbd
commit 765ef2f725
1 changed files with 14 additions and 12 deletions

View File

@ -25,7 +25,8 @@
#include "libsigrok-internal.h" #include "libsigrok-internal.h"
#include "driver.h" #include "driver.h"
static GSList *dev_insts = NULL; SR_PRIV struct sr_dev_driver chronovu_la8_driver_info;
static struct sr_dev_driver *cdi = &chronovu_la8_driver_info;
/* /*
* The ChronoVu LA8 can have multiple PIDs. Older versions shipped with * The ChronoVu LA8 can have multiple PIDs. Older versions shipped with
@ -115,7 +116,7 @@ static int hw_scan(void)
sdi->priv = ctx; sdi->priv = ctx;
dev_insts = g_slist_append(dev_insts, sdi); cdi->instances = g_slist_append(cdi->instances, sdi);
sr_spew("la8: Device init successful."); sr_spew("la8: Device init successful.");
@ -143,7 +144,7 @@ static int hw_dev_open(int dev_index)
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct context *ctx; struct context *ctx;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__); sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR_BUG; return SR_ERR_BUG;
} }
@ -201,7 +202,7 @@ static int hw_dev_close(int dev_index)
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct context *ctx; struct context *ctx;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__); sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR_BUG; return SR_ERR_BUG;
} }
@ -236,7 +237,7 @@ static int hw_cleanup(void)
int ret = SR_OK; int ret = SR_OK;
/* Properly close all devices. */ /* Properly close all devices. */
for (l = dev_insts; l; l = l->next) { for (l = cdi->instances; l; l = l->next) {
if (!(sdi = l->data)) { if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */ /* Log error, but continue cleaning up the rest. */
sr_err("la8: %s: sdi was NULL, continuing", __func__); sr_err("la8: %s: sdi was NULL, continuing", __func__);
@ -245,8 +246,8 @@ static int hw_cleanup(void)
} }
sr_dev_inst_free(sdi); /* Returns void. */ sr_dev_inst_free(sdi); /* Returns void. */
} }
g_slist_free(dev_insts); /* Returns void. */ g_slist_free(cdi->instances); /* Returns void. */
dev_insts = NULL; cdi->instances = NULL;
return ret; return ret;
} }
@ -257,7 +258,7 @@ static const void *hw_dev_info_get(int dev_index, int dev_info_id)
struct context *ctx; struct context *ctx;
const void *info; const void *info;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__); sr_err("la8: %s: sdi was NULL", __func__);
return NULL; return NULL;
} }
@ -313,7 +314,7 @@ static int hw_dev_status_get(int dev_index)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL, device not found", __func__); sr_err("la8: %s: sdi was NULL, device not found", __func__);
return SR_ST_NOT_FOUND; return SR_ST_NOT_FOUND;
} }
@ -335,7 +336,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, const void *value)
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct context *ctx; struct context *ctx;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__); sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR_BUG; return SR_ERR_BUG;
} }
@ -447,7 +448,7 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
uint8_t buf[4]; uint8_t buf[4];
int bytes_written; int bytes_written;
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__); sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR_BUG; return SR_ERR_BUG;
} }
@ -526,7 +527,7 @@ static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
sr_dbg("la8: Stopping acquisition."); sr_dbg("la8: Stopping acquisition.");
if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { if (!(sdi = sr_dev_inst_get(cdi->instances, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__); sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR_BUG; return SR_ERR_BUG;
} }
@ -559,4 +560,5 @@ SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = {
.dev_config_set = hw_dev_config_set, .dev_config_set = hw_dev_config_set,
.dev_acquisition_start = hw_dev_acquisition_start, .dev_acquisition_start = hw_dev_acquisition_start,
.dev_acquisition_stop = hw_dev_acquisition_stop, .dev_acquisition_stop = hw_dev_acquisition_stop,
.instances = NULL,
}; };