diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-01-25 12:55:06 -0800 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-01-25 12:55:06 -0800 |
commit | 720d4ae010c7b2dac83ac61b96a9bf7e6f02f440 (patch) | |
tree | 5e7df26aefceba6c4c6f824459db3cf64a4b9ab8 /android | |
parent | 2ae501556f90647e40466b6a1948f6f7f51cf251 (diff) | |
download | external_qemu-720d4ae010c7b2dac83ac61b96a9bf7e6f02f440.zip external_qemu-720d4ae010c7b2dac83ac61b96a9bf7e6f02f440.tar.gz external_qemu-720d4ae010c7b2dac83ac61b96a9bf7e6f02f440.tar.bz2 |
Expand the ways how a query can be sent to Android device.
Contains new routines that allow sending multiple blocks of data within a single
query. Also, these routines allow to avoid restriction on queries as zero-terminated
strings.
Change-Id: Ia5789a01a7eadbae5b1f5014a67864eea463af43
Diffstat (limited to 'android')
-rw-r--r-- | android/android-device.c | 29 | ||||
-rw-r--r-- | android/android-device.h | 41 |
2 files changed, 70 insertions, 0 deletions
diff --git a/android/android-device.c b/android/android-device.c index 5722a7e..f5121e8 100644 --- a/android/android-device.c +++ b/android/android-device.c @@ -1271,6 +1271,35 @@ android_device_query(AndroidDevice* ad, } int +android_device_start_query(AndroidDevice* ad, const char* query, int to) +{ + int res; + + /* Setup deadline for the query. */ + _ads_set_deadline(&ad->query_socket.dev_socket, to); + + /* Send the query header. */ + res = _android_dev_socket_send(&ad->query_socket.dev_socket, query, + strlen(query) + 1); + return (res > 0) ? 0 : -1; +} + +int +android_device_send_query_data(AndroidDevice* ad, const void* data, int size) +{ + return _android_dev_socket_send(&ad->query_socket.dev_socket, data, size); +} + +int +android_device_complete_query(AndroidDevice* ad, char* buff, size_t buffsize) +{ + /* Receive the response to the query. */ + const int res = _android_dev_socket_read_response(&ad->query_socket.dev_socket, + buff, buffsize); + return (res >= 0) ? 0 : -1; +} + +int android_device_listen(AndroidDevice* ad, char* buff, int buffsize, diff --git a/android/android-device.h b/android/android-device.h index 9fde906..769ba66 100644 --- a/android/android-device.h +++ b/android/android-device.h @@ -222,6 +222,47 @@ extern int android_device_query(AndroidDevice* ad, size_t buffsize, int to); +/* Starts a query that may require more than one buffer transfer. + * This routine allows to initiate a query that may require more than one call to + * send_data, or may have a format that differs from the usual (a zero-terminated + * string). For instance, sending a BLOB data should use this routine to start a + * a query, then use android_device_send_query_data to transfer the data, and + * then call android_device_complete_query to obtain the response. + * Param: + * ad - Android device descriptor, returned from android_device_init API. + * query - Zero-terminated query string. + * to - Milliseconds to wait for the entire query to complete. + * Return: + * Zero on success, or non-zero value on failure with 'errno' properly set: + * - 0 Indicates that the server has failed the query. + * - Anything else indicates an I/O error. + */ +extern int android_device_start_query(AndroidDevice* ad, + const char* query, + int to); + +/* Sends data block for a query started with android_device_start_query + * Param: + * ad - Android device descriptor, returned from android_device_init API. + * data, size - Data to transfer. + * Return: + * Number of bytes transferred on success, or -1 on failure with errno + * containing the reason for failure. + */ +extern int android_device_send_query_data(AndroidDevice* ad, + const void* data, + int size); + +/* Completes a query started with android_device_start_query, and receives the + * query response. + * Param: + * ad - Android device descriptor, returned from android_device_init API. + * buff, buffsize - Buffer where to receive the response to the query. + * Return: + * Zero on success, or non-zero value on failure with 'errno' properly set. + */ +extern int android_device_complete_query(AndroidDevice* ad, char* buff, size_t buffsize); + /* Start listening on the event channel. * Param: * ad - Android device descriptor, returned from android_device_init API. |