[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / windows / curl-environment-win.cpp
1 /*\r
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  *\r
16  */\r
17 \r
18 // EXTERNAL INCLUDES\r
19 #include <string>\r
20 #include <curl/curl.h>\r
21 \r
22 // INTERNAL INCLUDES\r
23 #include <dali/internal/imaging/common/file-download.h>\r
24 #include <dali/integration-api/debug.h>\r
25 #include <dali/internal/system/common/file-closer.h>\r
26 #include <dali/internal/window-system/windows/platform-implement-win.h>\r
27 \r
28 namespace Dali\r
29 {\r
30 \r
31 namespace TizenPlatform\r
32 {\r
33 \r
34 const int CONNECTION_TIMEOUT_SECONDS( 30L );\r
35 const long VERBOSE_MODE = 0L;                // 0 == off, 1 == on\r
36 const long CLOSE_CONNECTION_ON_ERROR = 1L;   // 0 == off, 1 == on\r
37 const long EXCLUDE_HEADER = 0L;\r
38 const long INCLUDE_HEADER = 1L;\r
39 const long INCLUDE_BODY = 0L;\r
40 const long EXCLUDE_BODY = 1L;\r
41 \r
42 namespace Network\r
43 {\r
44 \r
45 unsigned long CurlEnvironment::GetThreadId()\r
46 {\r
47   // If dali uses c++ thread, we may replace pthread_self() to this_thread::get_id()\r
48   return Internal::Adaptor::WindowsPlatformImplement::GetCurrentThreadId();\r
49 }\r
50 \r
51 void CurlEnvironment::ConfigureCurlOptions( void* curlHandle, const std::string& url )\r
52 {\r
53   curl_easy_setopt( curlHandle, CURLOPT_URL, url.c_str() );\r
54   //curl_easy_setopt( curlHandle, CURLOPT_VERBOSE, VERBOSE_MODE );\r
55   curl_easy_setopt( curlHandle, CURLOPT_PROXY, "109.123.100.31:3128" );\r
56 \r
57   // CURLOPT_FAILONERROR is not fail-safe especially when authentication is involved ( see manual )\r
58   // Removed CURLOPT_FAILONERROR option\r
59   curl_easy_setopt( curlHandle, CURLOPT_CONNECTTIMEOUT, CONNECTION_TIMEOUT_SECONDS );\r
60   curl_easy_setopt( curlHandle, CURLOPT_HEADER, INCLUDE_HEADER );\r
61   curl_easy_setopt( curlHandle, CURLOPT_NOBODY, EXCLUDE_BODY );\r
62 }\r
63 \r
64 static size_t WriteFunction( void *input, size_t uSize, size_t uCount, void *avg )\r
65 {\r
66   Internal::Platform::InternalFile::fwrite( input, uSize, uCount, (FILE*)avg );\r
67   return uSize * uCount;\r
68 }\r
69 \r
70 void CurlEnvironment::InitWriteFunction( void* curlHandle )\r
71 {\r
72   curl_easy_setopt( curlHandle, CURLOPT_WRITEFUNCTION, WriteFunction );\r
73 }\r
74 }\r
75 }\r
76 }