|
1 /* |
|
2 * Copyright (c) 2007 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: Interface to messaging provider |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <msvstd.h> |
|
21 #include <msvapi.h> |
|
22 #include <msvids.h> |
|
23 |
|
24 #include "messageheader.h" |
|
25 #include "messagingservice.h" |
|
26 #include "messagenotify.h" |
|
27 #include "sendmessage.h" |
|
28 #include "accessfolder.h" |
|
29 #include "messagedetail.h" |
|
30 #include "changestatus.h" |
|
31 |
|
32 |
|
33 #ifdef __WINSCW__ |
|
34 #define KFolderId KMsvDraftEntryId; |
|
35 #else |
|
36 #define KFolderId KMsvGlobalInBoxIndexEntryId; |
|
37 #endif |
|
38 |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Two-phased constructor. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C CMessagingService* CMessagingService::NewL() |
|
45 { |
|
46 CMessagingService* self = new (ELeave) CMessagingService; |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CMessagingService::~CMessagingService() |
|
58 { |
|
59 DeleteAsyncObjects();//deletes all Asychronous objects |
|
60 iAsyncObjArray.Reset(); |
|
61 delete iMsgServerSession; |
|
62 delete iSessionObserver; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Constructor. |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CMessagingService::CMessagingService() |
|
70 { |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Constructor. |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CMessagingService::ConstructL() |
|
78 { |
|
79 iSessionObserver = CMessageObserver::NewL(); |
|
80 |
|
81 iMsgServerSession = CMsvSession::OpenSyncL( *iSessionObserver ); |
|
82 |
|
83 ((CMessageObserver*)iSessionObserver)->SetSession( iMsgServerSession ); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Sends Message |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C void CMessagingService::SendMessageL( CSendMessageParams* aMessageParam, |
|
91 CMsgCallbackBase* aCallback ) |
|
92 { |
|
93 CMessageDetailInfo* templateDetail = NULL; |
|
94 |
|
95 if ( aMessageParam->TemplateId() > 0 ) |
|
96 { |
|
97 CMessageDetail* detailObj = NULL; |
|
98 |
|
99 detailObj = CMessageDetail::NewL( *iMsgServerSession ); |
|
100 |
|
101 CleanupStack::PushL( detailObj ); |
|
102 |
|
103 detailObj->GetMessageDetailL( aMessageParam->TemplateId(), templateDetail ); |
|
104 |
|
105 CleanupStack::PopAndDestroy( detailObj ); |
|
106 } |
|
107 else if ( aMessageParam->TemplateId() < 0 ) |
|
108 { |
|
109 User::Leave( KErrNotSupported ); |
|
110 } |
|
111 |
|
112 |
|
113 CSendMessage* sendMessageObj = CSendMessage::NewL( *iMsgServerSession ); |
|
114 |
|
115 CleanupStack::PushL( sendMessageObj ); |
|
116 |
|
117 // aCallback, templateDetail ownership passes to CSendMessage |
|
118 sendMessageObj->SetInputParamsL( aMessageParam, templateDetail, aCallback, this ); |
|
119 |
|
120 if ( aCallback ) |
|
121 { |
|
122 AddAsyncObjL( aCallback->iTransactionId, sendMessageObj ); |
|
123 } |
|
124 |
|
125 sendMessageObj->SendMessageL(); |
|
126 |
|
127 CleanupStack::Pop( sendMessageObj ); |
|
128 |
|
129 if ( !aCallback ) |
|
130 delete sendMessageObj; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // Deletes Message |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 EXPORT_C void CMessagingService::DeleteMessageL( const TMsvId aMessageId, |
|
138 CMsgCallbackBase* /*aCallback*/ ) |
|
139 { |
|
140 CMessageChangeStatus* obj = NULL; |
|
141 |
|
142 obj = CMessageChangeStatus::NewL( *iMsgServerSession ); |
|
143 |
|
144 CleanupStack::PushL( obj ); |
|
145 |
|
146 obj->DeleteMessageL( aMessageId ); |
|
147 |
|
148 CleanupStack::PopAndDestroy( obj ); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // Chages status of message entry |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C void CMessagingService::ChangeStatusL( const TMsvId aMessageId, |
|
156 const TMessageStatusFlag aStatusFlag, |
|
157 const TBool aFlagValue, |
|
158 CMsgCallbackBase* /*aCallback*/ ) |
|
159 { |
|
160 CMessageChangeStatus* obj = CMessageChangeStatus::NewL( *iMsgServerSession ); |
|
161 |
|
162 CleanupStack::PushL( obj ); |
|
163 |
|
164 obj->ChangeStatusL( aMessageId, aStatusFlag, aFlagValue ); |
|
165 |
|
166 CleanupStack::PopAndDestroy( obj ); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // Gives notification for new messages |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C TInt CMessagingService::RequestNotification( const TNotificationType /*aNotification*/, |
|
174 CMsgCallbackBase* aCallback ) |
|
175 { |
|
176 // Only one object can get the new message notification |
|
177 if( ( (CMessageObserver*)iSessionObserver )->IsActive() ) |
|
178 return KErrAlreadyExists; |
|
179 |
|
180 CMsgCallbackBase* oldCallback = iSessionObserver->SetCallback( aCallback ); |
|
181 |
|
182 delete oldCallback; |
|
183 |
|
184 return KErrNone; |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Cancels notification |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C TInt CMessagingService::CancelNotification( const TNotificationType /*aNotification*/, |
|
192 CMsgCallbackBase* /*aCallback*/ ) |
|
193 { |
|
194 CMsgCallbackBase* oldCallback = iSessionObserver->SetCallback( NULL ); |
|
195 |
|
196 delete oldCallback; |
|
197 |
|
198 return KErrNone; |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // Gives a sorted list of message Ids |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C void CMessagingService::GetIdListL( CFilterParamInfo* aFilterParams, |
|
206 TMsvId /*aFolderId*/, |
|
207 CMsgCallbackBase* /*aCallback*/, |
|
208 CMsvEntrySelection*& aEntrySelection ) |
|
209 { |
|
210 // Hard coding for Inbox/Draft |
|
211 // Folder Id can be passed as input parameter, to support access any folder |
|
212 TMsvId folderId = KFolderId; |
|
213 |
|
214 CMessagingAccessFolder* obj = CMessagingAccessFolder::NewL( *iMsgServerSession ); |
|
215 |
|
216 CleanupStack::PushL( obj ); |
|
217 |
|
218 obj->GetIdListL( folderId, aFilterParams, aEntrySelection ); |
|
219 |
|
220 CleanupStack::PopAndDestroy( obj ); |
|
221 } |
|
222 |
|
223 EXPORT_C void CMessagingService::GetNextHeaderL( CFilterParamInfo* aFilterParams, |
|
224 CMsvEntrySelection* aEntrySelection, |
|
225 TInt& aIndex, |
|
226 CMsgCallbackBase* /*aCallback*/, |
|
227 CMessageHeader*& aHeader ) |
|
228 { |
|
229 CMessagingAccessFolder* obj = CMessagingAccessFolder::NewL( *iMsgServerSession ); |
|
230 |
|
231 CleanupStack::PushL( obj ); |
|
232 |
|
233 obj->GetNextHeaderL( aFilterParams, aEntrySelection, aIndex, aHeader ); |
|
234 |
|
235 CleanupStack::PopAndDestroy( obj ); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // Gives details of the message |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CMessagingService::GetMessageDetailL( const TMsvId aMessageId, |
|
243 CMsgCallbackBase* /*aCallback*/, |
|
244 CMessageDetailInfo*& aResult ) |
|
245 { |
|
246 CMessageDetail* obj = CMessageDetail::NewL( *iMsgServerSession ); |
|
247 |
|
248 CleanupStack::PushL( obj ); |
|
249 |
|
250 obj->GetMessageDetailL( aMessageId, aResult ); |
|
251 |
|
252 CleanupStack::PopAndDestroy( obj ); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Adds asynchronous request object |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CMessagingService::AddAsyncObjL( const TInt32 aTransactionId, CActive* aAsyncObj ) |
|
260 { |
|
261 TAsyncRequestInfo asyncRequestInfo; |
|
262 asyncRequestInfo.iTransactionId = aTransactionId; |
|
263 asyncRequestInfo.iAsyncObj = aAsyncObj; |
|
264 User::LeaveIfError( iAsyncObjArray.Append( asyncRequestInfo ) ); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // Deletes all the asynchronous request objects |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CMessagingService::DeleteAsyncObjects() |
|
272 { |
|
273 TInt pos = iAsyncObjArray.Count() - 1; |
|
274 TAsyncRequestInfo obj; |
|
275 for ( ; pos >= 0; pos-- ) |
|
276 { |
|
277 obj = iAsyncObjArray[pos]; |
|
278 (obj.iAsyncObj)->Cancel(); |
|
279 delete obj.iAsyncObj; |
|
280 } |
|
281 } |
|
282 |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // Cancels asynchronous request |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C TInt CMessagingService::Cancel( const TInt32 aTransactionId ) |
|
289 { |
|
290 TInt pos = iAsyncObjArray.Count() - 1; |
|
291 TAsyncRequestInfo obj; |
|
292 for ( ; pos >= 0; pos-- ) |
|
293 { |
|
294 obj = iAsyncObjArray[pos]; |
|
295 if( obj.iTransactionId == aTransactionId ) |
|
296 { |
|
297 obj.iAsyncObj->Cancel(); |
|
298 delete obj.iAsyncObj; |
|
299 return KErrNone; |
|
300 } |
|
301 } |
|
302 return KErrNotFound; |
|
303 } |
|
304 |
|
305 |
|
306 // --------------------------------------------------------------------------- |
|
307 // Notifies Messaging service about the completeion of the request |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 void CMessagingService::RequestComplete( const TInt32 aTransactionId ) |
|
311 { |
|
312 TInt pos = iAsyncObjArray.Count() - 1; |
|
313 TAsyncRequestInfo obj; |
|
314 for ( ; pos >= 0; pos-- ) |
|
315 { |
|
316 obj = iAsyncObjArray[pos]; |
|
317 if( obj.iTransactionId == aTransactionId ) |
|
318 { |
|
319 iAsyncObjArray.Remove(pos); |
|
320 iAsyncObjArray.Compress(); |
|
321 return; |
|
322 } |
|
323 } |
|
324 } |
|
325 |