[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / file-download.h
1 #ifndef DALI_TIZEN_PLATFORM_NETWORK_FILE_DOWNLOAD_H
2 #define DALI_TIZEN_PLATFORM_NETWORK_FILE_DOWNLOAD_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <stdint.h> // uint8
24 #include <mutex>    //c++11
25 #include <string>
26
27 namespace Dali
28 {
29 namespace TizenPlatform
30 {
31 namespace Network
32 {
33 /**
34  * Set up the cURL environment - this will ensure curl_global_init is called on startup
35  * and curl_global_cleanup is called on shutdown.
36  * Having this environment enables curl to be used in a single or multi-threaded
37  * program safely.
38  */
39 class CurlEnvironment
40 {
41 public:
42   /**
43    * Constructor calls curl_global_init()
44    */
45   CurlEnvironment();
46
47   /**
48    * Destructor calls curl_global_cleanup()
49    */
50   ~CurlEnvironment();
51
52   // Moveable but not copyable
53
54   CurlEnvironment(const CurlEnvironment&) = delete;
55   CurlEnvironment& operator=(const CurlEnvironment&) = delete;
56   CurlEnvironment(CurlEnvironment&&)                 = default;
57   CurlEnvironment& operator=(CurlEnvironment&&) = default;
58 };
59
60 /**
61  * Download a requested file into a memory buffer.
62  *
63  * @note Threading notes: This function can be called from multiple threads, however
64  * we must explicitly call curl_global_init() from a single thread before using curl
65  * as the global function calls are not thread safe.
66  *
67  * @param[in] url The requested file url
68  * @param[out] dataBuffer  A memory buffer object to be written with downloaded file data.
69  * @param[out] dataSize  The size of the memory buffer.
70  * @param[in] maximumAllowedSize The maxmimum allowed file size in bytes to download. E.g. for an Image file this may be 50 MB
71  * @return true on success, false on failure
72  *
73  */
74 bool DownloadRemoteFileIntoMemory(const std::string&     url,
75                                   Dali::Vector<uint8_t>& dataBuffer,
76                                   size_t&                dataSize,
77                                   size_t                 maximumAllowedSizeBytes);
78
79 } // namespace Network
80
81 } // namespace TizenPlatform
82
83 } // namespace Dali
84
85 #endif // DALI_TIZEN_PLATFORM_RESOURCE_THREAD_IMAGE_H