|
1 // Copyright (c) 2007-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 // |
|
15 |
|
16 #include "cpopsessionmanager.h" |
|
17 #include <pop3set.h> |
|
18 #include <iapprefs.h> |
|
19 #include "imutcon.h" |
|
20 #include <pops.h> |
|
21 #include "POPS.PAN" |
|
22 |
|
23 GLREF_C void Panic(TPopsPanic aPanic); |
|
24 |
|
25 /** |
|
26 Factory constructor |
|
27 |
|
28 @return Constructed session manager |
|
29 */ |
|
30 CPopSessionManager* CPopSessionManager::NewL() |
|
31 { |
|
32 CPopSessionManager* self = new (ELeave) CPopSessionManager(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 /** |
|
40 Constructor |
|
41 */ |
|
42 CPopSessionManager::CPopSessionManager() : |
|
43 CMsgActive(KImPopSessionPriority) |
|
44 { |
|
45 } |
|
46 |
|
47 /** |
|
48 Second phase constructor |
|
49 */ |
|
50 void CPopSessionManager::ConstructL() |
|
51 { |
|
52 User::LeaveIfError(iServ.Connect()); |
|
53 CActiveScheduler::Add(this); |
|
54 } |
|
55 |
|
56 /** |
|
57 Destructor |
|
58 */ |
|
59 CPopSessionManager::~CPopSessionManager() |
|
60 { |
|
61 Cancel(); |
|
62 delete iConnect; |
|
63 iServ.Close(); |
|
64 } |
|
65 |
|
66 /** |
|
67 Gets a new logged in POP session. |
|
68 The caller passes a reference to a session pointer which they should initially |
|
69 set to NULL. If the client status is completed with KErrNone, then their pointer |
|
70 will have been updated to point to the new session. If the client status completes |
|
71 with an error then their pointer will not be updated. |
|
72 |
|
73 @param aSettings POP settings |
|
74 @param aIAPPrefs IAP preferences |
|
75 @param aSession Used to store session to pass back to caller |
|
76 @param aClientStatus Signals completion of the request |
|
77 */ |
|
78 void CPopSessionManager::GetSessionL(CImPop3Settings& aSettings, |
|
79 CImIAPPreferences& aIAPPrefs, |
|
80 CImPop3Session*& aSession, |
|
81 TRequestStatus& aClientStatus) |
|
82 { |
|
83 iSettings = &aSettings; |
|
84 iIAPPrefs = &aIAPPrefs; |
|
85 iStoreSession = &aSession; |
|
86 |
|
87 CreateConnectionL(); |
|
88 |
|
89 Queue(aClientStatus); |
|
90 } |
|
91 |
|
92 /** |
|
93 Deletes a session. |
|
94 |
|
95 @param aSession The session to delete. This routine takes immediate ownsership |
|
96 of the session. |
|
97 @param aClientStatus Signals completion of the request |
|
98 */ |
|
99 void CPopSessionManager::DeleteSession(CImPop3Session& aSession, |
|
100 TRequestStatus& aClientStatus) |
|
101 { |
|
102 iSession = &aSession; |
|
103 QuitSession(); |
|
104 Queue(aClientStatus); |
|
105 } |
|
106 |
|
107 /** |
|
108 Gets the progress of a connection |
|
109 |
|
110 @param aProgress Stores the progress information |
|
111 */ |
|
112 void CPopSessionManager::ConnectionProgress(TPop3Progress& aProgress) |
|
113 { |
|
114 TUint32 iap = 0; |
|
115 TInt iapErr = KErrNotFound; |
|
116 |
|
117 if (iSession) |
|
118 { |
|
119 aProgress.iTotalMsgs = iSession->TextServerSession()->GetConnectionStage(); |
|
120 |
|
121 iapErr = iSession->TextServerSession()->GetIAPValue(iap); |
|
122 } |
|
123 else if (iConnect) |
|
124 { |
|
125 TNifProgress progress; |
|
126 TInt err = iConnect->Progress(progress); |
|
127 if (err == KErrNone) |
|
128 { |
|
129 aProgress.iTotalMsgs = progress.iStage; |
|
130 } |
|
131 else |
|
132 { |
|
133 aProgress.iTotalMsgs = err; |
|
134 } |
|
135 |
|
136 iapErr = iConnect->GetIAPValue(iap); |
|
137 } |
|
138 else |
|
139 { |
|
140 aProgress.iTotalMsgs = KErrNotFound; |
|
141 } |
|
142 |
|
143 if (iapErr == KErrNone) |
|
144 { |
|
145 aProgress.iTotalBytes = iap; |
|
146 } |
|
147 else |
|
148 { |
|
149 aProgress.iTotalBytes = iapErr; |
|
150 } |
|
151 } |
|
152 |
|
153 /** |
|
154 Called when asynchronous event completes. |
|
155 */ |
|
156 void CPopSessionManager::DoRunL() |
|
157 { |
|
158 switch (iState) |
|
159 { |
|
160 case EStateCreatingConnection: |
|
161 { |
|
162 CreateSessionL(); |
|
163 break; |
|
164 } |
|
165 |
|
166 case EStateCreatingSession: |
|
167 { |
|
168 StoreSession(); |
|
169 break; |
|
170 } |
|
171 |
|
172 case EStateQuittingSession: |
|
173 { |
|
174 // We have quit successfully, so we can delete the session now. |
|
175 delete iSession; |
|
176 iSession = NULL; |
|
177 break; |
|
178 } |
|
179 |
|
180 case EStateStoringSession: |
|
181 default: |
|
182 { |
|
183 Panic(EPopSessionManagerInvalidState); |
|
184 break; |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 /** |
|
190 Cancel an outstanding asynchronous request. |
|
191 */ |
|
192 void CPopSessionManager::DoCancel() |
|
193 { |
|
194 if (iState == EStateCreatingConnection) |
|
195 { |
|
196 iConnect->Cancel(); |
|
197 } |
|
198 else if (iSession) |
|
199 { |
|
200 iSession->Cancel(); |
|
201 } |
|
202 |
|
203 // Tell base class to finish up. |
|
204 CMsgActive::DoCancel(); |
|
205 } |
|
206 |
|
207 /** |
|
208 The clients outstanding asynchronous request has been completed. |
|
209 |
|
210 @param aStatus Status of completed operation. |
|
211 */ |
|
212 void CPopSessionManager::DoComplete(TInt& aStatus) |
|
213 { |
|
214 if (aStatus != KErrNone) |
|
215 { |
|
216 // If an error occured or the client cancelled the request then |
|
217 // perform all the cleanup. |
|
218 delete iSession; |
|
219 iSession = NULL; |
|
220 |
|
221 if (iState == EStateCreatingConnection) |
|
222 { |
|
223 delete iConnect; |
|
224 iConnect = NULL; |
|
225 } |
|
226 } |
|
227 else |
|
228 { |
|
229 iSession = NULL; |
|
230 } |
|
231 } |
|
232 |
|
233 /** |
|
234 Creates the network connection if it has not already been created. |
|
235 */ |
|
236 void CPopSessionManager::CreateConnectionL() |
|
237 { |
|
238 iState = EStateCreatingConnection; |
|
239 |
|
240 if (iConnect) |
|
241 { |
|
242 TRequestStatus* status = &iStatus; |
|
243 User::RequestComplete(status, KErrNone); |
|
244 } |
|
245 else |
|
246 { |
|
247 iConnect = CImConnect::NewL(*iIAPPrefs, iServ); |
|
248 iConnect->StartL(iStatus); |
|
249 } |
|
250 SetActive(); |
|
251 } |
|
252 |
|
253 /** |
|
254 Returns ETrue if the session manager has access to an RConnection |
|
255 |
|
256 @return TBool |
|
257 */ |
|
258 TBool CPopSessionManager::HasConnection() |
|
259 { |
|
260 if (iConnect) |
|
261 { |
|
262 return ETrue; |
|
263 } |
|
264 return EFalse; |
|
265 } |
|
266 |
|
267 /** |
|
268 Requests an already connected RConnection from the Mobility Manager |
|
269 and returns the RConnection, this method is called by the POP Server MTM. |
|
270 */ |
|
271 RConnection& CPopSessionManager::GetConnection() |
|
272 { |
|
273 // Get the Connection from CImConnect and pass on to the Server MTM |
|
274 return iConnect->GetConnection(); |
|
275 } |
|
276 |
|
277 /** |
|
278 Starts the creation of a session. |
|
279 */ |
|
280 void CPopSessionManager::CreateSessionL() |
|
281 { |
|
282 iState = EStateCreatingSession; |
|
283 |
|
284 iSession = CImPop3Session::NewL(iServ, *iConnect); |
|
285 iSession->ConnectL(iSettings, *iIAPPrefs, iStatus); |
|
286 SetActive(); |
|
287 } |
|
288 |
|
289 /** |
|
290 Stores the created session via the reference passed by the client |
|
291 */ |
|
292 void CPopSessionManager::StoreSession() |
|
293 { |
|
294 iState = EStateStoringSession; |
|
295 *iStoreSession = iSession; |
|
296 } |
|
297 |
|
298 /** |
|
299 Quit from the server |
|
300 */ |
|
301 void CPopSessionManager::QuitSession() |
|
302 { |
|
303 iState = EStateQuittingSession; |
|
304 iSession->Quit(iStatus); |
|
305 SetActive(); |
|
306 } |
|
307 |
|
308 /** |
|
309 Gets the access point ID in use for the connection to the server |
|
310 |
|
311 @param aAccessPointId On return stores the access point ID value |
|
312 |
|
313 @return KErrNone if successful, or a system wide error code |
|
314 */ |
|
315 TInt CPopSessionManager::GetAccessPointIdForConnection(TUint32& aAccessPointId) const |
|
316 { |
|
317 if (iConnect) |
|
318 { |
|
319 return iConnect->GetIAPValue(aAccessPointId); |
|
320 } |
|
321 |
|
322 return KErrNotFound; |
|
323 } |