diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2012-01-26 12:14:22 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-01-26 12:14:22 -0800 |
commit | 562240d8235c122b1624713169cd0764d84956d2 (patch) | |
tree | 62203684b4104ac707fe4817d4aa8a8dba6ee645 /android | |
parent | 828b135787a028f6befe56470e7233329cc45e3f (diff) | |
parent | 720d4ae010c7b2dac83ac61b96a9bf7e6f02f440 (diff) | |
download | external_qemu-562240d8235c122b1624713169cd0764d84956d2.zip external_qemu-562240d8235c122b1624713169cd0764d84956d2.tar.gz external_qemu-562240d8235c122b1624713169cd0764d84956d2.tar.bz2 |
Merge "Expand the ways how a query can be sent to Android device."
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. |