diff options
author | Ben Chan <benchan@chromium.org> | 2013-08-21 17:32:23 -0700 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-08-26 15:59:29 +0200 |
commit | 0f2a0aa0bc1b5ceea8275ca5c98834195c050ed6 (patch) | |
tree | 064afab43f45faef9efcaf4e8fe6ffc1e0f383c0 /src | |
parent | 3979939eaf2a99483c50035b8c5a6c4633ce61e7 (diff) |
at-serial-port: allow enabling/disabling unsolicited message handlers
This patch adds an 'enable' flag in MMAtUnsolicitedMsgHandler and
mm_at_serial_port_enable_disable_unsolicited_msg_handler() to allow
enabling and disabling of unsolicited message handlers. The enable flag
is set to TRUE by mm_at_serial_port_add_unsolicited_msg_handler().
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-at-serial-port.c | 28 | ||||
-rw-r--r-- | src/mm-at-serial-port.h | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/mm-at-serial-port.c b/src/mm-at-serial-port.c index 346221ab..3b94458f 100644 --- a/src/mm-at-serial-port.c +++ b/src/mm-at-serial-port.c @@ -176,6 +176,7 @@ handle_response (MMSerialPort *port, typedef struct { GRegex *regex; MMAtSerialUnsolicitedMsgFn callback; + gboolean enable; gpointer user_data; GDestroyNotify notify; } MMAtUnsolicitedMsgHandler; @@ -219,10 +220,34 @@ mm_at_serial_port_add_unsolicited_msg_handler (MMAtSerialPort *self, } handler->callback = callback; + handler->enable = TRUE; handler->user_data = user_data; handler->notify = notify; } +void +mm_at_serial_port_enable_disable_unsolicited_msg_handler (MMAtSerialPort *self, + GRegex *regex, + gboolean enable) +{ + GSList *existing; + MMAtUnsolicitedMsgHandler *handler; + MMAtSerialPortPrivate *priv; + + g_return_if_fail (MM_IS_AT_SERIAL_PORT (self)); + g_return_if_fail (regex != NULL); + + priv = MM_AT_SERIAL_PORT_GET_PRIVATE (self); + + existing = g_slist_find_custom (priv->unsolicited_msg_handlers, + regex, + (GCompareFunc)unsolicited_msg_handler_cmp); + if (existing) { + handler = existing->data; + handler->enable = enable; + } +} + static gboolean remove_eval_cb (const GMatchInfo *match_info, GString *result, @@ -254,6 +279,9 @@ parse_unsolicited (MMSerialPort *port, GByteArray *response) GMatchInfo *match_info; gboolean matches; + if (!handler->enable) + continue; + matches = g_regex_match_full (handler->regex, (const char *) response->data, response->len, diff --git a/src/mm-at-serial-port.h b/src/mm-at-serial-port.h index cf960a0f..09706818 100644 --- a/src/mm-at-serial-port.h +++ b/src/mm-at-serial-port.h @@ -89,6 +89,10 @@ void mm_at_serial_port_add_unsolicited_msg_handler (MMAtSerialPort *self, gpointer user_data, GDestroyNotify notify); +void mm_at_serial_port_enable_disable_unsolicited_msg_handler (MMAtSerialPort *self, + GRegex *regex, + gboolean enable); + void mm_at_serial_port_set_response_parser (MMAtSerialPort *self, MMAtSerialResponseParserFn fn, gpointer user_data, |