X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fsession_driver.c;h=72011d2f3775243a1a7b48b7584a506f4fff5e0b;hb=82b01e42f8c1bace29fb273417571543548618ad;hp=9120ea14575b4f2e71fbfa3d0fcdfc28100b8467;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git diff --git a/src/session_driver.c b/src/session_driver.c index 9120ea14..72011d2f 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -23,7 +23,7 @@ #include #include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" #define LOG_PREFIX "virtual-session" @@ -34,7 +34,6 @@ /** @endcond */ SR_PRIV struct sr_dev_driver session_driver_info; -static struct sr_dev_driver *di = &session_driver_info; struct session_vdev { char *sessionfile; @@ -49,10 +48,10 @@ struct session_vdev { gboolean finished; }; -static const int hwcaps[] = { - SR_CONF_CAPTUREFILE, - SR_CONF_CAPTURE_UNITSIZE, - SR_CONF_SAMPLERATE, +static const uint32_t devopts[] = { + SR_CONF_CAPTUREFILE | SR_CONF_SET, + SR_CONF_CAPTURE_UNITSIZE | SR_CONF_GET | SR_CONF_SET, + SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET, }; static int receive_data(int fd, int revents, void *cb_data) @@ -118,10 +117,7 @@ static int receive_data(int fd, int revents, void *cb_data) } } - if (!(buf = g_try_malloc(CHUNKSIZE))) { - sr_err("%s: buf malloc failed", __func__); - return FALSE; - } + buf = g_malloc(CHUNKSIZE); ret = zip_fread(vdev->capfile, buf, CHUNKSIZE / vdev->unitsize * vdev->unitsize); @@ -165,17 +161,17 @@ static int receive_data(int fd, int revents, void *cb_data) /* driver callbacks */ -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { struct drv_context *drvc; GSList *l; - drvc = di->priv; + drvc = di->context; for (l = drvc->instances; l; l = l->next) sr_dev_inst_free(l->data); g_slist_free(drvc->instances); @@ -186,10 +182,12 @@ static int dev_clear(void) static int dev_open(struct sr_dev_inst *sdi) { + struct sr_dev_driver *di; struct drv_context *drvc; struct session_vdev *vdev; - drvc = di->priv; + di = sdi->driver; + drvc = di->context; vdev = g_malloc0(sizeof(struct session_vdev)); sdi->priv = vdev; drvc->instances = g_slist_append(drvc->instances, sdi); @@ -209,20 +207,24 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, +static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct session_vdev *vdev; (void)cg; - switch (id) { + if (!sdi) + return SR_ERR; + + vdev = sdi->priv; + + switch (key) { case SR_CONF_SAMPLERATE: - if (sdi) { - vdev = sdi->priv; - *data = g_variant_new_uint64(vdev->samplerate); - } else - return SR_ERR; + *data = g_variant_new_uint64(vdev->samplerate); + break; + case SR_CONF_CAPTURE_UNITSIZE: + *data = g_variant_new_uint64(vdev->unitsize); break; default: return SR_ERR_NA; @@ -231,7 +233,7 @@ 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(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct session_vdev *vdev; @@ -240,7 +242,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, vdev = sdi->priv; - switch (id) { + switch (key) { case SR_CONF_SAMPLERATE: vdev->samplerate = g_variant_get_uint64(data); sr_info("Setting samplerate to %" PRIu64 ".", vdev->samplerate); @@ -268,7 +270,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, return SR_OK; } -static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, +static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { (void)sdi; @@ -276,8 +278,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, switch (key) { case SR_CONF_DEVICE_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); break; default: return SR_ERR_NA; @@ -333,5 +335,5 @@ SR_PRIV struct sr_dev_driver session_driver = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = NULL, - .priv = NULL, + .context = NULL, };