diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-01-18 18:23:40 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2016-01-23 11:19:19 +0100 |
commit | 97962bb65caaabc4133740a2698dae2406be319e (patch) | |
tree | de72f4b2fc5bbb356ad4f6fc4c3d0faa6d3f8cdf /src/mm-port-serial-gps.c | |
parent | ede17bd41c044af1d59b347f8859a9894272d27e (diff) |
port-serial: rework response parsing
Response parsing was being done in different places for AT and QCDM subclasses;
in the case of AT it was being done early, before returning the byte array in
the mm_serial_port_command_finish() response. In the case of QCDM, it was being
done after mm_serial_port_command_finish(), and that was forcing every caller to
cleanup the response buffer once the response was processed.
With the new logic in this patch, the response is always parsed (i.e. looked for
a valid response or an error detected) before mm_serial_port_command_finish()
returns, and actually this method now returns a totally different GByteArray,
not the internal response buffer GByteArray, so there's no longer any need for
the caller to explicitly clean it up. The one doing the cleanup is the parser
method itself in every case.
This change also allows us to return serial port responses in idle, but that's
not changed for now as there's no immediate need.
Diffstat (limited to 'src/mm-port-serial-gps.c')
-rw-r--r-- | src/mm-port-serial-gps.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/mm-port-serial-gps.c b/src/mm-port-serial-gps.c index 306df1fe..b316d05e 100644 --- a/src/mm-port-serial-gps.c +++ b/src/mm-port-serial-gps.c @@ -68,9 +68,10 @@ remove_eval_cb (const GMatchInfo *match_info, return FALSE; } -static gboolean +static MMPortSerialResponseType parse_response (MMPortSerial *port, GByteArray *response, + GByteArray **parsed_response, GError **error) { MMPortSerialGps *self = MM_PORT_SERIAL_GPS (port); @@ -112,7 +113,7 @@ parse_response (MMPortSerial *port, g_match_info_free (match_info); if (!matches) - return FALSE; + return MM_PORT_SERIAL_RESPONSE_NONE; /* Remove matches */ result_len = response->len; @@ -122,9 +123,11 @@ parse_response (MMPortSerial *port, 0, 0, remove_eval_cb, &result_len, NULL); + /* Cleanup response buffer */ g_byte_array_remove_range (response, 0, response->len); - g_byte_array_append (response, (const guint8 *) str, result_len); - g_free (str); + + /* Build parsed response */ + *parsed_response = g_byte_array_new_take ((guint8 *)str, result_len); return TRUE; } |