|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The client side connection to the FeedsSever. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "FeedsServerClient.h" |
|
20 #include "FeedsServerMsg.h" |
|
21 #include "FeedsServerSettings.h" |
|
22 #include "Logger.h" |
|
23 #include "ClientRequestHandlers.h" |
|
24 #include "FeedRequestHandlers.h" |
|
25 #include "FolderItemRequestHandlers.h" |
|
26 |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // RFeedsServer::RFeedsServer |
|
30 // |
|
31 // C++ default constructor can NOT contain any code that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 EXPORT_C RFeedsServer::RFeedsServer( MFeedsServerObserver& aObserver, TInt aFolderListId ): |
|
36 iObserver(aObserver), iFolderListId(aFolderListId) |
|
37 { |
|
38 |
|
39 CClientRequestHandler *requestHandler = NULL; |
|
40 |
|
41 TRAP_IGNORE ( |
|
42 { |
|
43 requestHandler = CClientRequestHandler::NewL( this, aFolderListId ); |
|
44 |
|
45 CleanupStack::PushL(requestHandler); |
|
46 iActiveRequests.AppendL(requestHandler); |
|
47 CleanupStack::Pop(requestHandler); |
|
48 }); |
|
49 |
|
50 |
|
51 #ifdef TRACK_LEAKS |
|
52 delete gLeakTracker; |
|
53 gLeakTracker = NULL; |
|
54 |
|
55 TRAP_IGNORE(gLeakTracker = CLeakTracker::NewL(_L("FeedsServerClient"))); |
|
56 #endif |
|
57 } |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // RFeedsServer::Connect |
|
62 // |
|
63 // Connects to the server. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C TInt RFeedsServer::Connect() |
|
67 { |
|
68 return iActiveRequests[0]->GetFeedInterface()->Connect(); |
|
69 } |
|
70 |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // RFeedsServer::Close |
|
74 // |
|
75 // Closes the connection to the server. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C void RFeedsServer::Close() |
|
79 { |
|
80 |
|
81 iActiveRequests[0]->GetFeedInterface()->Close(); |
|
82 |
|
83 iActiveRequests.ResetAndDestroy(); |
|
84 |
|
85 #ifdef TRACK_LEAKS |
|
86 delete gLeakTracker; |
|
87 gLeakTracker = NULL; |
|
88 #endif |
|
89 } |
|
90 |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // RFeedsServer::Version |
|
94 // |
|
95 // Defines server version number |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C TVersion RFeedsServer::Version() const |
|
99 { |
|
100 return(TVersion(KFeedsServerMajorVersionNumber, KFeedsServerMinorVersionNumber, |
|
101 KFeedsServerBuildVersionNumber)); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // RFeedsServer::RequestHandlerCompletedL |
|
106 // |
|
107 // Notifies the observer that the request is completed. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void RFeedsServer::RequestHandlerCompletedL(CTransaction& aTrans, TInt aStatus) |
|
111 { |
|
112 TFeedsServerSetting setting; |
|
113 |
|
114 // Notify the observer if an error occurred. |
|
115 switch (aTrans.Type()) |
|
116 { |
|
117 case CTransaction::EFetchSettings: |
|
118 { |
|
119 // Notify the observer that the request has completed. |
|
120 if (aStatus == KErrNone) |
|
121 { |
|
122 setting = iActiveRequests[0]->GetFeedInterface()->Settings(); |
|
123 iSettings.SetAutoUpdate(setting.iAutoUpdate); |
|
124 iSettings.SetAutoUpdateAP(setting.iAutoUpdateAP); |
|
125 iSettings.SetAutoUpdateFreq(setting.iAutoUpdateFreq); |
|
126 iSettings.SetAutoUpdateWhileRoaming(setting.iAutoUpdateWhileRoaming); |
|
127 } |
|
128 iObserver.SettingsChanged( aStatus ); |
|
129 |
|
130 break; |
|
131 } |
|
132 |
|
133 case CTransaction::EWatchForSettingChanges: |
|
134 { |
|
135 // Only notify the user if an error occurred. |
|
136 if (aStatus != KErrNone) |
|
137 { |
|
138 iObserver.SettingsChanged(aStatus); |
|
139 } |
|
140 break; |
|
141 } |
|
142 |
|
143 case CTransaction::EChangeSettings: |
|
144 break; |
|
145 } |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // RFeedsServer::RequestCompletedL |
|
150 // |
|
151 // Called to handle the response. |
|
152 // ----------------------------------------------------------------------------- |
|
153 void RFeedsServer::RequestCompleted(CTransaction* aTrans, TInt /*aStatus*/) |
|
154 { |
|
155 // Notify the observer if an error occurred. |
|
156 switch (aTrans->Type()) |
|
157 { |
|
158 //Server related |
|
159 case CTransaction::EFetchSettings: |
|
160 case CTransaction::EWatchForSettingChanges: |
|
161 case CTransaction::EChangeSettings: |
|
162 { |
|
163 TRAP_IGNORE(RequestHandlerCompletedL(*aTrans, aTrans->GetStatusCode())); |
|
164 break; |
|
165 } |
|
166 //Feed related |
|
167 case CTransaction::EFetchFeed: |
|
168 case CTransaction::EUpdateItemStatus: |
|
169 { |
|
170 TRAP_IGNORE(iActiveRequests[0]->GetFeedsServerFeed()->RequestHandlerCompletedL(*aTrans, aTrans->GetStatusCode())); |
|
171 break; |
|
172 } |
|
173 //Folder item related |
|
174 default: |
|
175 { |
|
176 TRAP_IGNORE(iActiveRequests[0]->GetFeedsServerFolderItem()->RequestHandlerCompletedL(*aTrans, aTrans->GetStatusCode())); |
|
177 break; |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // RFeedsServer::NetworkConnectionNeededL |
|
184 // |
|
185 // Request to create a network connection. |
|
186 // ----------------------------------------------------------------------------- |
|
187 void RFeedsServer::NetworkConnectionNeededL(TInt* aConnectionPtr, TInt& aSockSvrHandle, |
|
188 TBool& aNewConn, TApBearerType& aBearerType) |
|
189 { |
|
190 TBool feedOperationRequested = EFalse; |
|
191 TBool FolderItemOperationRequested = EFalse; |
|
192 CClientRequestHandler *requestHandler = iActiveRequests[0]; |
|
193 |
|
194 RFeed* feedsServerFeed = requestHandler->GetFeedsServerFeed(); |
|
195 CFeedRequestHandler *feedReqHandler = feedsServerFeed->iActiveRequests[0]; |
|
196 feedOperationRequested = feedReqHandler->GetOperationRequested(); |
|
197 |
|
198 RFolderItem* feedsServerFolderItem = requestHandler->GetFeedsServerFolderItem(); |
|
199 CFolderItemRequestHandler *folderReqHandler = feedsServerFolderItem->iActiveRequests[0]; |
|
200 FolderItemOperationRequested = folderReqHandler->GetOperationRequested(); |
|
201 |
|
202 |
|
203 if( feedOperationRequested ) |
|
204 { |
|
205 feedsServerFeed->NetworkConnectionNeededL(aConnectionPtr, aSockSvrHandle, aNewConn, aBearerType); |
|
206 } |
|
207 else if ( FolderItemOperationRequested ) |
|
208 { |
|
209 feedsServerFolderItem->NetworkConnectionNeededL(aConnectionPtr, aSockSvrHandle, aNewConn, aBearerType); |
|
210 } |
|
211 } |
|
212 |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // RFeedsServer::DebugPrintTablesL |
|
216 // |
|
217 // Print tables of database. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C void RFeedsServer::DebugPrintTablesL() |
|
221 { |
|
222 iActiveRequests[0]->GetFeedInterface()->DebugPrintTablesL(); |
|
223 } |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // RFeedsServer::DisconnectManualUpdateConnectionL |
|
228 // |
|
229 // Disconnect connection provided by client for manual update. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C void RFeedsServer::DisconnectManualUpdateConnectionL() |
|
233 { |
|
234 iActiveRequests[0]->GetFeedInterface()->DisconnectManualUpdateConnectionL(); |
|
235 } |
|
236 |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // RFeedsServer::Settings |
|
240 // |
|
241 // Once fetched, it returns the Settings. This method panics the client if it is |
|
242 // called before the Settings is available. |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C const TFeedsServerSettings RFeedsServer::Settings() const |
|
246 { |
|
247 return iSettings; |
|
248 } |
|
249 |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // RFeedsServer::SettingsL |
|
253 // |
|
254 // Returns feed related settings. |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 EXPORT_C const TFeedsServerSettings RFeedsServer::FetchServerSettingsSyncL() const |
|
258 { |
|
259 TFeedsServerSetting setting; |
|
260 TFeedsServerSettings settings; |
|
261 CClientRequestHandler *requestHandler = iActiveRequests[0]; |
|
262 |
|
263 RFeedsServer* self = const_cast<RFeedsServer*>(this); |
|
264 |
|
265 self->iActiveRequests[0]->GetFeedInterface()->GetSettingsL(setting, EFalse); |
|
266 |
|
267 settings.SetAutoUpdate(setting.iAutoUpdate); |
|
268 settings.SetAutoUpdateAP(setting.iAutoUpdateAP); |
|
269 settings.SetAutoUpdateFreq(setting.iAutoUpdateFreq); |
|
270 settings.SetAutoUpdateWhileRoaming(setting.iAutoUpdateWhileRoaming); |
|
271 |
|
272 return settings; |
|
273 } |
|
274 |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // RFeedsServer::UpdateSettingsL |
|
278 // |
|
279 // Requests the server to change its settings to match the provided values. |
|
280 // Some care is needed by the client to prevent settings loss if SettingsChanged |
|
281 // was called after it called SettingsL. |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C void RFeedsServer::UpdateSettingsL( const TFeedsServerSettings& aNewSettings ) |
|
285 { |
|
286 |
|
287 TFeedsServerSetting setting; |
|
288 |
|
289 setting.iAutoUpdate = aNewSettings.AutoUpdate(); |
|
290 setting.iAutoUpdateAP = aNewSettings.AutoUpdateAP(); |
|
291 setting.iAutoUpdateFreq = aNewSettings.AutoUpdateFreq(); |
|
292 setting.iAutoUpdateWhileRoaming = aNewSettings.AutoUpdateWhileRoaming(); |
|
293 |
|
294 iActiveRequests[0]->GetFeedInterface()->SetSettingsL(setting); |
|
295 |
|
296 iPendingSettings = aNewSettings; |
|
297 } |
|
298 |
|
299 // ----------------------------------------------------------------------------- |
|
300 // RFeedsServer::WatchSettingsL |
|
301 // |
|
302 // Sets up a notifier to execute when the settings change. |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 EXPORT_C void RFeedsServer::WatchSettingsL() |
|
306 { |
|
307 iActiveRequests[0]->GetFeedInterface()->WatchSettingsL(); |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // RFeedsServer::FetchServerSettingsL |
|
312 // |
|
313 // Fetch the feeds server settings. |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C void RFeedsServer::FetchServerSettingsL() |
|
317 { |
|
318 TFeedsServerSetting setting; |
|
319 TFeedsServerSettings settings; |
|
320 |
|
321 iActiveRequests[0]->GetFeedInterface()->GetSettingsL(setting); |
|
322 settings.SetAutoUpdate(setting.iAutoUpdate); |
|
323 settings.SetAutoUpdateAP(setting.iAutoUpdateAP); |
|
324 settings.SetAutoUpdateFreq(setting.iAutoUpdateFreq); |
|
325 settings.SetAutoUpdateWhileRoaming(setting.iAutoUpdateWhileRoaming); |
|
326 } |
|
327 |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // RFeedsServer::CancelAllL |
|
331 // |
|
332 // Request the FeedsServer to cancel all activities that can be cancelled. |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 EXPORT_C void RFeedsServer::CancelAllL() |
|
336 { |
|
337 iActiveRequests[0]->GetFeedInterface()->CancelAllL(); |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // RFeedsServer::SetServerFeed |
|
342 // |
|
343 // Sets the address of RFeed instance which will be used for sending |
|
344 // RequestCompleted |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void RFeedsServer::SetServerFeed(RFeed& aFeedsServerFeed) |
|
348 { |
|
349 iActiveRequests[0]->SetFeedsServerFeed(&aFeedsServerFeed); |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // RFeedsServer::SetServerFolderItem |
|
354 // |
|
355 // Sets the address of RFolderItem instance which will be used for sending |
|
356 // RequestCompleted |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void RFeedsServer::SetServerFolderItem(RFolderItem& aFeedsServerFolderItem) |
|
360 { |
|
361 iActiveRequests[0]->SetFeedsServerFolderItem(&aFeedsServerFolderItem); |
|
362 } |
|
363 |