libsigrok: closedev() now has a return code.
This is useful to allow frontends to react upon close failures in a way they see fit (e.g. a popup in the GUI, or error message in the CLI). They can also still ignore the error if they want, of course.
This commit is contained in:
parent
1352eeddd4
commit
697785d1ae
10
device.c
10
device.c
|
@ -61,12 +61,18 @@ int sr_device_plugin_init(struct sr_device_plugin *plugin)
|
||||||
|
|
||||||
void sr_device_close_all(void)
|
void sr_device_close_all(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
struct sr_device *device;
|
struct sr_device *device;
|
||||||
|
|
||||||
while (devices) {
|
while (devices) {
|
||||||
device = devices->data;
|
device = devices->data;
|
||||||
if (device->plugin && device->plugin->closedev)
|
if (device->plugin && device->plugin->closedev) {
|
||||||
device->plugin->closedev(device->plugin_index);
|
ret = device->plugin->closedev(device->plugin_index);
|
||||||
|
if (ret != SR_OK) {
|
||||||
|
sr_err("dev: %s: could not close device %d",
|
||||||
|
__func__, device->plugin_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
sr_device_destroy(device);
|
sr_device_destroy(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,21 +108,28 @@ static int hw_opendev(int device_index)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
struct alsa *alsa;
|
struct alsa *alsa;
|
||||||
|
|
||||||
if (!(sdi = sr_get_device_instance(device_instances, device_index)))
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
return;
|
sr_err("alsa: %s: sdi was NULL", __func__);
|
||||||
alsa = sdi->priv;
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
if (!alsa)
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
|
if (!(alsa = sdi->priv)) {
|
||||||
|
sr_err("alsa: %s: sdi->priv was NULL", __func__);
|
||||||
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Return values of snd_*?
|
||||||
if (alsa->hw_params)
|
if (alsa->hw_params)
|
||||||
snd_pcm_hw_params_free(alsa->hw_params);
|
snd_pcm_hw_params_free(alsa->hw_params);
|
||||||
if (alsa->capture_handle)
|
if (alsa->capture_handle)
|
||||||
snd_pcm_close(alsa->capture_handle);
|
snd_pcm_close(alsa->capture_handle);
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
|
@ -675,19 +675,28 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
struct sigma *sigma;
|
struct sigma *sigma;
|
||||||
|
|
||||||
if ((sdi = sr_get_device_instance(device_instances, device_index)))
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
{
|
sr_err("asix: %s: sdi was NULL", __func__);
|
||||||
sigma = sdi->priv;
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
if (sdi->status == SR_ST_ACTIVE)
|
|
||||||
ftdi_usb_close(&sigma->ftdic);
|
|
||||||
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(sigma = sdi->priv)) {
|
||||||
|
sr_err("asix: %s: sdi->priv was NULL", __func__);
|
||||||
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
|
if (sdi->status == SR_ST_ACTIVE)
|
||||||
|
ftdi_usb_close(&sigma->ftdic);
|
||||||
|
|
||||||
|
sdi->status = SR_ST_INACTIVE;
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
|
@ -632,25 +632,26 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
struct la8 *la8;
|
struct la8 *la8;
|
||||||
|
|
||||||
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
sr_err("la8: %s: sdi was NULL", __func__);
|
sr_err("la8: %s: sdi was NULL", __func__);
|
||||||
return;
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(la8 = sdi->priv)) {
|
if (!(la8 = sdi->priv)) {
|
||||||
sr_err("la8: %s: sdi->priv was NULL", __func__);
|
sr_err("la8: %s: sdi->priv was NULL", __func__);
|
||||||
return;
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
}
|
}
|
||||||
|
|
||||||
sr_dbg("la8: closing device");
|
sr_dbg("la8: closing device");
|
||||||
|
|
||||||
if (sdi->status == SR_ST_ACTIVE) {
|
if (sdi->status == SR_ST_ACTIVE) {
|
||||||
sr_dbg("la8: %s: status ACTIVE, closing device", __func__);
|
sr_dbg("la8: %s: status ACTIVE, closing device", __func__);
|
||||||
|
/* TODO: Really ignore errors here, or return SR_ERR? */
|
||||||
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
|
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
|
||||||
} else {
|
} else {
|
||||||
sr_dbg("la8: %s: status not ACTIVE, nothing to do", __func__);
|
sr_dbg("la8: %s: status not ACTIVE, nothing to do", __func__);
|
||||||
|
@ -660,6 +661,8 @@ static void hw_closedev(int device_index)
|
||||||
|
|
||||||
sr_dbg("la8: %s: freeing sample buffers", __func__);
|
sr_dbg("la8: %s: freeing sample buffers", __func__);
|
||||||
free(la8->final_buf);
|
free(la8->final_buf);
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
|
@ -121,15 +121,18 @@ static int hw_opendev(int device_index)
|
||||||
device_index = device_index;
|
device_index = device_index;
|
||||||
|
|
||||||
/* Nothing needed so far. */
|
/* Nothing needed so far. */
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
/* Avoid compiler warnings. */
|
/* Avoid compiler warnings. */
|
||||||
device_index = device_index;
|
device_index = device_index;
|
||||||
|
|
||||||
/* Nothing needed so far. */
|
/* Nothing needed so far. */
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
|
@ -539,18 +539,23 @@ static int hw_opendev(int device_index)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
|
|
||||||
if (!(sdi = sr_get_device_instance(device_instances, device_index)))
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
return;
|
sr_err("mso19: %s: sdi was NULL", __func__);
|
||||||
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
if (sdi->serial->fd != -1) {
|
if (sdi->serial->fd != -1) {
|
||||||
serial_close(sdi->serial->fd);
|
serial_close(sdi->serial->fd);
|
||||||
sdi->serial->fd = -1;
|
sdi->serial->fd = -1;
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *hw_get_device_info(int device_index, int device_info_id)
|
static void *hw_get_device_info(int device_index, int device_info_id)
|
||||||
|
|
|
@ -458,18 +458,23 @@ static int hw_opendev(int device_index)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
|
|
||||||
if (!(sdi = sr_get_device_instance(device_instances, device_index)))
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
return;
|
sr_err("ols: %s: sdi was NULL", __func__);
|
||||||
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
if (sdi->serial->fd != -1) {
|
if (sdi->serial->fd != -1) {
|
||||||
serial_close(sdi->serial->fd);
|
serial_close(sdi->serial->fd);
|
||||||
sdi->serial->fd = -1;
|
sdi->serial->fd = -1;
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
|
@ -394,12 +394,19 @@ static int hw_opendev(int device_index)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
|
|
||||||
if ((sdi = sr_get_device_instance(device_instances, device_index)))
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
close_device(sdi);
|
sr_err("logic: %s: sdi was NULL", __func__);
|
||||||
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
|
close_device(sdi);
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
|
@ -370,12 +370,19 @@ static int hw_opendev(int device_index)
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_closedev(int device_index)
|
static int hw_closedev(int device_index)
|
||||||
{
|
{
|
||||||
struct sr_device_instance *sdi;
|
struct sr_device_instance *sdi;
|
||||||
|
|
||||||
if ((sdi = sr_get_device_instance(device_instances, device_index)))
|
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
|
||||||
close_device(sdi);
|
sr_err("lap-c: %s: sdi was NULL", __func__);
|
||||||
|
return SR_ERR; /* TODO: SR_ERR_ARG? */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
|
close_device(sdi);
|
||||||
|
|
||||||
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hw_cleanup(void)
|
static void hw_cleanup(void)
|
||||||
|
|
2
sigrok.h
2
sigrok.h
|
@ -335,7 +335,7 @@ struct sr_device_plugin {
|
||||||
|
|
||||||
/* Device-specific */
|
/* Device-specific */
|
||||||
int (*opendev) (int device_index);
|
int (*opendev) (int device_index);
|
||||||
void (*closedev) (int device_index);
|
int (*closedev) (int device_index);
|
||||||
void *(*get_device_info) (int device_index, int device_info_id);
|
void *(*get_device_info) (int device_index, int device_info_id);
|
||||||
int (*get_status) (int device_index);
|
int (*get_status) (int device_index);
|
||||||
int *(*get_capabilities) (void);
|
int *(*get_capabilities) (void);
|
||||||
|
|
Loading…
Reference in New Issue