|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // PUSHSMTM.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 #include "regpsdll.h" // Parser Registry - used to load the parser |
|
21 #include <msvids.h> |
|
22 #include <pushentry.h> |
|
23 #include "PushServerPanic.h" |
|
24 #include "pushservermtm.h" |
|
25 |
|
26 |
|
27 |
|
28 /** |
|
29 * Factory function for the WAP Push Server MTM. Sets the initial entry for the server to work with. |
|
30 * @param CRegisteredMtmDll& aRegisteredMtmDll |
|
31 * in: Registration data for the MTM DLL |
|
32 * @param CMsvServerEntry* aInitialEntry |
|
33 * in: initial context that the server should operate on. |
|
34 * @return CWapPushServerMtm* - new instance of the server MTM |
|
35 */ |
|
36 EXPORT_C CWapPushServerMtm* CWapPushServerMtm::NewL(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aInitialEntry) |
|
37 { |
|
38 CleanupStack::PushL(aInitialEntry); // Take ownership of aInitialEntry so it's cleaned up if we leave |
|
39 CWapPushServerMtm* myServerMtm = new(ELeave) CWapPushServerMtm(aRegisteredMtmDll,aInitialEntry); |
|
40 CleanupStack::Pop(); //safely stored aInitialEntry - we can release it now |
|
41 CleanupStack::PushL(myServerMtm); |
|
42 myServerMtm->Construct(); |
|
43 CleanupStack::Pop(); |
|
44 return myServerMtm; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Destructor |
|
49 */ |
|
50 CWapPushServerMtm::~CWapPushServerMtm() |
|
51 { |
|
52 Cancel(); |
|
53 } |
|
54 |
|
55 /** |
|
56 * C++ constructor. Passes parameters to the base constructor, and set the initial state. |
|
57 * @param CRegisteredMtmDll& aRegisteredMtmDll |
|
58 * in: Registration data for the MTM DLL |
|
59 * @param CMsvServerEntry* aInitialEntry |
|
60 * in: initial context that the server should operate on |
|
61 */ |
|
62 CWapPushServerMtm::CWapPushServerMtm(CRegisteredMtmDll& aRegisteredMtmDll, CMsvServerEntry* aInitialEntry) |
|
63 :CBaseServerMtm(aRegisteredMtmDll, aInitialEntry), iError(KErrNone),iState(EWapPushServerMtmWaiting) |
|
64 { |
|
65 __DECLARE_NAME(_S("CWAPPushServerMtm")); |
|
66 } |
|
67 |
|
68 /** |
|
69 * Second Stage Constructor. Adds the object to the Active Scheduler |
|
70 */ |
|
71 void CWapPushServerMtm::Construct() |
|
72 { |
|
73 CActiveScheduler::Add(this); |
|
74 } |
|
75 |
|
76 /** |
|
77 * MTM API Not Supported |
|
78 */ |
|
79 void CWapPushServerMtm::CopyToLocalL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& /*aStatus*/) |
|
80 { |
|
81 User::Leave(KErrNotSupported); |
|
82 } |
|
83 |
|
84 /** |
|
85 * MTM API Not Supported |
|
86 */ |
|
87 void CWapPushServerMtm::CopyFromLocalL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& /*aStatus*/) |
|
88 { |
|
89 User::Leave(KErrNotSupported); |
|
90 } |
|
91 |
|
92 /** |
|
93 * MTM API Not Supported |
|
94 */ |
|
95 void CWapPushServerMtm::CopyWithinServiceL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& /*aStatus*/) |
|
96 { |
|
97 User::Leave(KErrNotSupported); |
|
98 } |
|
99 |
|
100 /** |
|
101 * MTM API Not Supported |
|
102 */ |
|
103 void CWapPushServerMtm::MoveToLocalL(const CMsvEntrySelection& /*aSelection*/, TMsvId /*aDestination*/, TRequestStatus& /*aStatus*/) |
|
104 { |
|
105 User::Leave(KErrNotSupported); |
|
106 } |
|
107 |
|
108 /** |
|
109 * MTM API Not Supported |
|
110 */ |
|
111 void CWapPushServerMtm::MoveFromLocalL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& /*aStatus*/) |
|
112 { |
|
113 User::Leave(KErrNotSupported); |
|
114 } |
|
115 |
|
116 /** |
|
117 * MTM API Not Supported |
|
118 */ |
|
119 void CWapPushServerMtm::MoveWithinServiceL(const CMsvEntrySelection& /*aSelection*/,TMsvId /*aDestination*/, TRequestStatus& /*aStatus*/) |
|
120 { |
|
121 User::Leave(KErrNotSupported); |
|
122 } |
|
123 |
|
124 /** |
|
125 * Deletes a number of entries from the Message Server index. Also deletes child entries of the selected |
|
126 * entries. Makes a call to the Message Server to do the actual delete. |
|
127 * @param const CMsvEntrySelection& aSelection |
|
128 * in: Selection of entry Ids that the caller wants to delete |
|
129 * @param TRequestStatus& aStatus |
|
130 * in: Status object of calling object to be used to return status information |
|
131 * @leave KErrLocked Will leave if the entry is locked |
|
132 * @leave KErrAccessDenied Will leave if the entry or a descendant was locked by another client |
|
133 * @leave KErrInUse Will leave if the store or a file associated with the entry is open |
|
134 * @leave KErrNotFound Will leave if the entry is not a child of the context |
|
135 */ |
|
136 void CWapPushServerMtm::DeleteAllL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus) |
|
137 { |
|
138 __ASSERT_ALWAYS(iServerEntry!=NULL,Panic(EPushEntryNotSet)); |
|
139 ResetProgress(); |
|
140 iProgress.iTotalMsgs = aSelection.Count(); |
|
141 iState = EWapPushServerMtmDelete; |
|
142 |
|
143 // set the main server entry up to the first entry |
|
144 iError=iServerEntry->SetEntry(aSelection.At(0)); //Hold the error for progress |
|
145 User::LeaveIfError(iError); |
|
146 |
|
147 __ASSERT_ALWAYS(iServerEntry->Entry().iMtm == KUidMtmWapPush,Panic(EPushServerWrongMtm)); |
|
148 |
|
149 CMsvEntrySelection* entries=aSelection.CopyLC(); |
|
150 iError = iServerEntry->SetEntry(iServerEntry->Entry().Parent()); |
|
151 User::LeaveIfError(iError); |
|
152 |
|
153 // Call the message server to delete the entries recursively |
|
154 iError = iServerEntry->DeleteEntries(*entries); |
|
155 User::LeaveIfError(iError); |
|
156 CleanupStack::PopAndDestroy();//entries |
|
157 |
|
158 iProgress.iMsgsProcessed = aSelection.Count(); |
|
159 |
|
160 TRequestStatus* status=&aStatus; |
|
161 User::RequestComplete(status, KErrNone); |
|
162 iProgress.iMsgId = aSelection.At(0); //hold the first id for the progress |
|
163 } |
|
164 |
|
165 /** |
|
166 * Creates a new entry with this MTM group. Makes a call to the server to do the actual |
|
167 * create. Holds on to the new Id so it can returned in the Progress information. |
|
168 * @param const TMsvEntry& aSelection |
|
169 * in: entry that the user wants to create |
|
170 * @param TRequestStatus& aStatus |
|
171 * in: Status object of calling object to be used to return status information |
|
172 */ |
|
173 void CWapPushServerMtm::CreateL(TMsvEntry aNewEntry, TRequestStatus& aStatus) |
|
174 { |
|
175 ResetProgress(); |
|
176 iProgress.iTotalMsgs = 1; |
|
177 iError=iServerEntry->SetEntry(aNewEntry.Parent()); |
|
178 User::LeaveIfError(iError); |
|
179 |
|
180 __ASSERT_ALWAYS(aNewEntry.iMtm == KUidMtmWapPush,Panic(EPushServerWrongMtm)); |
|
181 |
|
182 iState = EWapPushServerMtmCreate; |
|
183 iError = iServerEntry->CreateEntry(aNewEntry); |
|
184 User::LeaveIfError(iError); |
|
185 |
|
186 TRequestStatus* status=&aStatus; |
|
187 User::RequestComplete(status, KErrNone); // No errors so far |
|
188 iProgress.iMsgsProcessed = 1; |
|
189 iProgress.iMsgId = aNewEntry.Id(); // hold the id for the progress info |
|
190 } |
|
191 |
|
192 |
|
193 /** |
|
194 * Changes the specified entry to the new values. Must be of the Push Message MTM type. |
|
195 * Makes a call to the server to do the actual change. Holds on to the Id so it |
|
196 * can returned in the Progress information. |
|
197 * @param const TMsvEntry& aEntry |
|
198 * in: entry with the new values |
|
199 * @param TRequestStatus& aStatus |
|
200 * in: Status object of calling object to be used to return status information |
|
201 */ |
|
202 |
|
203 void CWapPushServerMtm::ChangeL(TMsvEntry aEntry, TRequestStatus& aStatus) |
|
204 { |
|
205 ResetProgress(); |
|
206 iProgress.iTotalMsgs = 1; |
|
207 iState = EWapPushServerMtmChange; |
|
208 |
|
209 iError =iServerEntry->SetEntry(aEntry.Id()); //Hold the error so that the progress can return it |
|
210 User::LeaveIfError(iError); |
|
211 __ASSERT_ALWAYS(iServerEntry->Entry().iMtm == KUidMtmWapPush,Panic(EPushServerWrongMtm)); |
|
212 |
|
213 iError = iServerEntry->ChangeEntry(aEntry); |
|
214 User::LeaveIfError(iError); |
|
215 |
|
216 TRequestStatus* status=&aStatus; |
|
217 User::RequestComplete(status, KErrNone); |
|
218 |
|
219 //Update progress |
|
220 iProgress.iMsgsProcessed=1; |
|
221 iProgress.iMsgId = aEntry.Id(); //hold the id for the progress |
|
222 } |
|
223 |
|
224 /** |
|
225 * Function called when server specific commands are required. Case statement is used to call the |
|
226 * appropriate function. Currently there are no commands which are not defined in the base class. |
|
227 * If any specific commands are to be added for this MTM then the call should be made via this function. |
|
228 * @param CMsvEntrySelection& aSelection |
|
229 * in: group of message entry Ids to be operated on. |
|
230 * @param TInt aCommand |
|
231 * in: parameter specifying the MTM specific command to be executed |
|
232 |
|
233 * @param const TDesC8& aParameter |
|
234 * in: Command-specific parameters |
|
235 * @param TRequestStatus& aStatus |
|
236 * in : reference to use to return asynchronous completion status information |
|
237 * @leave KErrNotSupported - currently don't support any MTM specific commands. |
|
238 * |
|
239 */ |
|
240 void CWapPushServerMtm::StartCommandL(CMsvEntrySelection& /*aSelection*/, TInt aCommand, const TDesC8& /*aParameter*/, TRequestStatus& /*aStatus*/) |
|
241 { |
|
242 // Add any Mtm specific requests to this section. |
|
243 switch (aCommand) |
|
244 { |
|
245 case 0: //Keeps compiler happy |
|
246 default: |
|
247 User::Leave(KErrNotSupported); // Currently don't support any MTM specific commands |
|
248 break; |
|
249 } |
|
250 *iReportStatus=KRequestPending; |
|
251 User::RequestComplete(iReportStatus, KErrNone); |
|
252 |
|
253 } |
|
254 |
|
255 |
|
256 /** |
|
257 * Indicates whether any more commands are expected. This is to prevent the server unloading |
|
258 * the MTM if further commands are expected. Currently always return EFalse, so the MTM can be unloaded. |
|
259 * @return TBool - always EFalse |
|
260 */ |
|
261 TBool CWapPushServerMtm::CommandExpected() |
|
262 { |
|
263 return EFalse; // Currently ALWAYS EFalse can be deleted by Msg Server |
|
264 } |
|
265 |
|
266 /** |
|
267 * Returns a Package Buffer containing a Progress Object. Provides the caller on the current operation |
|
268 * total number of entries, number processed, Error, and the current entry. |
|
269 * @return const TDesC8& - package buffer containing the Progress object |
|
270 */ |
|
271 const TDesC8& CWapPushServerMtm::Progress() |
|
272 { |
|
273 iProgress.iPushState = iState; |
|
274 iProgress.iError=iError; |
|
275 iProgressBuf = TPushMTMProgressBuf(iProgress); |
|
276 return iProgressBuf; |
|
277 } |
|
278 |
|
279 /** |
|
280 * Cancels the current asynchronous operation. Required by the Active Object class |
|
281 * inherited by the base class. |
|
282 */ |
|
283 void CWapPushServerMtm::DoCancel() |
|
284 { |
|
285 User::RequestComplete( iReportStatus, KErrCancel ); |
|
286 } |
|
287 |
|
288 |
|
289 /** |
|
290 * Inherited from the the base class. Called by RunL. |
|
291 */ |
|
292 void CWapPushServerMtm::DoRunL() |
|
293 { |
|
294 User::RequestComplete (iReportStatus, iError); |
|
295 } |
|
296 |
|
297 /** |
|
298 * Called by the active scheduler when RunL leaves. Tidies things up and completes |
|
299 * the current asynchronous request with the error code passed as a parameter. |
|
300 * @param TInt aError |
|
301 * in: Error code |
|
302 * @return TInt error code required by Active Scheduler - KErrNone prevents Scheduler panicing |
|
303 */ |
|
304 TInt CWapPushServerMtm::RunError(TInt aError) |
|
305 { |
|
306 iError = aError; |
|
307 Cancel(); |
|
308 Complete(); |
|
309 return KErrNone; |
|
310 } |
|
311 |
|
312 /** |
|
313 * Completes the current operation with the current error level. |
|
314 */ |
|
315 void CWapPushServerMtm::Complete() |
|
316 { |
|
317 DoComplete(iError); |
|
318 } |
|
319 |
|
320 /** |
|
321 * Performs the completiong of the curent operation with the specified error code. |
|
322 */ |
|
323 void CWapPushServerMtm::DoComplete(TInt aError) |
|
324 { |
|
325 TRequestStatus* status = iReportStatus; |
|
326 User::RequestComplete(status, aError); |
|
327 } |
|
328 /** |
|
329 * Resets the progress variable. |
|
330 */ |
|
331 void CWapPushServerMtm::ResetProgress() |
|
332 { |
|
333 iProgress.iError=KErrNone; |
|
334 iProgress.iTotalMsgs = 0; |
|
335 iProgress.iMsgsProcessed =0; |
|
336 iProgress.iMsgId=KMsvNullIndexEntryId; |
|
337 |
|
338 iProgressBuf.Zero(); |
|
339 } |
|
340 |
|
341 |
|
342 |
|
343 |