1 #ifndef __DALI_TIZEN_PLATFORM_NETWORK_FILE_DOWNLOAD_H__
2 #define __DALI_TIZEN_PLATFORM_NETWORK_FILE_DOWNLOAD_H__
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-vector.h>
24 #include <mutex> //c++11
25 #include <stdint.h> // uint8
26 #include <openssl/crypto.h>
31 namespace TizenPlatform
38 * Set up the cURL environment - this will ensure curl_global_init is called on startup
39 * and curl_global_cleanup is called on shutdown.
40 * Having this environment enables curl to be used in a single or multi-threaded
47 * Constructor calls curl_global_init()
52 * Destructor calls curl_global_cleanup()
56 // Moveable but not copyable
58 CurlEnvironment( const CurlEnvironment& ) = delete;
59 CurlEnvironment& operator=( const CurlEnvironment& ) = delete;
60 CurlEnvironment( CurlEnvironment&& ) = default;
61 CurlEnvironment& operator=( CurlEnvironment&& ) = default;
64 * Locking function for libcurl with openssl
66 static void OnOpenSSLLocking( int mode, int n, const char* file, int line );
69 * Gets thread id for libcurl with openssl
71 static void GetThreadId( CRYPTO_THREADID* tid );
73 static void ConfigureCurlOptions( void* curlHandle, const std::string& url );
75 static void InitWriteFunction( void* curlHandle );
79 void SetLockingFunction();
81 void UnsetLockingFunction();
83 static std::mutex* mMutexs;
88 * Download a requested file into a memory buffer.
90 * @note Threading notes: This function can be called from multiple threads, however
91 * we must explicitly call curl_global_init() from a single thread before using curl
92 * as the global function calls are not thread safe.
94 * @param[in] url The requested file url
95 * @param[out] dataBuffer A memory buffer object to be written with downloaded file data.
96 * @param[out] dataSize The size of the memory buffer.
97 * @param[in] maximumAllowedSize The maxmimum allowed file size in bytes to download. E.g. for an Image file this may be 50 MB
98 * @return true on success, false on failure
101 bool DownloadRemoteFileIntoMemory( const std::string& url,
102 Dali::Vector<uint8_t>& dataBuffer,
104 size_t maximumAllowedSizeBytes );
106 } // namespace Network
108 } // namespace TizenPlatform
112 #endif // __DALI_TIZEN_PLATFORM_RESOURCE_THREAD_IMAGE_H__