]> sigrok.org Git - libsigrok.git/commitdiff
alsa: Adjust to GVariant-based sr_config_* functions
authorBert Vermeulen <redacted>
Sun, 31 Mar 2013 18:55:39 +0000 (20:55 +0200)
committerBert Vermeulen <redacted>
Thu, 11 Apr 2013 16:32:07 +0000 (18:32 +0200)
hardware/alsa/api.c
hardware/alsa/protocol.c
hardware/alsa/protocol.h

index e2efbf468dc944b21f56f7ac7b91808c4552d39f..39ab74d139480f3e852f7fa44f3e0a4a556c8c94 100644 (file)
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-static const int hwcaps[] = {
+static const int32_t hwcaps[] = {
        SR_CONF_SAMPLERATE,
        SR_CONF_LIMIT_SAMPLES,
        SR_CONF_CONTINUOUS,
-       0,
 };
 
 SR_PRIV struct sr_dev_driver alsa_driver_info;
@@ -124,14 +123,14 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
+static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
        switch (id) {
        case SR_CONF_SAMPLERATE:
                devc = sdi->priv;
-               *data = &devc->cur_samplerate;
+               *data = g_variant_new_uint64(devc->cur_samplerate);
                break;
        default:
                return SR_ERR_ARG;
@@ -140,7 +139,7 @@ static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
+static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
@@ -148,10 +147,10 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
 
        switch (id) {
        case SR_CONF_SAMPLERATE:
-               alsa_set_samplerate(sdi, *(const uint64_t *)value);
+               alsa_set_samplerate(sdi, g_variant_get_uint64(data));
                break;
        case SR_CONF_LIMIT_SAMPLES:
-               devc->limit_samples = *(const uint64_t *)value;
+               devc->limit_samples = g_variant_get_uint64(data);
                break;
        default:
                sr_err("Unknown capability: %d.", id);
@@ -161,25 +160,35 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static int config_list(int key, const void **data, const struct sr_dev_inst *sdi)
+static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       GVariant *gvar;
+       GVariantBuilder gvb;
+       int i;
 
        (void)sdi;
 
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
-               *data = hwcaps;
+               *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+                               hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
                break;
        case SR_CONF_SAMPLERATE:
                if (!sdi || !sdi->priv)
                        return SR_ERR_ARG;
                devc = sdi->priv;
-               if (!devc->supp_rates.list) {
+               if (!devc->samplerates) {
                        sr_err("Instance did not contain a samplerate list.");
                        return SR_ERR_ARG;
                }
-               *data = &devc->supp_rates;
+               for (i = 0; devc->samplerates[i]; i++)
+                       ;
+               g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
+               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
+                               devc->samplerates, i, sizeof(uint64_t));
+               g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
+               *data = g_variant_builder_end(&gvb);
                break;
        default:
                return SR_ERR_ARG;
index 2d95f8cb17565977c08e84451976c5926bb3716a..74326205042a48511e5a5a824152c5d058b7ca55 100644 (file)
@@ -152,7 +152,7 @@ static void alsa_scan_handle_dev(GSList **devices,
        devc->num_probes = channels;
        devc->hw_params = hw_params;
        memcpy(devrates, hwrates, offset * sizeof(uint64_t));
-       devc->supp_rates.list = devrates;
+       devc->samplerates = devrates;
 
        sdi->priv = devc;
        sdi->driver = di;
@@ -294,7 +294,7 @@ SR_PRIV void alsa_dev_inst_clear(struct sr_dev_inst *sdi)
                return;
 
        snd_pcm_hw_params_free(devc->hw_params);
-       g_free((void*)devc->supp_rates.list);
+       g_free((void*)devc->samplerates);
        sr_dev_inst_free(sdi);
 }
 
@@ -326,11 +326,11 @@ SR_PRIV int alsa_set_samplerate(const struct sr_dev_inst *sdi,
 
        i = 0;
        do {
-               if (newrate == devc->supp_rates.list[i]) {
+               if (newrate == devc->samplerates[i]) {
                        rate = newrate;
                        break;
                }
-       } while (devc->supp_rates.list[i++] != 0);
+       } while (devc->samplerates[i++] != 0);
 
        if (!rate) {
                sr_err("Sample rate %" PRIu64 " not supported.", newrate);
index 92d2ba68c1d6dcafee8ce59a20e445e261d063bd..f7d047bb1268b714710f4998a69d9e2527f53acb 100644 (file)
@@ -43,7 +43,7 @@ struct dev_context {
        uint64_t limit_samples;
        uint64_t num_samples;
        uint8_t num_probes;
-       struct sr_samplerates supp_rates;
+       uint64_t *samplerates;
        char *hwdev;
        snd_pcm_t *capture_handle;
        snd_pcm_hw_params_t *hw_params;