371affea59e8c87b9f3fe34c2468fb4d8998da6b
[platform/core/location/maps-plugin-here.git] / inc / engine / internal / RestCurl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #ifndef REST_CURL_H
18 #define REST_CURL_H
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <vector>
23 #include <glib.h>
24 #include <curl/curl.h>
25 #include <curl/easy.h>
26
27 #include "common/HereMaps_global.h"
28
29 #include "common/RestItemHandle.h"
30 #include "base/BaseByteBuffer.h"
31 #include "base/EventDrivenThread.h"
32
33 TIZEN_MAPS_BEGIN_NAMESPACE
34
35 using namespace Tizen::Maps;
36
37 typedef struct MemoryStruct {
38         MemoryStruct() : memory(NULL), size(0), http_code(0), error(0) {};
39
40         char *memory;
41         size_t size;
42         long http_code;
43         int error;
44 } MemoryStruct_s;
45
46 class RestCurl
47 {
48 public:
49         RestCurl();
50         virtual ~RestCurl();
51
52         static RestCurl& GetInstance();
53         bool Commit(void *pArgs);
54         void Abort(const Here::Maps::RestItemHandle::RequestId aRequestId);
55         void Clear();
56         void Join();
57         void Shutdown();
58 private:
59         int EasyCurl(String sUrl, MemoryStruct_s* pChunk
60                 #ifdef TIZEN_SUPPORT_POST_METHOD
61                 , bool bPost = false, String sPostData = ""
62                 #endif
63         );
64         static void *ThreadFunc(void *pArgs);
65         static size_t WriteMemoryCb(void *pContents, size_t nSize, size_t nNmemb, void *pUser);
66         static int XferInfoCb(void *pUser, curl_off_t dlTotal, curl_off_t dlNow,
67                                            curl_off_t ulTotal, curl_off_t ulNow);
68         String UrlEncode(String sStr);
69         bool CreateDetachedThread(void* (*pFunc)(void*), void *pArgs);
70
71         #ifdef TIZEN_SUPPORT_CRYPTO_LOCK
72         static void CryptoMutexLock(int mode, int type, char *file, int line);
73         static void CryptoInitMutexLocks(void);
74         static void CryptoKillMutexLocks(void);
75         static unsigned long CryptoThreadId(void);
76         #endif
77
78         class RestCurlImpl;
79         RestCurlImpl* m_pImpl;
80 };
81
82 TIZEN_MAPS_END_NAMESPACE
83
84 #endif /* REST_CURL_H */