diff options
author | pradeep kumar B <b.pradeep@samsung.com> | 2016-06-20 11:05:55 +0530 |
---|---|---|
committer | pradeep kumar B <b.pradeep@samsung.com> | 2016-06-20 11:05:55 +0530 |
commit | 51f3316475f649b8e17eeb95f1b46e7762345d09 (patch) | |
tree | 38091290ee6f758a4231f9b0b3eedb7e96f3bc3f | |
parent | 3086306811b0d8f92d839264f4df089df35dc679 (diff) | |
download | http-51f3316475f649b8e17eeb95f1b46e7762345d09.tar.gz http-51f3316475f649b8e17eeb95f1b46e7762345d09.tar.bz2 http-51f3316475f649b8e17eeb95f1b46e7762345d09.zip |
[capi-http] Implemented the Progress callback for download/upload requestssubmit/tizen/20160621.234856submit/tizen/20160621.060739accepted/tizen/wearable/20160623.120435accepted/tizen/mobile/20160623.120355accepted/tizen/common/20160621.184456
Change-Id: I5d2137585472cd78c91b36be9bdc2b166408b228
Signed-off-by: pradeep kumar B <b.pradeep@samsung.com>
-rw-r--r-- | src/http_transaction.c | 20 | ||||
-rw-r--r-- | test/http_test.c | 8 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/http_transaction.c b/src/http_transaction.c index 11689da..9473985 100644 --- a/src/http_transaction.c +++ b/src/http_transaction.c @@ -143,6 +143,22 @@ size_t __http_debug_received(CURL* easy_handle, curl_infotype type, gchar* byte, return 0; } +int __progress_cb(void *user_data, double dltotal, double dlnow, double ultotal, double ulnow) +{ + __http_transaction_h *transaction = (__http_transaction_h *)user_data; + + double total_download = dltotal; + double current_download = dlnow; + double total_upload = ultotal; + double current_upload = ulnow; + + if (transaction->progress_cb) + transaction->progress_cb(transaction, total_download, current_download, + total_upload, current_upload, transaction->progress_user_data); + + return 0; +} + //LCOV_EXCL_START int http_transaction_set_authentication_info(http_transaction_h http_transaction) { @@ -346,6 +362,10 @@ int _transaction_submit(gpointer user_data) curl_easy_setopt(transaction->easy_handle, CURLOPT_READDATA, transaction); } + curl_easy_setopt(transaction->easy_handle, CURLOPT_NOPROGRESS, FALSE); + curl_easy_setopt(transaction->easy_handle, CURLOPT_PROGRESSFUNCTION, __progress_cb); + curl_easy_setopt(transaction->easy_handle, CURLOPT_PROGRESSDATA, transaction); + curl_easy_setopt(transaction->easy_handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(transaction->easy_handle, CURLOPT_DEBUGFUNCTION, __http_debug_received); curl_easy_setopt(transaction->easy_handle, CURLOPT_ERRORBUFFER, transaction->error); diff --git a/test/http_test.c b/test/http_test.c index 738d6dc..ebf32d3 100644 --- a/test/http_test.c +++ b/test/http_test.c @@ -96,6 +96,13 @@ void __transaction_aborted_cb(http_transaction_h transaction, int reason, void * DBG("aborted reason: %d\n", reason); } +void __transaction_progress_cb(http_transaction_h transaction, double download_total, double download_now, double upload_total, double upload_now, void *user_data) +{ + PRG("__transaction_progress_cb", transaction); + DBG("Download ====>: DOWN(%lf/%lf)\n", download_total, download_now); + DBG("Upload ====>: UP(%lf/%lf)\n", upload_total, upload_now); +} + void _register_callbacks(http_transaction_h transaction) { http_transaction_set_received_header_cb(transaction, __transaction_header_cb, NULL); @@ -103,6 +110,7 @@ void _register_callbacks(http_transaction_h transaction) http_transaction_set_uploaded_cb(transaction, __transaction_write_cb, NULL); http_transaction_set_completed_cb(transaction, __transaction_completed_cb, NULL); http_transaction_set_aborted_cb(transaction, __transaction_aborted_cb, NULL); + http_transaction_set_progress_cb(transaction, __transaction_progress_cb, NULL); } int test_http_init(void) |