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