+ if (pipe(ctx->pipe_fds)) {
+ /* TODO: Better error message. */
+ sr_err("demo: %s: pipe() failed", __func__);
+ return SR_ERR;
+ }
+
+ ctx->channels[0] = g_io_channel_unix_new(ctx->pipe_fds[0]);
+ ctx->channels[1] = g_io_channel_unix_new(ctx->pipe_fds[1]);
+
+ g_io_channel_set_flags(ctx->channels[0], G_IO_FLAG_NONBLOCK, NULL);
+
+ /* Set channel encoding to binary (default is UTF-8). */
+ g_io_channel_set_encoding(ctx->channels[0], NULL, NULL);
+ g_io_channel_set_encoding(ctx->channels[1], NULL, NULL);
+
+ /* Make channels to unbuffered. */
+ g_io_channel_set_buffered(ctx->channels[0], FALSE);
+ g_io_channel_set_buffered(ctx->channels[1], FALSE);
+
+ sr_session_source_add_channel(ctx->channels[0], G_IO_IN | G_IO_ERR,
+ 40, receive_data, ctx);
+
+ /* Run the demo thread. */
+ g_thread_init(NULL);
+ /* This must to be done between g_thread_init() & g_thread_create(). */
+ ctx->timer = g_timer_new();
+ thread_running = 1;
+ my_thread =
+ g_thread_create((GThreadFunc)thread_func, ctx, TRUE, NULL);
+ if (!my_thread) {
+ sr_err("demo: %s: g_thread_create failed", __func__);
+ return SR_ERR; /* TODO */
+ }
+
+ if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
+ sr_err("demo: %s: packet malloc failed", __func__);
+ return SR_ERR_MALLOC;
+ }
+
+ if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
+ sr_err("demo: %s: header malloc failed", __func__);
+ return SR_ERR_MALLOC;
+ }
+
+ packet->type = SR_DF_HEADER;
+ packet->payload = header;
+ header->feed_version = 1;
+ gettimeofday(&header->starttime, NULL);
+ sr_session_send(ctx->session_dev_id, packet);
+
+ /* Send metadata about the SR_DF_LOGIC packets to come. */
+ packet->type = SR_DF_META_LOGIC;
+ packet->payload = &meta;
+ meta.samplerate = cur_samplerate;
+ meta.num_probes = NUM_PROBES;
+ sr_session_send(ctx->session_dev_id, packet);
+
+ g_free(header);
+ g_free(packet);
+
+ return SR_OK;
+}
+
+/* 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)cb_data;