core: let partial serial responses be consumed by the handlers
This commit is contained in:
@@ -85,7 +85,7 @@ parse_response (MMSerialPort *port, GByteArray *response, GError **error)
|
||||
return found;
|
||||
}
|
||||
|
||||
static void
|
||||
static gsize
|
||||
handle_response (MMSerialPort *port,
|
||||
GByteArray *response,
|
||||
GError *error,
|
||||
@@ -101,6 +101,8 @@ handle_response (MMSerialPort *port,
|
||||
g_string_append_len (string, (const char *) response->data, response->len);
|
||||
response_callback (self, string, error, callback_data);
|
||||
g_string_free (string, TRUE);
|
||||
|
||||
return response->len;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@@ -53,7 +53,7 @@ parse_response (MMSerialPort *port, GByteArray *response, GError **error)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
static gsize
|
||||
handle_response (MMSerialPort *port,
|
||||
GByteArray *response,
|
||||
GError *error,
|
||||
@@ -62,18 +62,34 @@ handle_response (MMSerialPort *port,
|
||||
{
|
||||
MMQcdmSerialResponseFn response_callback = (MMQcdmSerialResponseFn) callback;
|
||||
GByteArray *unescaped = NULL;
|
||||
gboolean escaping = FALSE;
|
||||
GError *dm_error = NULL;
|
||||
gsize used = 0;
|
||||
|
||||
/* Ignore empty frames */
|
||||
if (!response->len > 0 && response->data[0] == 0x7E)
|
||||
return 1;
|
||||
|
||||
if (!error) {
|
||||
unescaped = g_byte_array_sized_new (response->len);
|
||||
unescaped->len = dm_unescape ((const char *) response->data, response->len,
|
||||
(char *) unescaped->data, unescaped->len,
|
||||
&escaping);
|
||||
if (unescaped->len == 0) {
|
||||
gboolean more = FALSE, success;
|
||||
|
||||
/* FIXME: don't munge around with byte array internals */
|
||||
unescaped = g_byte_array_sized_new (1024);
|
||||
success = dm_decapsulate_buffer ((const char *) response->data,
|
||||
response->len,
|
||||
(char *) unescaped->data,
|
||||
sizeof (1024),
|
||||
&unescaped->len,
|
||||
&used,
|
||||
&more);
|
||||
if (!success) {
|
||||
g_set_error_literal (&dm_error, 0, 0, "Failed to unescape QCDM packet.");
|
||||
g_byte_array_free (unescaped, TRUE);
|
||||
unescaped = NULL;
|
||||
} else if (more) {
|
||||
/* Need more data; we shouldn't have gotten here since the parse
|
||||
* function checks for the end-of-frame marker, but whatever.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +100,8 @@ handle_response (MMSerialPort *port,
|
||||
|
||||
if (unescaped)
|
||||
g_byte_array_free (unescaped, TRUE);
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@@ -492,7 +492,7 @@ mm_serial_port_schedule_queue_process (MMSerialPort *self)
|
||||
g_source_unref (source);
|
||||
}
|
||||
|
||||
static void
|
||||
static gsize
|
||||
real_handle_response (MMSerialPort *self,
|
||||
GByteArray *response,
|
||||
GError *error,
|
||||
@@ -502,6 +502,7 @@ real_handle_response (MMSerialPort *self,
|
||||
MMSerialResponseFn response_callback = (MMSerialResponseFn) callback;
|
||||
|
||||
response_callback (self, response, error, callback_data);
|
||||
return response->len;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -509,6 +510,7 @@ mm_serial_port_got_response (MMSerialPort *self, GError *error)
|
||||
{
|
||||
MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (self);
|
||||
MMQueueData *info;
|
||||
gsize consumed = priv->response->len;
|
||||
|
||||
if (priv->timeout_id) {
|
||||
g_source_remove (priv->timeout_id);
|
||||
@@ -522,7 +524,7 @@ mm_serial_port_got_response (MMSerialPort *self, GError *error)
|
||||
|
||||
if (info->callback) {
|
||||
g_warn_if_fail (MM_SERIAL_PORT_GET_CLASS (self)->handle_response != NULL);
|
||||
MM_SERIAL_PORT_GET_CLASS (self)->handle_response (self,
|
||||
consumed = MM_SERIAL_PORT_GET_CLASS (self)->handle_response (self,
|
||||
priv->response,
|
||||
error,
|
||||
info->callback,
|
||||
@@ -536,8 +538,8 @@ mm_serial_port_got_response (MMSerialPort *self, GError *error)
|
||||
if (error)
|
||||
g_error_free (error);
|
||||
|
||||
if (priv->response->len)
|
||||
g_byte_array_remove_range (priv->response, 0, priv->response->len);
|
||||
if (consumed)
|
||||
g_byte_array_remove_range (priv->response, 0, consumed);
|
||||
if (!g_queue_is_empty (priv->queue))
|
||||
mm_serial_port_schedule_queue_process (self);
|
||||
}
|
||||
|
@@ -74,9 +74,10 @@ struct _MMSerialPortClass {
|
||||
GError **error);
|
||||
|
||||
/* Called after parsing to allow the command response to be delivered to
|
||||
* it's callback to be handled.
|
||||
* it's callback to be handled. Returns the # of bytes of the response
|
||||
* consumed.
|
||||
*/
|
||||
void (*handle_response) (MMSerialPort *self,
|
||||
gsize (*handle_response) (MMSerialPort *self,
|
||||
GByteArray *response,
|
||||
GError *error,
|
||||
GCallback callback,
|
||||
|
Reference in New Issue
Block a user