]> sigrok.org Git - libsigrok.git/blobdiff - hardware/alsa/api.c
Enforce open device before config_set()/dev_acquisition_start()
[libsigrok.git] / hardware / alsa / api.c
index 2e674fff6e3fe151aa2233108212aeab11ccfe3b..43d9b51b5543484605f11826682f076ad8e4f27e 100644 (file)
@@ -92,6 +92,8 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
                return SR_ERR;
        }
 
+       sdi->status = SR_ST_ACTIVE;
+
        return SR_OK;
 }
 
@@ -108,6 +110,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
                        sr_err("Failed to close device: %s.",
                               snd_strerror(ret));
                        devc->capture_handle = NULL;
+            sdi->status = SR_ST_INACTIVE;
                }
        } else {
                sr_dbg("No capture handle, no need to close audio device.");
@@ -143,6 +146,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
 
        switch (id) {
@@ -203,6 +209,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        int count, ret;
        char *endianness;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc = sdi->priv;
        devc->cb_data = cb_data;
        devc->num_samples = 0;