changed attributes of header files
[platform/core/location/maps-plugin-here.git] / inc / engine / internal / RestEngine.h
1 /*
2  * Copyright (C) 2013 HERE Global B.V. All rights reserved.
3  * This software, including documentation, is protected by copyright controlled by
4  * HERE Global B.V. (“Software”). All rights are reserved. Copying, including reproducing,
5  * storing, adapting or translating, any or all of this material requires the prior
6  * written consent of HERE Global B.V. You may use this
7  * Software in accordance with the terms and conditions defined in the
8  * HERE Location Platform Services Terms and Conditions, available at
9  * http://developer.here.com/terms-conditions-base
10  *
11  * As an additional permission to the above, you may distribute Software,
12  * in object code format as part of an Application, according to, and subject to, terms and
13  * conditions defined in the Tizen Software Development kit (“SDK”) License Agreement.
14  * You may distribute such object code format Application under terms of your choice,
15  * provided that the header and source files of the Software have not been modified.
16  */
17
18 #ifndef RESTENGINE_H
19 #define RESTENGINE_H
20
21 #include "common/HereMaps_global.h"
22
23 #ifndef TIZEN_MIGRATION
24 #include <FBaseObject.h>
25 #include <FBaseRtEventDrivenThread.h>
26 #include <FNetHttpIHttpTransactionEventListener.h>
27 #endif
28
29 #include "common/QueryListener.h"
30 #include "common/RestItemHandle.h"
31
32 #ifdef TIZEN_MIGRATION
33 #include "base/BaseObject.h"
34 #include "base/BaseByteBuffer.h"
35 #include "base/EventDrivenThread.h"
36 #include "internal/RestCurl.h"
37
38 using namespace Tizen::Maps;
39 #else
40 using namespace Tizen::Base::Runtime;
41 #endif
42
43 HERE_MAPS_BEGIN_NAMESPACE
44
45 class RestItem;
46 class BaseReply;
47 class QueryListener;
48
49 class RestEngineArgument
50 : public Tizen::Maps::Object
51 {
52 public:
53 #ifdef TIZEN_SUPPORT_POST_METHOD
54     RestEngineArgument(const String& sUrl, RestItem* pRestItem,
55                        bool bPost = false, const String& sPostData = "")
56     : m_sUrl(sUrl)
57     , m_pRestItem(pRestItem)
58     , m_bPost(bPost)
59     , m_sPostData(sPostData)
60 #else
61     RestEngineArgument(const String& sUrl, RestItem* pRestItem)
62     : m_sUrl(sUrl)
63     , m_pRestItem(pRestItem)
64 #endif
65     {
66     #ifdef TIZEN_MIGRATION
67         m_aRequestId = RestItemHandle::INVALID_RESTITEM;
68     #endif
69     }
70
71     RestEngineArgument(RestItemHandle::RequestId aRequestId)
72     : m_aRequestId(aRequestId)
73     {
74     #ifdef TIZEN_MIGRATION
75         m_pRestItem = NULL;
76     #ifdef TIZEN_SUPPORT_POST_METHOD
77         m_bPost = false;
78     #endif
79     #endif
80     }
81
82     RestEngineArgument(RestItem* pRestItem)
83     : m_pRestItem(pRestItem)
84     {
85     #ifdef TIZEN_MIGRATION
86         m_aRequestId = RestItemHandle::INVALID_RESTITEM;
87     #ifdef TIZEN_SUPPORT_POST_METHOD
88         m_bPost = false;
89     #endif
90     #endif
91     }
92
93     ~RestEngineArgument()
94     {
95     }
96
97     String m_sUrl;
98     RestItem* m_pRestItem;
99     RestItemHandle::RequestId m_aRequestId;
100 #ifdef TIZEN_MIGRATION
101     Tizen::Maps::MemoryStruct_s m_Chunk;
102 #endif
103 #ifdef TIZEN_SUPPORT_POST_METHOD
104     bool m_bPost;
105     String m_sPostData;
106 #endif
107 };
108
109 //this is an internal class and should not be used outside
110 class RestEngine
111 : public EventDrivenThread
112 #ifndef TIZEN_MIGRATION
113 , public Tizen::Net::Http::IHttpTransactionEventListener
114 #endif
115 {
116 public:
117     static RestEngine& GetInstance();
118
119 #ifdef TIZEN_SUPPORT_POST_METHOD
120     RestItemHandle::RequestId OpenRequest(const String& sUrl, QueryListener* pListener, BaseReplyPtr pReply,
121                                           bool bPost = false, const String& sPostData = "");
122 #else
123     RestItemHandle::RequestId OpenRequest(const String& sUrl, QueryListener* pListener, BaseReplyPtr pReply);
124 #endif
125     size_t GetNumPendingRequests() const;
126     void ShutdownEngine();
127     void AbortRequest(RestItemHandle::RequestId aRequestId);
128     void AbortListenerRequests(QueryListener* pListener);
129     void AbortAllRequests();
130     void UnregisterListener(QueryListener* pListener);
131
132     int  CountListeners() const;
133
134     static unsigned int GetMaxPendingRequests();
135
136 #ifdef TIZEN_MIGRATION
137     void FireImpl(void* pArgs);
138 #endif
139
140 private:
141     enum RequestType
142     {
143         RT_OpenRequest = 0,
144         RT_CloseRestItem,
145         RT_DeleteRestItem
146     };
147
148     bool CheckRequestIn(RestItem* pRestItem);
149     RestItem* GetChechedInRequest(RestItemHandle::RequestId aRequestId) const;
150
151     void CloseRestItemLater(RestItemHandle::RequestId aRequestId);
152     void CloseRestItem(RestItemHandle::RequestId aRequestId, bool bDeleteLater = false);
153     void DeleteRestItemLater(RestItem* pRestItem);
154
155 #ifdef TIZEN_MIGRATION
156     void OnUserEventReceivedN(int requestType, void *pArgs);
157 #else
158     void OnTransactionAborted(Tizen::Net::Http::HttpSession& httpSession,
159                               Tizen::Net::Http::HttpTransaction& httpTransaction, result r);
160
161     void OnTransactionCertVerificationRequiredN(Tizen::Net::Http::HttpSession& httpSession,
162                                                 Tizen::Net::Http::HttpTransaction& httpTransaction,
163                                                 Tizen::Base::String* pCert);
164
165     void OnTransactionCompleted(Tizen::Net::Http::HttpSession& httpSession,
166                                 Tizen::Net::Http::HttpTransaction& httpTransaction);
167
168     void OnTransactionHeaderCompleted(Tizen::Net::Http::HttpSession& httpSession,
169                                       Tizen::Net::Http::HttpTransaction& httpTransaction,
170                                       int headerLen,
171                                       bool bAuthRequired);
172
173     void OnTransactionReadyToRead(Tizen::Net::Http::HttpSession& httpSession,
174                                   Tizen::Net::Http::HttpTransaction& httpTransaction,
175                                   int availableBodyLen);
176
177     void OnTransactionReadyToWrite(Tizen::Net::Http::HttpSession& httpSession,
178                                    Tizen::Net::Http::HttpTransaction& httpTransaction,
179                                    int recommendedChunkSize);
180
181     void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList *pArgs);
182 #endif
183
184     RestEngine();
185     ~RestEngine();
186
187     void Begin();
188
189     void LockPendingRequests() const;
190     void UnlockPendingRequests() const;
191
192     void LockListenersRegistery() const;
193     void UnlockListenersRegistery() const;
194
195     bool OnStart();
196     void OnStop();
197
198     void RegisterListener(QueryListener* rListener);
199
200 #ifdef TIZEN_SUPPORT_POST_METHOD
201     bool DoOpenRequest(const String& sUrl, RestItem* pRestItem,
202                        bool bPost = false, const String& sPostData = "");
203 #else
204     bool DoOpenRequest(const String& sUrl, RestItem* pRestItem);
205 #endif
206     void DoCloseRestItemLater(RestItemHandle::RequestId aRequestId);
207     void DoDeleteRestItemLater(RestItem* pRestItem);
208
209     //classes allowed to access this internal instance
210     friend class RestItem;
211     friend class QueryListener;
212 #ifdef TIZEN_SUPPORT_TILE_FILE_CACHE
213     friend class TileFetcherQuery;
214 #endif
215
216     //members
217     class RestEngineImpl;
218     RestEngineImpl* m_pImpl;
219 };
220
221 HERE_MAPS_END_NAMESPACE
222
223 #endif