[PATCH 3/4] port-serial-at: always prepend unsolicited message handlers

Aleksander Morgado aleksander at aleksander.es
Sun May 21 19:49:50 UTC 2017


The generic modem has several URC handlers for generic messages, like
+CIEV. But, there may be cases where the plugins themselves want to
provide their own URC handlers to be run before the generic one.

This patch enables this setup by always prepending the new URC
handlers, so that the last ones added are processed before the ones
already in the list. So if a plugin does its own unsolicited
messages setup, they can run first the parent setup and then their
own.

The only thing to consider is that the regex provided by the plugin
must be specific enough not to match the specific messages required
by the parent implementation.
---
 src/mm-port-serial-at.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c
index 8e2aa2aa..fb2174da 100644
--- a/src/mm-port-serial-at.c
+++ b/src/mm-port-serial-at.c
@@ -207,9 +207,12 @@ mm_port_serial_at_add_unsolicited_msg_handler (MMPortSerialAt *self,
         if (handler->notify)
             handler->notify (handler->user_data);
     } else {
+        /* The new handler is always PREPENDED, so that e.g. plugins can provide
+         * more specific matches for URCs that are also handled by the generic
+         * plugin. */
         handler = g_slice_new (MMAtUnsolicitedMsgHandler);
-        self->priv->unsolicited_msg_handlers = g_slist_append (self->priv->unsolicited_msg_handlers, handler);
         handler->regex = g_regex_ref (regex);
+        self->priv->unsolicited_msg_handlers = g_slist_prepend (self->priv->unsolicited_msg_handlers, handler);
     }
 
     handler->callback = callback;
-- 
2.12.2



More information about the ModemManager-devel mailing list