[PATCH v2 1/2] at-serial-port: allow enabling/disabling unsolicited message handlers

Ben Chan benchan at chromium.org
Wed Aug 21 17:32:23 PDT 2013


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().
---
 src/mm-at-serial-port.c | 28 ++++++++++++++++++++++++++++
 src/mm-at-serial-port.h |  4 ++++
 2 files changed, 32 insertions(+)

diff --git a/src/mm-at-serial-port.c b/src/mm-at-serial-port.c
index 346221a..3b94458 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 cf960a0..0970681 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,
-- 
1.8.3



More information about the ModemManager-devel mailing list