X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fsession.c;h=d1a19c56e9967a7187d3dc8fdfca01da25848ab1;hb=d65f51bf5c549e5dbacb5c6fb6636e482ff02da8;hp=c88e48c74e49c159c85fdc0e946d7774e4e3f1a2;hpb=f200d59ee21a42998752c4319d4ff48e129c95c5;p=libsigrok.git diff --git a/src/session.c b/src/session.c index c88e48c7..d1a19c56 100644 --- a/src/session.c +++ b/src/session.c @@ -53,7 +53,6 @@ struct datafeed_callback { /** Custom GLib event source for generic descriptor I/O. * @see https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html - * @internal */ struct fd_source { GSource base; @@ -127,7 +126,7 @@ static gboolean fd_source_dispatch(GSource *source, sr_err("Callback not set, cannot dispatch event."); return G_SOURCE_REMOVE; } - keep = (*(sr_receive_data_callback)callback) + keep = (*SR_RECEIVE_DATA_CALLBACK(callback)) (fsource->pollfd.fd, revents, user_data); if (fsource->timeout_us >= 0 && G_LIKELY(keep) @@ -158,7 +157,9 @@ static void fd_source_finalize(GSource *source) * @param session The session the event source belongs to. * @param key The key used to identify this source. * @param fd The file descriptor or HANDLE. + * @param events Events. * @param timeout_ms The timeout interval in ms, or -1 to wait indefinitely. + * * @return A new event source object, or NULL on failure. */ static GSource *fd_source_new(struct sr_session *session, void *key, @@ -365,7 +366,7 @@ SR_API int sr_session_dev_add(struct sr_session *session, sr_strerror(ret)); return ret; } - if ((ret = sdi->driver->dev_acquisition_start(sdi)) != SR_OK) { + if ((ret = sr_dev_acquisition_start(sdi)) != SR_OK) { sr_err("Failed to start acquisition of device in " "running session (%s)", sr_strerror(ret)); return ret; @@ -816,7 +817,7 @@ SR_API int sr_session_start(struct sr_session *session) ret = SR_ERR; break; } - ret = sdi->driver->dev_acquisition_start(sdi); + ret = sr_dev_acquisition_start(sdi); if (ret != SR_OK) { sr_err("Could not start %s device %s acquisition.", sdi->driver->name, sdi->connection_id); @@ -830,7 +831,7 @@ SR_API int sr_session_start(struct sr_session *session) lend = l->next; for (l = session->devs; l != lend; l = l->next) { sdi = l->data; - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } /* TODO: Handle delayed stops. Need to iterate the event * sources... */ @@ -913,8 +914,7 @@ static gboolean session_stop_sync(void *user_data) for (node = session->devs; node; node = node->next) { sdi = node->data; - if (sdi->driver && sdi->driver->dev_acquisition_stop) - sdi->driver->dev_acquisition_stop(sdi); + sr_dev_acquisition_stop(sdi); } return G_SOURCE_REMOVE; @@ -1072,6 +1072,42 @@ static void datafeed_dump(const struct sr_datafeed_packet *packet) } } +/** + * Helper to send a meta datafeed package (SR_DF_META) to the session bus. + * + * @param sdi The device instance to send the package from. Must not be NULL. + * @param key The config key to send to the session bus. + * @param var The value to send to the session bus. + * + * @retval SR_OK Success. + * @retval SR_ERR_ARG Invalid argument. + * + * @private + */ +SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi, + uint32_t key, GVariant *var) +{ + struct sr_config *cfg; + struct sr_datafeed_packet packet; + struct sr_datafeed_meta meta; + int ret; + + cfg = sr_config_new(key, var); + + memset(&meta, 0, sizeof(meta)); + + packet.type = SR_DF_META; + packet.payload = &meta; + + meta.config = g_slist_append(NULL, cfg); + + ret = sr_session_send(sdi, &packet); + g_slist_free(meta.config); + sr_config_free(cfg); + + return ret; +} + /** * Send a packet to whatever is listening on the datafeed bus. * @@ -1201,7 +1237,7 @@ SR_PRIV int sr_session_fd_source_add(struct sr_session *session, if (!source) return SR_ERR; - g_source_set_callback(source, (GSourceFunc)cb, cb_data, NULL); + g_source_set_callback(source, G_SOURCE_FUNC(cb), cb_data, NULL); ret = sr_session_source_add_internal(session, key, source); g_source_unref(source); @@ -1295,7 +1331,7 @@ SR_PRIV int sr_session_source_add_channel(struct sr_session *session, /* We should be using g_io_create_watch(), but can't without * changing the driver API, as the callback signature is different. */ -#ifdef G_OS_WIN32 +#ifdef _WIN32 g_io_channel_win32_make_pollfd(channel, events, &pollfd); #else pollfd.fd = g_io_channel_unix_get_fd(channel); @@ -1451,8 +1487,7 @@ static void copy_src(struct sr_config *src, struct sr_datafeed_meta *meta_copy) g_memdup(src, sizeof(struct sr_config))); } -/** @private */ -SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet, +SR_API int sr_packet_copy(const struct sr_datafeed_packet *packet, struct sr_datafeed_packet **copy) { const struct sr_datafeed_meta *meta; @@ -1485,8 +1520,15 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet, case SR_DF_LOGIC: logic = packet->payload; logic_copy = g_malloc(sizeof(*logic_copy)); + if (!logic_copy) + return SR_ERR; logic_copy->length = logic->length; logic_copy->unitsize = logic->unitsize; + logic_copy->data = g_malloc(logic->length * logic->unitsize); + if (!logic_copy->data) { + g_free(logic_copy); + return SR_ERR; + } memcpy(logic_copy->data, logic->data, logic->length * logic->unitsize); (*copy)->payload = logic_copy; break; @@ -1516,7 +1558,7 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet, return SR_OK; } -void sr_packet_free(struct sr_datafeed_packet *packet) +SR_API void sr_packet_free(struct sr_datafeed_packet *packet) { const struct sr_datafeed_meta *meta; const struct sr_datafeed_logic *logic; @@ -1561,7 +1603,6 @@ void sr_packet_free(struct sr_datafeed_packet *packet) sr_err("Unknown packet type %d", packet->type); } g_free(packet); - } /** @} */