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.h | |
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.h')
-rw-r--r-- | src/mm-port-serial.h | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/mm-port-serial.h b/src/mm-port-serial.h index 8f357ae0..708e3912 100644 --- a/src/mm-port-serial.h +++ b/src/mm-port-serial.h @@ -40,6 +40,12 @@ #define MM_PORT_SERIAL_SPEW_CONTROL "spew-control" /* Construct-only */ #define MM_PORT_SERIAL_FLASH_OK "flash-ok" /* Construct-only */ +typedef enum { + MM_PORT_SERIAL_RESPONSE_NONE, + MM_PORT_SERIAL_RESPONSE_BUFFER, + MM_PORT_SERIAL_RESPONSE_ERROR, +} MMPortSerialResponseType; + typedef struct _MMPortSerial MMPortSerial; typedef struct _MMPortSerialClass MMPortSerialClass; typedef struct _MMPortSerialPrivate MMPortSerialPrivate; @@ -58,16 +64,26 @@ struct _MMPortSerialClass { */ void (*parse_unsolicited) (MMPortSerial *self, GByteArray *response); - /* Called to parse the device's response to a command or determine if the - * response was an error response. If the response indicates an error, an - * appropriate error should be returned in the 'error' argument. The - * function should return FALSE if there is not enough data yet to determine - * the device's reply (whether success *or* error), and should return TRUE - * when the device's response has been recognized and parsed. + /* + * Called to parse the device's response to a command or determine if the + * response was an error response. + * + * If the response indicates an error, @MM_PORT_SERIAL_RESPONSE_ERROR will + * be returned and an appropriate GError set in @error. + * + * If the response indicates a valid response, @MM_PORT_SERIAL_RESPONSE_BUFFER + * will be returned, and a newly allocated GByteArray set in @parsed_response. + * + * If there is no response, @MM_PORT_SERIAL_RESPONSE_NONE will be returned, + * and neither @error nor @parsed_response will be set. + * + * The implementation is allowed to cleanup the @response byte array, e.g. to + * just remove 1 single response if more than one found. */ - gboolean (*parse_response) (MMPortSerial *self, - GByteArray *response, - GError **error); + MMPortSerialResponseType (*parse_response) (MMPortSerial *self, + GByteArray *response, + GByteArray **parsed_response, + GError **error); /* Called to configure the serial port fd after it's opened. On error, should * return FALSE and set 'error' as appropriate. |