[capi-http] Implemented the Progress callback for download/upload requests 75/75475/1 accepted/tizen/common/20160621.184456 accepted/tizen/mobile/20160623.120355 accepted/tizen/wearable/20160623.120435 submit/tizen/20160621.060739 submit/tizen/20160621.234856
authorpradeep kumar B <b.pradeep@samsung.com>
Mon, 20 Jun 2016 05:35:55 +0000 (11:05 +0530)
committerpradeep kumar B <b.pradeep@samsung.com>
Mon, 20 Jun 2016 05:35:55 +0000 (11:05 +0530)
Change-Id: I5d2137585472cd78c91b36be9bdc2b166408b228
Signed-off-by: pradeep kumar B <b.pradeep@samsung.com>
src/http_transaction.c
test/http_test.c

index 11689da..9473985 100644 (file)
@@ -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);
index 738d6dc..ebf32d3 100644 (file)
@@ -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)