]> sigrok.org Git - libsigrok.git/blobdiff - hardware/demo/demo.c
fx2lafw: Keep track of our own libusb fds
[libsigrok.git] / hardware / demo / demo.c
index 0245e185bfcab39e905c340967b5dafc17bd8a30..1328c4cfc586869d18b5d9db46bfcd76afbfbdfc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
  * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
@@ -212,7 +212,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 {
        (void)sdi;
 
-       /* Nothing needed so far. */
+       sdi->status = SR_ST_ACTIVE;
 
        return SR_OK;
 }
@@ -221,7 +221,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 {
        (void)sdi;
 
-       /* Nothing needed so far. */
+    sdi->status = SR_ST_INACTIVE;
 
        return SR_OK;
 }
@@ -286,7 +286,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
                }
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;
@@ -299,6 +299,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 
        struct dev_context *const devc = sdi->priv;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        if (id == SR_CONF_SAMPLERATE) {
                devc->cur_samplerate = g_variant_get_uint64(data);
                sr_dbg("%s: setting samplerate to %" PRIu64, __func__,
@@ -335,7 +338,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
                sr_dbg("%s: setting pattern to %d",
                        __func__, devc->sample_generator);
        } else {
-               ret = SR_ERR;
+               ret = SR_ERR_NA;
        }
 
        return ret;
@@ -364,7 +367,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
                *data = g_variant_new_strv(pattern_strings, ARRAY_SIZE(pattern_strings));
                break;
        default:
-               return SR_ERR_ARG;
+               return SR_ERR_NA;
        }
 
        return SR_OK;
@@ -460,6 +463,9 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct dev_context *const devc = sdi->priv;
 
+       if (sdi->status != SR_ST_ACTIVE)
+               return SR_ERR_DEV_CLOSED;
+
        devc->cb_data = cb_data;
        devc->samples_counter = 0;