diff options
Diffstat (limited to 'android/android-device.h')
-rw-r--r-- | android/android-device.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/android/android-device.h b/android/android-device.h index 9fde906..6825819 100644 --- a/android/android-device.h +++ b/android/android-device.h @@ -108,6 +108,17 @@ /* Definis infinite timeout. */ #define AD_INFINITE_WAIT -1 +/* Enumerates results of asynchronous data transfer. + */ +typedef enum ATResult { + /* Data transfer has been completed. */ + ATR_SUCCESS, + /* Socket got disconnected while data transfer has been in progress. */ + ATR_DISCONNECT, + /* An I/O error has occured. 'errno' contains error value. */ + ATR_IO_ERROR, +} ATResult; + /* Android device descriptor. */ typedef struct AndroidDevice AndroidDevice; @@ -149,6 +160,20 @@ typedef void (*event_cb)(void* opaque, AndroidDevice* ad, char* msg, int msgsize */ typedef void (*io_failure_cb)(void* opaque, AndroidDevice* ad, int failure); +/* Callback routine that is invoked when an asynchronous data send has been + * completed. + * Param: + * opaque - An opaque pointer associated with the data. + * res - Result of data transfer. + * data, size - Transferred data buffer. + * sent - Number of sent bytes. + */ +typedef void (*async_send_cb)(void* opaque, + ATResult res, + void* data, + int size, + int sent); + /******************************************************************************** * Android Device API. *******************************************************************************/ @@ -222,6 +247,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. @@ -236,4 +302,20 @@ extern int android_device_listen(AndroidDevice* ad, int buffsize, event_cb on_event); +/* Asynchronously sends data to the android device. + * Param: + * ad - Android device descriptor, returned from android_device_init API. + * data, size - Buffer containing data to send. + * free_on_close - A boolean flag indicating whether the data buffer should be + * freed upon data transfer completion. + * cb - Callback to invoke when data transfer is completed. + * opaque - An opaque pointer to pass to the transfer completion callback. + */ +extern int android_device_send_async(AndroidDevice* ad, + void* data, + int size, + int free_on_close, + async_send_cb cb, + void* opaque); + #endif /* ANDROID_ANDROID_DEVICE_H_ */ |