X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flink-mso19%2Fapi.c;h=e283a2cb7fb9cacf94ef2409c18da3c6124eba04;hb=79bc9924d70d6c785c3ab28d35ac67f4a3601e1d;hp=a77a37e2a962899caf30d9ce831efaa88090d75d;hpb=f6beaac55ca58c406d6621038abe57c16a47e87f;p=libsigrok.git diff --git a/hardware/link-mso19/api.c b/hardware/link-mso19/api.c index a77a37e2..e283a2cb 100644 --- a/hardware/link-mso19/api.c +++ b/hardware/link-mso19/api.c @@ -51,6 +51,42 @@ static const uint64_t samplerates[] = { SR_PRIV struct sr_dev_driver link_mso19_driver_info; static struct sr_dev_driver *di = &link_mso19_driver_info; +/* TODO: Use sr_dev_inst to store connection handle & use std_dev_clear(). */ +static int dev_clear(void) +{ + GSList *l; + struct sr_dev_inst *sdi; + struct drv_context *drvc; + struct dev_context *devc; + int ret = SR_OK; + + if (!(drvc = di->priv)) + return SR_OK; + + /* Properly close and free all devices. */ + for (l = drvc->instances; l; l = l->next) { + if (!(sdi = l->data)) { + /* Log error, but continue cleaning up the rest. */ + sr_err("%s: sdi was NULL, continuing", __func__); + ret = SR_ERR_BUG; + continue; + } + if (!(devc = sdi->priv)) { + /* Log error, but continue cleaning up the rest. */ + sr_err("%s: sdi->priv was NULL, continuing", __func__); + ret = SR_ERR_BUG; + continue; + } + std_serial_dev_close(sdi); + sr_serial_dev_inst_free(devc->serial); + sr_dev_inst_free(sdi); + } + g_slist_free(drvc->instances); + drvc->instances = NULL; + + return ret; +} + static int init(struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); @@ -234,59 +270,18 @@ static int dev_open(struct sr_dev_inst *sdi) return SR_OK; } -static int dev_close(struct sr_dev_inst *sdi) -{ - struct dev_context *devc; - - devc = sdi->priv; - - if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial); - sdi->status = SR_ST_INACTIVE; - } - - return SR_OK; -} - static int cleanup(void) { - GSList *l; - struct sr_dev_inst *sdi; - struct drv_context *drvc; - struct dev_context *devc; - int ret = SR_OK; - - if (!(drvc = di->priv)) - return SR_OK; - - /* Properly close and free all devices. */ - for (l = drvc->instances; l; l = l->next) { - if (!(sdi = l->data)) { - /* Log error, but continue cleaning up the rest. */ - sr_err("%s: sdi was NULL, continuing", __func__); - ret = SR_ERR_BUG; - continue; - } - if (!(devc = sdi->priv)) { - /* Log error, but continue cleaning up the rest. */ - sr_err("%s: sdi->priv was NULL, continuing", __func__); - ret = SR_ERR_BUG; - continue; - } - dev_close(sdi); - sr_serial_dev_inst_free(devc->serial); - sr_dev_inst_free(sdi); - } - g_slist_free(drvc->instances); - drvc->instances = NULL; - - return ret; + return dev_clear(); } -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) +static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { struct dev_context *devc; + (void)probe_group; + switch (id) { case SR_CONF_SAMPLERATE: if (sdi) { @@ -302,7 +297,8 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi) return SR_OK; } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) +static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { int ret; struct dev_context *devc; @@ -310,6 +306,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) int trigger_pos; double pos; + (void)probe_group; devc = sdi->priv; if (sdi->status != SR_ST_ACTIVE) @@ -368,11 +365,13 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) return ret; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi) +static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, + const struct sr_probe_group *probe_group) { GVariant *gvar; GVariantBuilder gvb; + (void)probe_group; (void)sdi; switch (key) { @@ -458,7 +457,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* Our first probe is analog, the other 8 are of type 'logic'. */ /* TODO. */ - sr_source_add(devc->serial->fd, G_IO_IN, -1, mso_receive_data, cb_data); + serial_source_add(devc->serial, G_IO_IN, -1, mso_receive_data, cb_data); return SR_OK; } @@ -481,12 +480,12 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = { .cleanup = cleanup, .scan = scan, .dev_list = dev_list, - .dev_clear = cleanup, + .dev_clear = dev_clear, .config_get = config_get, .config_set = config_set, .config_list = config_list, .dev_open = dev_open, - .dev_close = dev_close, + .dev_close = std_serial_dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, .priv = NULL,