Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 1 | /* |
Uwe Hermann | 50985c2 | 2013-04-23 22:24:30 +0200 | [diff] [blame] | 2 | * This file is part of the libsigrok project. |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 3 | * |
Bert Vermeulen | c73d2ea | 2012-02-13 14:31:51 +0100 | [diff] [blame] | 4 | * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com> |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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/>. |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <unistd.h> |
| 23 | #include <string.h> |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 24 | #include <glib.h> |
Bert Vermeulen | 45c59c8 | 2012-07-05 00:55:07 +0200 | [diff] [blame] | 25 | #include "libsigrok.h" |
| 26 | #include "libsigrok-internal.h" |
Bert Vermeulen | aa4b110 | 2011-01-24 07:46:16 +0100 | [diff] [blame] | 27 | |
Uwe Hermann | 29a2719 | 2013-05-03 21:59:32 +0200 | [diff] [blame] | 28 | /* Message logging helpers with subsystem-specific prefix string. */ |
| 29 | #define LOG_PREFIX "session: " |
| 30 | #define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args) |
| 31 | #define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args) |
| 32 | #define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args) |
| 33 | #define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args) |
| 34 | #define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args) |
| 35 | #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 36 | |
Uwe Hermann | 7b870c3 | 2012-10-21 16:13:36 +0200 | [diff] [blame] | 37 | /** |
Uwe Hermann | 393fb9c | 2012-10-22 00:30:12 +0200 | [diff] [blame] | 38 | * @file |
| 39 | * |
| 40 | * Creating, using, or destroying libsigrok sessions. |
| 41 | */ |
| 42 | |
| 43 | /** |
Uwe Hermann | 7b870c3 | 2012-10-21 16:13:36 +0200 | [diff] [blame] | 44 | * @defgroup grp_session Session handling |
| 45 | * |
| 46 | * Creating, using, or destroying libsigrok sessions. |
| 47 | * |
| 48 | * @{ |
| 49 | */ |
| 50 | |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 51 | struct source { |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 52 | int timeout; |
Uwe Hermann | d08490a | 2012-02-29 21:56:24 +0100 | [diff] [blame] | 53 | sr_receive_data_callback_t cb; |
Uwe Hermann | 1f9813e | 2012-02-29 22:32:34 +0100 | [diff] [blame] | 54 | void *cb_data; |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 55 | |
| 56 | /* This is used to keep track of the object (fd, pollfd or channel) which is |
| 57 | * being polled and will be used to match the source when removing it again. |
| 58 | */ |
| 59 | gintptr poll_object; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 62 | struct datafeed_callback { |
| 63 | sr_datafeed_callback_t cb; |
| 64 | void *cb_data; |
| 65 | }; |
| 66 | |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 67 | /* There can only be one session at a time. */ |
Uwe Hermann | a0ecd83 | 2011-12-28 22:55:21 +0100 | [diff] [blame] | 68 | /* 'session' is not static, it's used elsewhere (via 'extern'). */ |
Uwe Hermann | 2872d21 | 2011-02-08 17:50:29 +0100 | [diff] [blame] | 69 | struct sr_session *session; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 70 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 71 | /** |
| 72 | * Create a new session. |
| 73 | * |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 74 | * @todo Should it use the file-global "session" variable or take an argument? |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 75 | * The same question applies to all the other session functions. |
| 76 | * |
| 77 | * @return A pointer to the newly allocated session, or NULL upon errors. |
| 78 | */ |
Uwe Hermann | 1a081ca | 2012-02-01 23:40:35 +0100 | [diff] [blame] | 79 | SR_API struct sr_session *sr_session_new(void) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 80 | { |
Uwe Hermann | 133a37b | 2012-02-11 20:06:46 +0100 | [diff] [blame] | 81 | if (!(session = g_try_malloc0(sizeof(struct sr_session)))) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 82 | sr_err("Session malloc failed."); |
| 83 | return NULL; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 84 | } |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 85 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 86 | session->source_timeout = -1; |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 87 | session->abort_session = FALSE; |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 88 | // g_mutex_init(&session->stop_mutex); |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 89 | |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 90 | return session; |
| 91 | } |
| 92 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 93 | /** |
| 94 | * Destroy the current session. |
| 95 | * |
| 96 | * This frees up all memory used by the session. |
| 97 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 98 | * @return SR_OK upon success, SR_ERR_BUG if no session exists. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 99 | */ |
Uwe Hermann | 1a081ca | 2012-02-01 23:40:35 +0100 | [diff] [blame] | 100 | SR_API int sr_session_destroy(void) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 101 | { |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 102 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 103 | sr_err("%s: session was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 104 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Lars-Peter Clausen | ed229aa | 2012-07-05 21:15:07 +0200 | [diff] [blame] | 107 | sr_session_dev_remove_all(); |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 108 | |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 109 | sr_session_datafeed_callback_remove_all(); |
| 110 | |
| 111 | if (session->sources) { |
| 112 | g_free(session->sources); |
| 113 | session->sources = NULL; |
| 114 | } |
| 115 | |
| 116 | if (session->pollfds) { |
| 117 | g_free(session->pollfds); |
| 118 | session->pollfds = NULL; |
| 119 | } |
| 120 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 121 | /* TODO: Error checks needed? */ |
| 122 | |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 123 | // g_mutex_clear(&session->stop_mutex); |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 124 | |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 125 | g_free(session); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 126 | session = NULL; |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 127 | |
| 128 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 129 | } |
| 130 | |
Uwe Hermann | 961009b | 2013-02-01 22:58:54 +0100 | [diff] [blame] | 131 | /** |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 132 | * Remove all the devices from the current session. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 133 | * |
| 134 | * The session itself (i.e., the struct sr_session) is not free'd and still |
| 135 | * exists after this function returns. |
| 136 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 137 | * @return SR_OK upon success, SR_ERR_BUG if no session exists. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 138 | */ |
Uwe Hermann | 01c3e9d | 2012-03-28 21:55:48 +0200 | [diff] [blame] | 139 | SR_API int sr_session_dev_remove_all(void) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 140 | { |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 141 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 142 | sr_err("%s: session was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 143 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Bert Vermeulen | 681803d | 2013-04-28 22:35:42 +0200 | [diff] [blame] | 146 | g_slist_free(session->devs); |
Uwe Hermann | bb7ef79 | 2012-02-17 22:25:01 +0100 | [diff] [blame] | 147 | session->devs = NULL; |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 148 | |
| 149 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 152 | /** |
Uwe Hermann | 9c5332d | 2012-10-21 16:52:56 +0200 | [diff] [blame] | 153 | * Add a device instance to the current session. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 154 | * |
Uwe Hermann | 9c5332d | 2012-10-21 16:52:56 +0200 | [diff] [blame] | 155 | * @param sdi The device instance to add to the current session. Must not |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 156 | * be NULL. Also, sdi->driver and sdi->driver->dev_open must |
| 157 | * not be NULL. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 158 | * |
| 159 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments. |
| 160 | */ |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 161 | SR_API int sr_session_dev_add(const struct sr_dev_inst *sdi) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 162 | { |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 163 | |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 164 | if (!sdi) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 165 | sr_err("%s: sdi was NULL", __func__); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 166 | return SR_ERR_ARG; |
| 167 | } |
| 168 | |
Uwe Hermann | d6eb0c3 | 2012-03-18 12:57:34 +0100 | [diff] [blame] | 169 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 170 | sr_err("%s: session was NULL", __func__); |
Uwe Hermann | d6eb0c3 | 2012-03-18 12:57:34 +0100 | [diff] [blame] | 171 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 174 | /* If sdi->driver is NULL, this is a virtual device. */ |
| 175 | if (!sdi->driver) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 176 | sr_dbg("%s: sdi->driver was NULL, this seems to be " |
Uwe Hermann | d6eb0c3 | 2012-03-18 12:57:34 +0100 | [diff] [blame] | 177 | "a virtual device; continuing", __func__); |
| 178 | /* Just add the device, don't run dev_open(). */ |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 179 | session->devs = g_slist_append(session->devs, (gpointer)sdi); |
Uwe Hermann | d6eb0c3 | 2012-03-18 12:57:34 +0100 | [diff] [blame] | 180 | return SR_OK; |
| 181 | } |
| 182 | |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 183 | /* sdi->driver is non-NULL (i.e. we have a real device). */ |
| 184 | if (!sdi->driver->dev_open) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 185 | sr_err("%s: sdi->driver->dev_open was NULL", __func__); |
Uwe Hermann | 8ec95d2 | 2012-03-21 19:28:43 +0100 | [diff] [blame] | 186 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 189 | session->devs = g_slist_append(session->devs, (gpointer)sdi); |
Bert Vermeulen | aa4b110 | 2011-01-24 07:46:16 +0100 | [diff] [blame] | 190 | |
Uwe Hermann | e46b8fb | 2011-01-29 16:23:12 +0100 | [diff] [blame] | 191 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 192 | } |
| 193 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 194 | /** |
Uwe Hermann | 01c3e9d | 2012-03-28 21:55:48 +0200 | [diff] [blame] | 195 | * Remove all datafeed callbacks in the current session. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 196 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 197 | * @return SR_OK upon success, SR_ERR_BUG if no session exists. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 198 | */ |
Uwe Hermann | 01c3e9d | 2012-03-28 21:55:48 +0200 | [diff] [blame] | 199 | SR_API int sr_session_datafeed_callback_remove_all(void) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 200 | { |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 201 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 202 | sr_err("%s: session was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 203 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 206 | g_slist_free_full(session->datafeed_callbacks, g_free); |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 207 | session->datafeed_callbacks = NULL; |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 208 | |
| 209 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 212 | /** |
| 213 | * Add a datafeed callback to the current session. |
| 214 | * |
Uwe Hermann | d08490a | 2012-02-29 21:56:24 +0100 | [diff] [blame] | 215 | * @param cb Function to call when a chunk of data is received. |
Uwe Hermann | 0abee50 | 2012-03-04 15:08:11 +0100 | [diff] [blame] | 216 | * Must not be NULL. |
Uwe Hermann | 8522279 | 2013-04-16 12:48:58 +0200 | [diff] [blame] | 217 | * @param cb_data Opaque pointer passed in by the caller. |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 218 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 219 | * @return SR_OK upon success, SR_ERR_BUG if no session exists. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 220 | */ |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 221 | SR_API int sr_session_datafeed_callback_add(sr_datafeed_callback_t cb, void *cb_data) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 222 | { |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 223 | struct datafeed_callback *cb_struct; |
| 224 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 225 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 226 | sr_err("%s: session was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 227 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Uwe Hermann | 0abee50 | 2012-03-04 15:08:11 +0100 | [diff] [blame] | 230 | if (!cb) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 231 | sr_err("%s: cb was NULL", __func__); |
Uwe Hermann | 0abee50 | 2012-03-04 15:08:11 +0100 | [diff] [blame] | 232 | return SR_ERR_ARG; |
| 233 | } |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 234 | |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 235 | if (!(cb_struct = g_try_malloc0(sizeof(struct datafeed_callback)))) |
| 236 | return SR_ERR_MALLOC; |
| 237 | |
| 238 | cb_struct->cb = cb; |
| 239 | cb_struct->cb_data = cb_data; |
| 240 | |
Uwe Hermann | 62c8202 | 2010-04-15 20:16:53 +0200 | [diff] [blame] | 241 | session->datafeed_callbacks = |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 242 | g_slist_append(session->datafeed_callbacks, cb_struct); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 243 | |
| 244 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 247 | static int sr_session_run_poll(void) |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 248 | { |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 249 | unsigned int i; |
| 250 | int ret; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 251 | |
Bert Vermeulen | 2cbeb2b | 2012-08-03 01:04:05 +0200 | [diff] [blame] | 252 | while (session->num_sources > 0) { |
| 253 | ret = g_poll(session->pollfds, session->num_sources, |
| 254 | session->source_timeout); |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 255 | for (i = 0; i < session->num_sources; i++) { |
| 256 | if (session->pollfds[i].revents > 0 || (ret == 0 |
| 257 | && session->source_timeout == session->sources[i].timeout)) { |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 258 | /* |
| 259 | * Invoke the source's callback on an event, |
Bert Vermeulen | 2cbeb2b | 2012-08-03 01:04:05 +0200 | [diff] [blame] | 260 | * or if the poll timed out and this source |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 261 | * asked for that timeout. |
| 262 | */ |
Bert Vermeulen | 2cbeb2b | 2012-08-03 01:04:05 +0200 | [diff] [blame] | 263 | if (!session->sources[i].cb(session->pollfds[i].fd, |
| 264 | session->pollfds[i].revents, |
| 265 | session->sources[i].cb_data)) |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 266 | sr_session_source_remove(session->sources[i].poll_object); |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 267 | } |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 268 | /* |
| 269 | * We want to take as little time as possible to stop |
| 270 | * the session if we have been told to do so. Therefore, |
| 271 | * we check the flag after processing every source, not |
| 272 | * just once per main event loop. |
| 273 | */ |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 274 | // g_mutex_lock(&session->stop_mutex); |
Bert Vermeulen | 0372864 | 2013-04-30 00:04:39 +0200 | [diff] [blame] | 275 | if (session->abort_session) { |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 276 | sr_session_stop_sync(); |
Bert Vermeulen | 0372864 | 2013-04-30 00:04:39 +0200 | [diff] [blame] | 277 | /* But once is enough. */ |
| 278 | session->abort_session = FALSE; |
| 279 | } |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 280 | // g_mutex_unlock(&session->stop_mutex); |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 281 | } |
| 282 | } |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 283 | |
| 284 | return SR_OK; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 287 | /** |
| 288 | * Start a session. |
| 289 | * |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 290 | * There can only be one session at a time. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 291 | * |
| 292 | * @return SR_OK upon success, SR_ERR upon errors. |
| 293 | */ |
Uwe Hermann | 1a081ca | 2012-02-01 23:40:35 +0100 | [diff] [blame] | 294 | SR_API int sr_session_start(void) |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 295 | { |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 296 | struct sr_dev_inst *sdi; |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 297 | GSList *l; |
| 298 | int ret; |
| 299 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 300 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 301 | sr_err("%s: session was NULL; a session must be " |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 302 | "created before starting it.", __func__); |
Uwe Hermann | 0abee50 | 2012-03-04 15:08:11 +0100 | [diff] [blame] | 303 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 304 | } |
| 305 | |
Uwe Hermann | bb7ef79 | 2012-02-17 22:25:01 +0100 | [diff] [blame] | 306 | if (!session->devs) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 307 | sr_err("%s: session->devs was NULL; a session " |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 308 | "cannot be started without devices.", __func__); |
Uwe Hermann | 0abee50 | 2012-03-04 15:08:11 +0100 | [diff] [blame] | 309 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Uwe Hermann | c714260 | 2013-02-07 09:16:28 +0100 | [diff] [blame] | 312 | sr_info("Starting."); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 313 | |
Uwe Hermann | b7c3e84 | 2012-12-31 21:05:11 +0100 | [diff] [blame] | 314 | ret = SR_OK; |
Uwe Hermann | bb7ef79 | 2012-02-17 22:25:01 +0100 | [diff] [blame] | 315 | for (l = session->devs; l; l = l->next) { |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 316 | sdi = l->data; |
| 317 | if ((ret = sdi->driver->dev_acquisition_start(sdi, sdi)) != SR_OK) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 318 | sr_err("%s: could not start an acquisition " |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 319 | "(%d)", __func__, ret); |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 320 | break; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 321 | } |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 322 | } |
| 323 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 324 | /* TODO: What if there are multiple devices? Which return code? */ |
| 325 | |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 326 | return ret; |
| 327 | } |
| 328 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 329 | /** |
| 330 | * Run the session. |
| 331 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 332 | * @return SR_OK upon success, SR_ERR_BUG upon errors. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 333 | */ |
Uwe Hermann | 1a081ca | 2012-02-01 23:40:35 +0100 | [diff] [blame] | 334 | SR_API int sr_session_run(void) |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 335 | { |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 336 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 337 | sr_err("%s: session was NULL; a session must be " |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 338 | "created first, before running it.", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 339 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Uwe Hermann | bb7ef79 | 2012-02-17 22:25:01 +0100 | [diff] [blame] | 342 | if (!session->devs) { |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 343 | /* TODO: Actually the case? */ |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 344 | sr_err("%s: session->devs was NULL; a session " |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 345 | "cannot be run without devices.", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 346 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 347 | } |
| 348 | |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 349 | sr_info("Running."); |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 350 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 351 | /* Do we have real sources? */ |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 352 | if (session->num_sources == 1 && session->pollfds[0].fd == -1) { |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 353 | /* Dummy source, freewheel over it. */ |
Bert Vermeulen | 2cbeb2b | 2012-08-03 01:04:05 +0200 | [diff] [blame] | 354 | while (session->num_sources) |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 355 | session->sources[0].cb(-1, 0, session->sources[0].cb_data); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 356 | } else { |
| 357 | /* Real sources, use g_poll() main loop. */ |
Uwe Hermann | 8a2efef | 2011-02-08 18:00:49 +0100 | [diff] [blame] | 358 | sr_session_run_poll(); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 361 | return SR_OK; |
Bert Vermeulen | 7d65887 | 2011-01-31 22:34:14 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 364 | /** |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 365 | * Stop the current session. |
| 366 | * |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 367 | * The current session is stopped immediately, with all acquisition sessions |
Uwe Hermann | c09f0b5 | 2012-02-28 23:52:30 +0100 | [diff] [blame] | 368 | * being stopped and hardware drivers cleaned up. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 369 | * |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 370 | * This must be called from within the session thread, to prevent freeing |
| 371 | * resources that the session thread will try to use. |
| 372 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 373 | * @return SR_OK upon success, SR_ERR_BUG if no session exists. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 374 | */ |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 375 | SR_PRIV int sr_session_stop_sync(void) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 376 | { |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 377 | struct sr_dev_inst *sdi; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 378 | GSList *l; |
| 379 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 380 | if (!session) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 381 | sr_err("%s: session was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 382 | return SR_ERR_BUG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 385 | sr_info("Stopping."); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 386 | |
Uwe Hermann | bb7ef79 | 2012-02-17 22:25:01 +0100 | [diff] [blame] | 387 | for (l = session->devs; l; l = l->next) { |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 388 | sdi = l->data; |
| 389 | if (sdi->driver) { |
| 390 | if (sdi->driver->dev_acquisition_stop) |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 391 | sdi->driver->dev_acquisition_stop(sdi, NULL); |
Bert Vermeulen | 8c76be5 | 2012-01-08 22:05:00 +0100 | [diff] [blame] | 392 | } |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 393 | } |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 394 | |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 395 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 396 | } |
| 397 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 398 | /** |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 399 | * Stop the current session. |
| 400 | * |
| 401 | * The current session is stopped immediately, with all acquisition sessions |
| 402 | * being stopped and hardware drivers cleaned up. |
| 403 | * |
| 404 | * If the session is run in a separate thread, this function will not block |
| 405 | * until the session is finished executing. It is the caller's responsibility |
| 406 | * to wait for the session thread to return before assuming that the session is |
| 407 | * completely decommissioned. |
| 408 | * |
| 409 | * @return SR_OK upon success, SR_ERR_BUG if no session exists. |
| 410 | */ |
| 411 | SR_API int sr_session_stop(void) |
| 412 | { |
| 413 | if (!session) { |
| 414 | sr_err("%s: session was NULL", __func__); |
| 415 | return SR_ERR_BUG; |
| 416 | } |
| 417 | |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 418 | // g_mutex_lock(&session->stop_mutex); |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 419 | session->abort_session = TRUE; |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 420 | // g_mutex_unlock(&session->stop_mutex); |
Alexandru Gagniuc | 33c6e4c | 2013-02-02 00:50:00 -0600 | [diff] [blame] | 421 | |
| 422 | return SR_OK; |
| 423 | } |
| 424 | |
| 425 | /** |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 426 | * Debug helper. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 427 | * |
Bert Vermeulen | 996b0c7 | 2012-02-13 02:13:51 +0100 | [diff] [blame] | 428 | * @param packet The packet to show debugging information for. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 429 | */ |
Joel Holdsworth | bf53457 | 2012-12-13 21:07:53 +0000 | [diff] [blame] | 430 | static void datafeed_dump(const struct sr_datafeed_packet *packet) |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 431 | { |
Joel Holdsworth | bf53457 | 2012-12-13 21:07:53 +0000 | [diff] [blame] | 432 | const struct sr_datafeed_logic *logic; |
| 433 | const struct sr_datafeed_analog *analog; |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 434 | |
| 435 | switch (packet->type) { |
| 436 | case SR_DF_HEADER: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 437 | sr_dbg("bus: Received SR_DF_HEADER packet."); |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 438 | break; |
| 439 | case SR_DF_TRIGGER: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 440 | sr_dbg("bus: Received SR_DF_TRIGGER packet."); |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 441 | break; |
Bert Vermeulen | c71bac3 | 2013-01-20 16:37:23 +0100 | [diff] [blame] | 442 | case SR_DF_META: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 443 | sr_dbg("bus: Received SR_DF_META packet."); |
Bert Vermeulen | ee7489d | 2012-04-22 18:11:31 +0200 | [diff] [blame] | 444 | break; |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 445 | case SR_DF_LOGIC: |
| 446 | logic = packet->payload; |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 447 | sr_dbg("bus: Received SR_DF_LOGIC packet (%" PRIu64 " bytes).", |
| 448 | logic->length); |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 449 | break; |
Bert Vermeulen | ee7489d | 2012-04-22 18:11:31 +0200 | [diff] [blame] | 450 | case SR_DF_ANALOG: |
| 451 | analog = packet->payload; |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 452 | sr_dbg("bus: Received SR_DF_ANALOG packet (%d samples).", |
| 453 | analog->num_samples); |
Bert Vermeulen | ee7489d | 2012-04-22 18:11:31 +0200 | [diff] [blame] | 454 | break; |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 455 | case SR_DF_END: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 456 | sr_dbg("bus: Received SR_DF_END packet."); |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 457 | break; |
Bert Vermeulen | 6ea7669 | 2012-04-30 19:55:06 +0200 | [diff] [blame] | 458 | case SR_DF_FRAME_BEGIN: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 459 | sr_dbg("bus: Received SR_DF_FRAME_BEGIN packet."); |
Bert Vermeulen | 6ea7669 | 2012-04-30 19:55:06 +0200 | [diff] [blame] | 460 | break; |
| 461 | case SR_DF_FRAME_END: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 462 | sr_dbg("bus: Received SR_DF_FRAME_END packet."); |
Bert Vermeulen | 6ea7669 | 2012-04-30 19:55:06 +0200 | [diff] [blame] | 463 | break; |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 464 | default: |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 465 | sr_dbg("bus: Received unknown packet type: %d.", packet->type); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 466 | break; |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 467 | } |
Bert Vermeulen | 7d2afd6 | 2011-06-20 11:42:43 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 470 | /** |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 471 | * Send a packet to whatever is listening on the datafeed bus. |
| 472 | * |
| 473 | * Hardware drivers use this to send a data packet to the frontend. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 474 | * |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 475 | * @param sdi TODO. |
Uwe Hermann | 31ccebc | 2012-02-29 22:08:45 +0100 | [diff] [blame] | 476 | * @param packet The datafeed packet to send to the session bus. |
Uwe Hermann | 44dae53 | 2012-02-17 20:44:19 +0100 | [diff] [blame] | 477 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 478 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments. |
Uwe Hermann | b4bd708 | 2012-10-19 10:07:22 +0200 | [diff] [blame] | 479 | * |
| 480 | * @private |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 481 | */ |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 482 | SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi, |
Joel Holdsworth | bf53457 | 2012-12-13 21:07:53 +0000 | [diff] [blame] | 483 | const struct sr_datafeed_packet *packet) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 484 | { |
| 485 | GSList *l; |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 486 | struct datafeed_callback *cb_struct; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 487 | |
Bert Vermeulen | de4d3f9 | 2012-07-22 15:31:56 +0200 | [diff] [blame] | 488 | if (!sdi) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 489 | sr_err("%s: sdi was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 490 | return SR_ERR_ARG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 491 | } |
| 492 | |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 493 | if (!packet) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 494 | sr_err("%s: packet was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 495 | return SR_ERR_ARG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Uwe Hermann | 62c8202 | 2010-04-15 20:16:53 +0200 | [diff] [blame] | 498 | for (l = session->datafeed_callbacks; l; l = l->next) { |
Bert Vermeulen | 18beaef | 2012-02-13 00:08:23 +0100 | [diff] [blame] | 499 | if (sr_log_loglevel_get() >= SR_LOG_DBG) |
| 500 | datafeed_dump(packet); |
Martin Ling | 2726474 | 2013-04-15 21:08:55 +0100 | [diff] [blame] | 501 | cb_struct = l->data; |
| 502 | cb_struct->cb(sdi, packet, cb_struct->cb_data); |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 503 | } |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 504 | |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 505 | return SR_OK; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 508 | /** |
| 509 | * Add an event source for a file descriptor. |
| 510 | * |
| 511 | * @param pollfd The GPollFD. |
| 512 | * @param timeout Max time to wait before the callback is called, ignored if 0. |
| 513 | * @param cb Callback function to add. Must not be NULL. |
| 514 | * @param cb_data Data for the callback function. Can be NULL. |
| 515 | * @param poll_object TODO. |
| 516 | * |
| 517 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 518 | * SR_ERR_MALLOC upon memory allocation errors. |
| 519 | */ |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 520 | static int _sr_session_source_add(GPollFD *pollfd, int timeout, |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 521 | sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi, gintptr poll_object) |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 522 | { |
| 523 | struct source *new_sources, *s; |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 524 | GPollFD *new_pollfds; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 525 | |
Uwe Hermann | d08490a | 2012-02-29 21:56:24 +0100 | [diff] [blame] | 526 | if (!cb) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 527 | sr_err("%s: cb was NULL", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 528 | return SR_ERR_ARG; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Uwe Hermann | 1f9813e | 2012-02-29 22:32:34 +0100 | [diff] [blame] | 531 | /* Note: cb_data can be NULL, that's not a bug. */ |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 532 | |
Bert Vermeulen | 2ac2e62 | 2012-07-22 15:32:35 +0200 | [diff] [blame] | 533 | new_pollfds = g_try_realloc(session->pollfds, |
| 534 | sizeof(GPollFD) * (session->num_sources + 1)); |
Lars-Peter Clausen | 0687dfc | 2012-06-30 20:54:43 +0200 | [diff] [blame] | 535 | if (!new_pollfds) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 536 | sr_err("%s: new_pollfds malloc failed", __func__); |
Lars-Peter Clausen | 0687dfc | 2012-06-30 20:54:43 +0200 | [diff] [blame] | 537 | return SR_ERR_MALLOC; |
| 538 | } |
| 539 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 540 | new_sources = g_try_realloc(session->sources, sizeof(struct source) * |
Bert Vermeulen | 2ac2e62 | 2012-07-22 15:32:35 +0200 | [diff] [blame] | 541 | (session->num_sources + 1)); |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 542 | if (!new_sources) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 543 | sr_err("%s: new_sources malloc failed", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 544 | return SR_ERR_MALLOC; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 545 | } |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 546 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 547 | new_pollfds[session->num_sources] = *pollfd; |
| 548 | s = &new_sources[session->num_sources++]; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 549 | s->timeout = timeout; |
Uwe Hermann | d08490a | 2012-02-29 21:56:24 +0100 | [diff] [blame] | 550 | s->cb = cb; |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 551 | s->cb_data = sdi; |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 552 | s->poll_object = poll_object; |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 553 | session->pollfds = new_pollfds; |
| 554 | session->sources = new_sources; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 555 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 556 | if (timeout != session->source_timeout && timeout > 0 |
| 557 | && (session->source_timeout == -1 || timeout < session->source_timeout)) |
| 558 | session->source_timeout = timeout; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 559 | |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 560 | return SR_OK; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 561 | } |
| 562 | |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 563 | /** |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 564 | * Add an event source for a file descriptor. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 565 | * |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 566 | * @param fd The file descriptor. |
| 567 | * @param events Events to check for. |
| 568 | * @param timeout Max time to wait before the callback is called, ignored if 0. |
| 569 | * @param cb Callback function to add. Must not be NULL. |
| 570 | * @param cb_data Data for the callback function. Can be NULL. |
Uwe Hermann | 44dae53 | 2012-02-17 20:44:19 +0100 | [diff] [blame] | 571 | * |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 572 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 573 | * SR_ERR_MALLOC upon memory allocation errors. |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 574 | */ |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 575 | SR_API int sr_session_source_add(int fd, int events, int timeout, |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 576 | sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi) |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 577 | { |
| 578 | GPollFD p; |
| 579 | |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 580 | p.fd = fd; |
| 581 | p.events = events; |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 582 | |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 583 | return _sr_session_source_add(&p, timeout, cb, sdi, (gintptr)fd); |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
Uwe Hermann | 1a895c6 | 2012-07-05 01:47:44 +0200 | [diff] [blame] | 587 | * Add an event source for a GPollFD. |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 588 | * |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 589 | * @param pollfd The GPollFD. |
| 590 | * @param timeout Max time to wait before the callback is called, ignored if 0. |
| 591 | * @param cb Callback function to add. Must not be NULL. |
| 592 | * @param cb_data Data for the callback function. Can be NULL. |
| 593 | * |
| 594 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 595 | * SR_ERR_MALLOC upon memory allocation errors. |
| 596 | */ |
| 597 | SR_API int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout, |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 598 | sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi) |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 599 | { |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 600 | return _sr_session_source_add(pollfd, timeout, cb, |
| 601 | sdi, (gintptr)pollfd); |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /** |
Uwe Hermann | 1a895c6 | 2012-07-05 01:47:44 +0200 | [diff] [blame] | 605 | * Add an event source for a GIOChannel. |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 606 | * |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 607 | * @param channel The GIOChannel. |
| 608 | * @param events Events to poll on. |
| 609 | * @param timeout Max time to wait before the callback is called, ignored if 0. |
| 610 | * @param cb Callback function to add. Must not be NULL. |
| 611 | * @param cb_data Data for the callback function. Can be NULL. |
| 612 | * |
| 613 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 614 | * SR_ERR_MALLOC upon memory allocation errors. |
| 615 | */ |
Uwe Hermann | 1a895c6 | 2012-07-05 01:47:44 +0200 | [diff] [blame] | 616 | SR_API int sr_session_source_add_channel(GIOChannel *channel, int events, |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 617 | int timeout, sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi) |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 618 | { |
| 619 | GPollFD p; |
| 620 | |
| 621 | #ifdef _WIN32 |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 622 | g_io_channel_win32_make_pollfd(channel, events, &p); |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 623 | #else |
| 624 | p.fd = g_io_channel_unix_get_fd(channel); |
| 625 | p.events = events; |
| 626 | #endif |
| 627 | |
Bert Vermeulen | f1b296f | 2013-12-16 01:31:46 +0100 | [diff] [blame] | 628 | return _sr_session_source_add(&p, timeout, cb, sdi, (gintptr)channel); |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 629 | } |
| 630 | |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 631 | /** |
| 632 | * Remove the source belonging to the specified channel. |
| 633 | * |
| 634 | * @todo Add more error checks and logging. |
| 635 | * |
| 636 | * @param channel The channel for which the source should be removed. |
| 637 | * |
| 638 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 639 | * SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon |
| 640 | * internal errors. |
| 641 | */ |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 642 | static int _sr_session_source_remove(gintptr poll_object) |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 643 | { |
| 644 | struct source *new_sources; |
Lars-Peter Clausen | 0687dfc | 2012-06-30 20:54:43 +0200 | [diff] [blame] | 645 | GPollFD *new_pollfds; |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 646 | unsigned int old; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 647 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 648 | if (!session->sources || !session->num_sources) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 649 | sr_err("%s: sources was NULL", __func__); |
Uwe Hermann | 0abee50 | 2012-03-04 15:08:11 +0100 | [diff] [blame] | 650 | return SR_ERR_BUG; |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 651 | } |
| 652 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 653 | for (old = 0; old < session->num_sources; old++) { |
| 654 | if (session->sources[old].poll_object == poll_object) |
Lars-Peter Clausen | 2bccd32 | 2012-06-30 20:54:42 +0200 | [diff] [blame] | 655 | break; |
| 656 | } |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 657 | |
Lars-Peter Clausen | 2bccd32 | 2012-06-30 20:54:42 +0200 | [diff] [blame] | 658 | /* fd not found, nothing to do */ |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 659 | if (old == session->num_sources) |
Lars-Peter Clausen | 2bccd32 | 2012-06-30 20:54:42 +0200 | [diff] [blame] | 660 | return SR_OK; |
| 661 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 662 | session->num_sources -= 1; |
Lars-Peter Clausen | 2bccd32 | 2012-06-30 20:54:42 +0200 | [diff] [blame] | 663 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 664 | if (old != session->num_sources) { |
| 665 | memmove(&session->pollfds[old], &session->pollfds[old+1], |
| 666 | (session->num_sources - old) * sizeof(GPollFD)); |
| 667 | memmove(&session->sources[old], &session->sources[old+1], |
| 668 | (session->num_sources - old) * sizeof(struct source)); |
Lars-Peter Clausen | 2bccd32 | 2012-06-30 20:54:42 +0200 | [diff] [blame] | 669 | } |
| 670 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 671 | new_pollfds = g_try_realloc(session->pollfds, sizeof(GPollFD) * session->num_sources); |
| 672 | if (!new_pollfds && session->num_sources > 0) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 673 | sr_err("%s: new_pollfds malloc failed", __func__); |
Lars-Peter Clausen | 0687dfc | 2012-06-30 20:54:43 +0200 | [diff] [blame] | 674 | return SR_ERR_MALLOC; |
| 675 | } |
| 676 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 677 | new_sources = g_try_realloc(session->sources, sizeof(struct source) * session->num_sources); |
| 678 | if (!new_sources && session->num_sources > 0) { |
Uwe Hermann | a421dc1 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 679 | sr_err("%s: new_sources malloc failed", __func__); |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 680 | return SR_ERR_MALLOC; |
Uwe Hermann | 9f45fb3 | 2012-01-02 14:15:25 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Lars-Peter Clausen | b7e9411 | 2012-07-06 23:23:31 +0200 | [diff] [blame] | 683 | session->pollfds = new_pollfds; |
| 684 | session->sources = new_sources; |
Uwe Hermann | e0508e6 | 2012-01-07 17:08:54 +0100 | [diff] [blame] | 685 | |
| 686 | return SR_OK; |
Bert Vermeulen | 544a458 | 2011-01-30 02:40:55 +0100 | [diff] [blame] | 687 | } |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 688 | |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 689 | /** |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 690 | * Remove the source belonging to the specified file descriptor. |
| 691 | * |
Uwe Hermann | 1a895c6 | 2012-07-05 01:47:44 +0200 | [diff] [blame] | 692 | * @param fd The file descriptor for which the source should be removed. |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 693 | * |
| 694 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 695 | * SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon |
| 696 | * internal errors. |
| 697 | */ |
| 698 | SR_API int sr_session_source_remove(int fd) |
| 699 | { |
| 700 | return _sr_session_source_remove((gintptr)fd); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Remove the source belonging to the specified poll descriptor. |
| 705 | * |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 706 | * @param pollfd The poll descriptor for which the source should be removed. |
| 707 | * |
| 708 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 709 | * SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon |
| 710 | * internal errors. |
| 711 | */ |
| 712 | SR_API int sr_session_source_remove_pollfd(GPollFD *pollfd) |
| 713 | { |
| 714 | return _sr_session_source_remove((gintptr)pollfd); |
| 715 | } |
| 716 | |
Uwe Hermann | 6b2d8d3 | 2012-10-21 23:24:42 +0200 | [diff] [blame] | 717 | /** |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 718 | * Remove the source belonging to the specified channel. |
| 719 | * |
Uwe Hermann | 1a895c6 | 2012-07-05 01:47:44 +0200 | [diff] [blame] | 720 | * @param channel The channel for which the source should be removed. |
Lars-Peter Clausen | aac0ea2 | 2012-06-30 20:54:44 +0200 | [diff] [blame] | 721 | * |
| 722 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or |
| 723 | * SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon |
| 724 | * internal errors. |
| 725 | */ |
| 726 | SR_API int sr_session_source_remove_channel(GIOChannel *channel) |
| 727 | { |
| 728 | return _sr_session_source_remove((gintptr)channel); |
| 729 | } |
Uwe Hermann | 7b870c3 | 2012-10-21 16:13:36 +0200 | [diff] [blame] | 730 | |
| 731 | /** @} */ |