]> sigrok.org Git - libsigrok.git/blobdiff - hardware/demo/demo.c
sr: More callback param renames.
[libsigrok.git] / hardware / demo / demo.c
index c1b5b5cf0890321fd7626d67dc2417f2c54d9ce3..e43613843a077970e00220d99e1e25508e97c058 100644 (file)
@@ -72,7 +72,7 @@ struct databag {
        uint8_t thread_running;
        uint64_t samples_counter;
        int dev_index;
-       gpointer session_data;
+       void *session_dev_id;
        GTimer *timer;
 };
 
@@ -102,6 +102,7 @@ static const char *pattern_strings[] = {
        NULL,
 };
 
+/* We name the probes 0-7 on our demo driver. */
 static const char *probe_names[NUM_PROBES + 1] = {
        "0",
        "1",
@@ -125,7 +126,10 @@ static uint8_t pattern_sigrok[] = {
        0xbe, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 };
 
-/* List of struct sr_dev_inst, maintained by opendev()/closedev(). */
+/* Private, per-device-instance driver context. */
+/* TODO: struct context as with the other drivers. */
+
+/* List of struct sr_dev_inst, maintained by dev_open()/dev_close(). */
 static GSList *dev_insts = NULL;
 static uint64_t cur_samplerate = SR_KHZ(200);
 static uint64_t limit_samples = 0;
@@ -134,7 +138,7 @@ static int default_pattern = PATTERN_SIGROK;
 static GThread *my_thread;
 static int thread_running;
 
-static int hw_acquisition_stop(int dev_index, gpointer session_data);
+static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
 
 static int hw_init(const char *devinfo)
 {
@@ -154,7 +158,7 @@ static int hw_init(const char *devinfo)
        return 1;
 }
 
-static int hw_opendev(int dev_index)
+static int hw_dev_open(int dev_index)
 {
        /* Avoid compiler warnings. */
        (void)dev_index;
@@ -164,7 +168,7 @@ static int hw_opendev(int dev_index)
        return SR_OK;
 }
 
-static int hw_closedev(int dev_index)
+static int hw_dev_close(int dev_index)
 {
        /* Avoid compiler warnings. */
        (void)dev_index;
@@ -214,7 +218,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id)
        return info;
 }
 
-static int hw_get_status(int dev_index)
+static int hw_dev_status_get(int dev_index)
 {
        /* Avoid compiler warnings. */
        (void)dev_index;
@@ -227,7 +231,7 @@ static int *hw_hwcap_get_all(void)
        return hwcaps;
 }
 
-static int hw_config_set(int dev_index, int hwcap, void *value)
+static int hw_dev_config_set(int dev_index, int hwcap, void *value)
 {
        int ret;
        char *stropt;
@@ -364,7 +368,7 @@ static void thread_func(void *data)
 }
 
 /* Callback handling data */
-static int receive_data(int fd, int revents, void *session_data)
+static int receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
@@ -386,7 +390,7 @@ static int receive_data(int fd, int revents, void *session_data)
                        logic.length = z;
                        logic.unitsize = 1;
                        logic.data = c;
-                       sr_session_bus(session_data, &packet);
+                       sr_session_send(cb_data, &packet);
                        samples_received += z;
                }
        } while (z > 0);
@@ -397,7 +401,7 @@ static int receive_data(int fd, int revents, void *session_data)
 
                /* Send last packet. */
                packet.type = SR_DF_END;
-               sr_session_bus(session_data, &packet);
+               sr_session_send(cb_data, &packet);
 
                return FALSE;
        }
@@ -405,7 +409,7 @@ static int receive_data(int fd, int revents, void *session_data)
        return TRUE;
 }
 
-static int hw_acquisition_start(int dev_index, gpointer session_data)
+static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 {
        struct sr_datafeed_packet *packet;
        struct sr_datafeed_header *header;
@@ -418,7 +422,7 @@ static int hw_acquisition_start(int dev_index, gpointer session_data)
        }
 
        mydata->sample_generator = default_pattern;
-       mydata->session_data = session_data;
+       mydata->session_dev_id = cb_data;
        mydata->dev_index = dev_index;
        mydata->samples_counter = 0;
 
@@ -440,7 +444,7 @@ static int hw_acquisition_start(int dev_index, gpointer session_data)
        g_io_channel_set_buffered(channels[1], FALSE);
 
        sr_source_add(mydata->pipe_fds[0], G_IO_IN | G_IO_ERR, 40,
-                     receive_data, session_data);
+                     receive_data, mydata->session_dev_id);
 
        /* Run the demo thread. */
        g_thread_init(NULL);
@@ -470,18 +474,19 @@ static int hw_acquisition_start(int dev_index, gpointer session_data)
        gettimeofday(&header->starttime, NULL);
        header->samplerate = cur_samplerate;
        header->num_logic_probes = NUM_PROBES;
-       sr_session_bus(session_data, packet);
+       sr_session_send(mydata->session_dev_id, packet);
        g_free(header);
        g_free(packet);
 
        return SR_OK;
 }
 
-static int hw_acquisition_stop(int dev_index, gpointer session_data)
+/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
+static int hw_dev_acquisition_stop(int dev_index, void *cb_data)
 {
        /* Avoid compiler warnings. */
        (void)dev_index;
-       (void)session_data;
+       (void)cb_data;
 
        /* Stop generate thread. */
        thread_running = 0;
@@ -489,18 +494,18 @@ static int hw_acquisition_stop(int dev_index, gpointer session_data)
        return SR_OK;
 }
 
-SR_PRIV struct sr_dev_plugin demo_plugin_info = {
+SR_PRIV struct sr_dev_driver demo_driver_info = {
        .name = "demo",
        .longname = "Demo driver and pattern generator",
        .api_version = 1,
        .init = hw_init,
        .cleanup = hw_cleanup,
-       .opendev = hw_opendev,
-       .closedev = hw_closedev,
+       .dev_open = hw_dev_open,
+       .dev_close = hw_dev_close,
        .dev_info_get = hw_dev_info_get,
-       .get_status = hw_get_status,
+       .dev_status_get = hw_dev_status_get,
        .hwcap_get_all = hw_hwcap_get_all,
-       .config_set = hw_config_set,
-       .acquisition_start = hw_acquisition_start,
-       .acquisition_stop = hw_acquisition_stop,
+       .dev_config_set = hw_dev_config_set,
+       .dev_acquisition_start = hw_dev_acquisition_start,
+       .dev_acquisition_stop = hw_dev_acquisition_stop,
 };