2 * This file is part of the libsigrok project.
4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "libsigrok.h"
26 #include "libsigrok-internal.h"
29 #define LOG_PREFIX "session"
35 * Creating, using, or destroying libsigrok sessions.
39 * @defgroup grp_session Session handling
41 * Creating, using, or destroying libsigrok sessions.
48 sr_receive_data_callback cb;
51 /* This is used to keep track of the object (fd, pollfd or channel) which is
52 * being polled and will be used to match the source when removing it again.
57 struct datafeed_callback {
58 sr_datafeed_callback cb;
63 * Create a new session.
65 * @param ctx The context in which to create the new session.
66 * @param new_session This will contain a pointer to the newly created
67 * session if the return value is SR_OK, otherwise the value
68 * is undefined and should not be used. Must not be NULL.
70 * @retval SR_OK Success.
71 * @retval SR_ERR_ARG Invalid argument.
75 SR_API int sr_session_new(struct sr_context *ctx,
76 struct sr_session **new_session)
78 struct sr_session *session;
83 session = g_malloc0(sizeof(struct sr_session));
86 session->source_timeout = -1;
87 session->running = FALSE;
88 session->abort_session = FALSE;
89 g_mutex_init(&session->stop_mutex);
91 *new_session = session;
98 * This frees up all memory used by the session.
100 * @param session The session to destroy. Must not be NULL.
102 * @retval SR_OK Success.
103 * @retval SR_ERR_ARG Invalid session passed.
107 SR_API int sr_session_destroy(struct sr_session *session)
110 sr_err("%s: session was NULL", __func__);
114 sr_session_dev_remove_all(session);
115 g_mutex_clear(&session->stop_mutex);
116 if (session->trigger)
117 sr_trigger_free(session->trigger);
119 g_slist_free_full(session->owned_devs, (GDestroyNotify)sr_dev_inst_free);
127 * Remove all the devices from a session.
129 * The session itself (i.e., the struct sr_session) is not free'd and still
130 * exists after this function returns.
132 * @param session The session to use. Must not be NULL.
134 * @retval SR_OK Success.
135 * @retval SR_ERR_BUG Invalid session passed.
139 SR_API int sr_session_dev_remove_all(struct sr_session *session)
141 struct sr_dev_inst *sdi;
145 sr_err("%s: session was NULL", __func__);
149 for (l = session->devs; l; l = l->next) {
150 sdi = (struct sr_dev_inst *) l->data;
154 g_slist_free(session->devs);
155 session->devs = NULL;
161 * Add a device instance to a session.
163 * @param session The session to add to. Must not be NULL.
164 * @param sdi The device instance to add to a session. Must not
165 * be NULL. Also, sdi->driver and sdi->driver->dev_open must
168 * @retval SR_OK Success.
169 * @retval SR_ERR_ARG Invalid argument.
173 SR_API int sr_session_dev_add(struct sr_session *session,
174 struct sr_dev_inst *sdi)
179 sr_err("%s: sdi was NULL", __func__);
184 sr_err("%s: session was NULL", __func__);
188 /* If sdi->session is not NULL, the device is already in this or
189 * another session. */
191 sr_err("%s: already assigned to session", __func__);
195 /* If sdi->driver is NULL, this is a virtual device. */
197 /* Just add the device, don't run dev_open(). */
198 session->devs = g_slist_append(session->devs, (gpointer)sdi);
199 sdi->session = session;
203 /* sdi->driver is non-NULL (i.e. we have a real device). */
204 if (!sdi->driver->dev_open) {
205 sr_err("%s: sdi->driver->dev_open was NULL", __func__);
209 session->devs = g_slist_append(session->devs, (gpointer)sdi);
210 sdi->session = session;
212 if (session->running) {
213 /* Adding a device to a running session. Commit settings
214 * and start acquisition on that device now. */
215 if ((ret = sr_config_commit(sdi)) != SR_OK) {
216 sr_err("Failed to commit device settings before "
217 "starting acquisition in running session (%s)",
221 if ((ret = sdi->driver->dev_acquisition_start(sdi,
222 (void *)sdi)) != SR_OK) {
223 sr_err("Failed to start acquisition of device in "
224 "running session (%s)", sr_strerror(ret));
233 * List all device instances attached to a session.
235 * @param session The session to use. Must not be NULL.
236 * @param devlist A pointer where the device instance list will be
237 * stored on return. If no devices are in the session,
238 * this will be NULL. Each element in the list points
239 * to a struct sr_dev_inst *.
240 * The list must be freed by the caller, but not the
241 * elements pointed to.
243 * @retval SR_OK Success.
244 * @retval SR_ERR_ARG Invalid argument.
248 SR_API int sr_session_dev_list(struct sr_session *session, GSList **devlist)
256 *devlist = g_slist_copy(session->devs);
262 * Remove all datafeed callbacks in a session.
264 * @param session The session to use. Must not be NULL.
266 * @retval SR_OK Success.
267 * @retval SR_ERR_ARG Invalid session passed.
271 SR_API int sr_session_datafeed_callback_remove_all(struct sr_session *session)
274 sr_err("%s: session was NULL", __func__);
278 g_slist_free_full(session->datafeed_callbacks, g_free);
279 session->datafeed_callbacks = NULL;
285 * Add a datafeed callback to a session.
287 * @param session The session to use. Must not be NULL.
288 * @param cb Function to call when a chunk of data is received.
290 * @param cb_data Opaque pointer passed in by the caller.
292 * @retval SR_OK Success.
293 * @retval SR_ERR_BUG No session exists.
297 SR_API int sr_session_datafeed_callback_add(struct sr_session *session,
298 sr_datafeed_callback cb, void *cb_data)
300 struct datafeed_callback *cb_struct;
303 sr_err("%s: session was NULL", __func__);
308 sr_err("%s: cb was NULL", __func__);
312 cb_struct = g_malloc0(sizeof(struct datafeed_callback));
314 cb_struct->cb_data = cb_data;
316 session->datafeed_callbacks =
317 g_slist_append(session->datafeed_callbacks, cb_struct);
323 * Get the trigger assigned to this session.
325 * @param session The session to use.
327 * @retval NULL Invalid (NULL) session was passed to the function.
328 * @retval other The trigger assigned to this session (can be NULL).
332 SR_API struct sr_trigger *sr_session_trigger_get(struct sr_session *session)
337 return session->trigger;
341 * Set the trigger of this session.
343 * @param session The session to use. Must not be NULL.
344 * @param trig The trigger to assign to this session. Can be NULL.
346 * @retval SR_OK Success.
347 * @retval SR_ERR_ARG Invalid argument.
351 SR_API int sr_session_trigger_set(struct sr_session *session, struct sr_trigger *trig)
356 session->trigger = trig;
362 * Call every device in the current session's callback.
364 * For sessions not driven by select loops such as sr_session_run(),
365 * but driven by another scheduler, this can be used to poll the devices
366 * from within that scheduler.
368 * @param session The session to use. Must not be NULL.
369 * @param block If TRUE, this call will wait for any of the session's
370 * sources to fire an event on the file descriptors, or
371 * any of their timeouts to activate. In other words, this
372 * can be used as a select loop.
373 * If FALSE, all sources have their callback run, regardless
374 * of file descriptor or timeout status.
376 * @retval SR_OK Success.
377 * @retval SR_ERR Error occurred.
379 static int sr_session_iteration(struct sr_session *session, gboolean block)
383 #ifdef HAVE_LIBUSB_1_0
388 timeout = block ? 0 : session->source_timeout;
390 #ifdef HAVE_LIBUSB_1_0
391 ret = libusb_get_next_timeout(session->ctx->libusb_ctx, &tv);
393 sr_err("Error getting libusb timeout: %s",
394 libusb_error_name(ret));
396 } else if (ret == 1) {
397 usb_timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000;
398 timeout = MIN(timeout, usb_timeout);
402 ret = g_poll(session->pollfds, session->num_sources, timeout);
403 for (i = 0; i < session->num_sources; i++) {
404 if (session->pollfds[i].revents > 0 || (ret == 0
405 && session->source_timeout == session->sources[i].timeout)) {
407 * Invoke the source's callback on an event,
408 * or if the poll timed out and this source
409 * asked for that timeout.
411 if (!session->sources[i].cb(session->pollfds[i].fd,
412 session->pollfds[i].revents,
413 session->sources[i].cb_data))
414 sr_session_source_remove(session,
415 session->sources[i].poll_object);
418 * We want to take as little time as possible to stop
419 * the session if we have been told to do so. Therefore,
420 * we check the flag after processing every source, not
421 * just once per main event loop.
423 g_mutex_lock(&session->stop_mutex);
424 if (session->abort_session) {
425 sr_session_stop_sync(session);
426 /* But once is enough. */
427 session->abort_session = FALSE;
429 g_mutex_unlock(&session->stop_mutex);
435 static int verify_trigger(struct sr_trigger *trigger)
437 struct sr_trigger_stage *stage;
438 struct sr_trigger_match *match;
441 if (!trigger->stages) {
442 sr_err("No trigger stages defined.");
446 sr_spew("Checking trigger:");
447 for (l = trigger->stages; l; l = l->next) {
449 if (!stage->matches) {
450 sr_err("Stage %d has no matches defined.", stage->stage);
453 for (m = stage->matches; m; m = m->next) {
455 if (!match->channel) {
456 sr_err("Stage %d match has no channel.", stage->stage);
460 sr_err("Stage %d match is not defined.", stage->stage);
463 sr_spew("Stage %d match on channel %s, match %d", stage->stage,
464 match->channel->name, match->match);
474 * @param session The session to use. Must not be NULL.
476 * @retval SR_OK Success.
477 * @retval SR_ERR_ARG Invalid session passed.
481 SR_API int sr_session_start(struct sr_session *session)
483 struct sr_dev_inst *sdi;
484 struct sr_channel *ch;
486 int enabled_channels, ret;
489 sr_err("%s: session was NULL", __func__);
493 if (!session->devs) {
494 sr_err("%s: session->devs was NULL; a session "
495 "cannot be started without devices.", __func__);
499 if (session->trigger && verify_trigger(session->trigger) != SR_OK)
502 sr_info("Starting.");
505 for (l = session->devs; l; l = l->next) {
507 enabled_channels = 0;
508 for (c = sdi->channels; c; c = c->next) {
515 if (enabled_channels == 0) {
517 sr_err("%s using connection %s has no enabled channels!",
518 sdi->driver->name, sdi->connection_id);
522 if ((ret = sr_config_commit(sdi)) != SR_OK) {
523 sr_err("Failed to commit device settings before "
524 "starting acquisition (%s)", sr_strerror(ret));
527 if ((ret = sdi->driver->dev_acquisition_start(sdi, sdi)) != SR_OK) {
528 sr_err("%s: could not start an acquisition "
529 "(%s)", __func__, sr_strerror(ret));
534 /* TODO: What if there are multiple devices? Which return code? */
542 * @param session The session to use. Must not be NULL.
544 * @retval SR_OK Success.
545 * @retval SR_ERR_ARG Invalid session passed.
549 SR_API int sr_session_run(struct sr_session *session)
552 sr_err("%s: session was NULL", __func__);
556 if (!session->devs) {
557 /* TODO: Actually the case? */
558 sr_err("%s: session->devs was NULL; a session "
559 "cannot be run without devices.", __func__);
562 session->running = TRUE;
566 /* Do we have real sources? */
567 if (session->num_sources == 1 && session->pollfds[0].fd == -1) {
568 /* Dummy source, freewheel over it. */
569 while (session->num_sources)
570 session->sources[0].cb(-1, 0, session->sources[0].cb_data);
572 /* Real sources, use g_poll() main loop. */
573 while (session->num_sources)
574 sr_session_iteration(session, TRUE);
583 * The session is stopped immediately, with all acquisition sessions stopped
584 * and hardware drivers cleaned up.
586 * This must be called from within the session thread, to prevent freeing
587 * resources that the session thread will try to use.
589 * @param session The session to use. Must not be NULL.
591 * @retval SR_OK Success.
592 * @retval SR_ERR_ARG Invalid session passed.
596 SR_PRIV int sr_session_stop_sync(struct sr_session *session)
598 struct sr_dev_inst *sdi;
602 sr_err("%s: session was NULL", __func__);
606 sr_info("Stopping.");
608 for (l = session->devs; l; l = l->next) {
611 if (sdi->driver->dev_acquisition_stop)
612 sdi->driver->dev_acquisition_stop(sdi, sdi);
615 session->running = FALSE;
623 * The session is stopped immediately, with all acquisition sessions being
624 * stopped and hardware drivers cleaned up.
626 * If the session is run in a separate thread, this function will not block
627 * until the session is finished executing. It is the caller's responsibility
628 * to wait for the session thread to return before assuming that the session is
629 * completely decommissioned.
631 * @param session The session to use. Must not be NULL.
633 * @retval SR_OK Success.
634 * @retval SR_ERR_ARG Invalid session passed.
638 SR_API int sr_session_stop(struct sr_session *session)
641 sr_err("%s: session was NULL", __func__);
645 g_mutex_lock(&session->stop_mutex);
646 session->abort_session = TRUE;
647 g_mutex_unlock(&session->stop_mutex);
655 * @param packet The packet to show debugging information for.
657 static void datafeed_dump(const struct sr_datafeed_packet *packet)
659 const struct sr_datafeed_logic *logic;
660 const struct sr_datafeed_analog *analog;
661 const struct sr_datafeed_analog2 *analog2;
663 switch (packet->type) {
665 sr_dbg("bus: Received SR_DF_HEADER packet.");
668 sr_dbg("bus: Received SR_DF_TRIGGER packet.");
671 sr_dbg("bus: Received SR_DF_META packet.");
674 logic = packet->payload;
675 sr_dbg("bus: Received SR_DF_LOGIC packet (%" PRIu64 " bytes, "
676 "unitsize = %d).", logic->length, logic->unitsize);
679 analog = packet->payload;
680 sr_dbg("bus: Received SR_DF_ANALOG packet (%d samples).",
681 analog->num_samples);
684 analog2 = packet->payload;
685 sr_dbg("bus: Received SR_DF_ANALOG2 packet (%d samples).",
686 analog2->num_samples);
689 sr_dbg("bus: Received SR_DF_END packet.");
691 case SR_DF_FRAME_BEGIN:
692 sr_dbg("bus: Received SR_DF_FRAME_BEGIN packet.");
694 case SR_DF_FRAME_END:
695 sr_dbg("bus: Received SR_DF_FRAME_END packet.");
698 sr_dbg("bus: Received unknown packet type: %d.", packet->type);
704 * Send a packet to whatever is listening on the datafeed bus.
706 * Hardware drivers use this to send a data packet to the frontend.
709 * @param packet The datafeed packet to send to the session bus.
711 * @retval SR_OK Success.
712 * @retval SR_ERR_ARG Invalid argument.
716 SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
717 const struct sr_datafeed_packet *packet)
720 struct datafeed_callback *cb_struct;
721 struct sr_datafeed_packet *packet_in, *packet_out;
722 struct sr_transform *t;
726 sr_err("%s: sdi was NULL", __func__);
731 sr_err("%s: packet was NULL", __func__);
736 sr_err("%s: session was NULL", __func__);
741 * Pass the packet to the first transform module. If that returns
742 * another packet (instead of NULL), pass that packet to the next
743 * transform module in the list, and so on.
745 packet_in = (struct sr_datafeed_packet *)packet;
746 for (l = sdi->session->transforms; l; l = l->next) {
748 sr_spew("Running transform module '%s'.", t->module->id);
749 ret = t->module->receive(t, packet_in, &packet_out);
751 sr_err("Error while running transform module: %d.", ret);
756 * If any of the transforms don't return an output
759 sr_spew("Transform module didn't return a packet, aborting.");
763 * Use this transform module's output packet as input
764 * for the next transform module.
766 packet_in = packet_out;
771 * If the last transform did output a packet, pass it to all datafeed
774 for (l = sdi->session->datafeed_callbacks; l; l = l->next) {
775 if (sr_log_loglevel_get() >= SR_LOG_DBG)
776 datafeed_dump(packet);
778 cb_struct->cb(sdi, packet, cb_struct->cb_data);
785 * Add an event source for a file descriptor.
787 * @param session The session to use. Must not be NULL.
788 * @param pollfd The GPollFD.
789 * @param[in] timeout Max time to wait before the callback is called,
791 * @param cb Callback function to add. Must not be NULL.
792 * @param cb_data Data for the callback function. Can be NULL.
793 * @param poll_object TODO.
795 * @retval SR_OK Success.
796 * @retval SR_ERR_ARG Invalid argument.
798 static int _sr_session_source_add(struct sr_session *session, GPollFD *pollfd,
799 int timeout, sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
801 struct source *new_sources, *s;
802 GPollFD *new_pollfds;
805 sr_err("%s: cb was NULL", __func__);
809 /* Note: cb_data can be NULL, that's not a bug. */
811 new_pollfds = g_realloc(session->pollfds,
812 sizeof(GPollFD) * (session->num_sources + 1));
813 new_sources = g_realloc(session->sources, sizeof(struct source) *
814 (session->num_sources + 1));
816 new_pollfds[session->num_sources] = *pollfd;
817 s = &new_sources[session->num_sources++];
818 s->timeout = timeout;
820 s->cb_data = cb_data;
821 s->poll_object = poll_object;
822 session->pollfds = new_pollfds;
823 session->sources = new_sources;
825 if (timeout != session->source_timeout && timeout > 0
826 && (session->source_timeout == -1 || timeout < session->source_timeout))
827 session->source_timeout = timeout;
833 * Add an event source for a file descriptor.
835 * @param session The session to use. Must not be NULL.
836 * @param fd The file descriptor.
837 * @param events Events to check for.
838 * @param timeout Max time to wait before the callback is called, ignored if 0.
839 * @param cb Callback function to add. Must not be NULL.
840 * @param cb_data Data for the callback function. Can be NULL.
842 * @retval SR_OK Success.
843 * @retval SR_ERR_ARG Invalid argument.
847 SR_API int sr_session_source_add(struct sr_session *session, int fd,
848 int events, int timeout, sr_receive_data_callback cb, void *cb_data)
855 return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)fd);
859 * Add an event source for a GPollFD.
861 * @param session The session to use. Must not be NULL.
862 * @param pollfd The GPollFD.
863 * @param timeout Max time to wait before the callback is called, ignored if 0.
864 * @param cb Callback function to add. Must not be NULL.
865 * @param cb_data Data for the callback function. Can be NULL.
867 * @retval SR_OK Success.
868 * @retval SR_ERR_ARG Invalid argument.
872 SR_API int sr_session_source_add_pollfd(struct sr_session *session,
873 GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
876 return _sr_session_source_add(session, pollfd, timeout, cb,
877 cb_data, (gintptr)pollfd);
881 * Add an event source for a GIOChannel.
883 * @param session The session to use. Must not be NULL.
884 * @param channel The GIOChannel.
885 * @param events Events to poll on.
886 * @param timeout Max time to wait before the callback is called, ignored if 0.
887 * @param cb Callback function to add. Must not be NULL.
888 * @param cb_data Data for the callback function. Can be NULL.
890 * @retval SR_OK Success.
891 * @retval SR_ERR_ARG Invalid argument.
895 SR_API int sr_session_source_add_channel(struct sr_session *session,
896 GIOChannel *channel, int events, int timeout,
897 sr_receive_data_callback cb, void *cb_data)
902 g_io_channel_win32_make_pollfd(channel, events, &p);
904 p.fd = g_io_channel_unix_get_fd(channel);
908 return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)channel);
912 * Remove the source belonging to the specified channel.
914 * @param session The session to use. Must not be NULL.
915 * @param poll_object The channel for which the source should be removed.
917 * @retval SR_OK Success
918 * @retval SR_ERR_ARG Invalid arguments
919 * @retval SR_ERR_BUG Internal error
921 static int _sr_session_source_remove(struct sr_session *session, gintptr poll_object)
925 if (!session->sources || !session->num_sources) {
926 sr_err("%s: sources was NULL", __func__);
930 for (old = 0; old < session->num_sources; old++) {
931 if (session->sources[old].poll_object == poll_object)
935 /* fd not found, nothing to do */
936 if (old == session->num_sources)
939 session->num_sources--;
941 if (old != session->num_sources) {
942 memmove(&session->pollfds[old], &session->pollfds[old + 1],
943 (session->num_sources - old) * sizeof(GPollFD));
944 memmove(&session->sources[old], &session->sources[old + 1],
945 (session->num_sources - old) * sizeof(struct source));
948 session->pollfds = g_realloc(session->pollfds, sizeof(GPollFD) * session->num_sources);
949 session->sources = g_realloc(session->sources, sizeof(struct source) * session->num_sources);
955 * Remove the source belonging to the specified file descriptor.
957 * @param session The session to use. Must not be NULL.
958 * @param fd The file descriptor for which the source should be removed.
960 * @retval SR_OK Success
961 * @retval SR_ERR_ARG Invalid argument
962 * @retval SR_ERR_BUG Internal error.
966 SR_API int sr_session_source_remove(struct sr_session *session, int fd)
968 return _sr_session_source_remove(session, (gintptr)fd);
972 * Remove the source belonging to the specified poll descriptor.
974 * @param session The session to use. Must not be NULL.
975 * @param pollfd The poll descriptor for which the source should be removed.
977 * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
978 * SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
983 SR_API int sr_session_source_remove_pollfd(struct sr_session *session,
986 return _sr_session_source_remove(session, (gintptr)pollfd);
990 * Remove the source belonging to the specified channel.
992 * @param session The session to use. Must not be NULL.
993 * @param channel The channel for which the source should be removed.
995 * @retval SR_OK Success.
996 * @retval SR_ERR_ARG Invalid argument.
997 * @return SR_ERR_BUG Internal error.
1001 SR_API int sr_session_source_remove_channel(struct sr_session *session,
1002 GIOChannel *channel)
1004 return _sr_session_source_remove(session, (gintptr)channel);
1007 static void copy_src(struct sr_config *src, struct sr_datafeed_meta *meta_copy)
1009 g_variant_ref(src->data);
1010 meta_copy->config = g_slist_append(meta_copy->config,
1011 g_memdup(src, sizeof(struct sr_config)));
1014 SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet,
1015 struct sr_datafeed_packet **copy)
1017 const struct sr_datafeed_meta *meta;
1018 struct sr_datafeed_meta *meta_copy;
1019 const struct sr_datafeed_logic *logic;
1020 struct sr_datafeed_logic *logic_copy;
1021 const struct sr_datafeed_analog *analog;
1022 struct sr_datafeed_analog *analog_copy;
1025 *copy = g_malloc0(sizeof(struct sr_datafeed_packet));
1026 (*copy)->type = packet->type;
1028 switch (packet->type) {
1034 payload = g_malloc(sizeof(struct sr_datafeed_header));
1035 memcpy(payload, packet->payload, sizeof(struct sr_datafeed_header));
1036 (*copy)->payload = payload;
1039 meta = packet->payload;
1040 meta_copy = g_malloc0(sizeof(struct sr_datafeed_meta));
1041 g_slist_foreach(meta->config, (GFunc)copy_src, meta_copy->config);
1042 (*copy)->payload = meta_copy;
1045 logic = packet->payload;
1046 logic_copy = g_malloc(sizeof(logic));
1047 logic_copy->length = logic->length;
1048 logic_copy->unitsize = logic->unitsize;
1049 memcpy(logic_copy->data, logic->data, logic->length * logic->unitsize);
1050 (*copy)->payload = logic_copy;
1053 analog = packet->payload;
1054 analog_copy = g_malloc(sizeof(analog));
1055 analog_copy->channels = g_slist_copy(analog->channels);
1056 analog_copy->num_samples = analog->num_samples;
1057 analog_copy->mq = analog->mq;
1058 analog_copy->unit = analog->unit;
1059 analog_copy->mqflags = analog->mqflags;
1060 memcpy(analog_copy->data, analog->data,
1061 analog->num_samples * sizeof(float));
1062 (*copy)->payload = analog_copy;
1065 sr_err("Unknown packet type %d", packet->type);
1072 void sr_packet_free(struct sr_datafeed_packet *packet)
1074 const struct sr_datafeed_meta *meta;
1075 const struct sr_datafeed_logic *logic;
1076 const struct sr_datafeed_analog *analog;
1077 struct sr_config *src;
1080 switch (packet->type) {
1086 /* Payload is a simple struct. */
1087 g_free((void *)packet->payload);
1090 meta = packet->payload;
1091 for (l = meta->config; l; l = l->next) {
1093 g_variant_unref(src->data);
1096 g_slist_free(meta->config);
1097 g_free((void *)packet->payload);
1100 logic = packet->payload;
1101 g_free(logic->data);
1102 g_free((void *)packet->payload);
1105 analog = packet->payload;
1106 g_slist_free(analog->channels);
1107 g_free(analog->data);
1108 g_free((void *)packet->payload);
1111 sr_err("Unknown packet type %d", packet->type);