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().
This commit is contained in:
committed by
Aleksander Morgado
parent
3979939eaf
commit
0f2a0aa0bc
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user