]> sigrok.org Git - libsigrok.git/blobdiff - src/session_driver.c
virtual-session: Advertise all config keys
[libsigrok.git] / src / session_driver.c
index 6a320aa5b3d17908dc401fa75bea5bd1ec0d3853..c1706bb5dec68956bdb079f9f99c2657c2ea76f6 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/time.h>
 #include <zip.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
 
 #define LOG_PREFIX "virtual-session"
@@ -34,7 +35,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 +49,12 @@ struct session_vdev {
        gboolean finished;
 };
 
-static const uint32_t 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_NUM_LOGIC_CHANNELS | SR_CONF_SET,
+       SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_SESSIONFILE | SR_CONF_SET,
 };
 
 static int receive_data(int fd, int revents, void *cb_data)
@@ -118,10 +120,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 +164,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 +185,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);
@@ -216,13 +217,17 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s
 
        (void)cg;
 
+       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;
@@ -277,7 +282,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        switch (key) {
        case SR_CONF_DEVICE_OPTIONS:
                *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                               hwcaps, ARRAY_SIZE(hwcaps), sizeof(uint32_t));
+                               devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
                break;
        default:
                return SR_ERR_NA;
@@ -333,5 +338,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,
 };