24
|
1 |
// Copyright (c) 1999-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 |
// Implements the CSmspReceiveMode and CSmspReceiveModeNotifier classes
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
*/
|
|
21 |
|
|
22 |
#include <commsdattypesv1_1.h>
|
|
23 |
#include <cdbcols.h>
|
|
24 |
|
|
25 |
#include "smspcdb.h"
|
|
26 |
#include "smspmain.h"
|
|
27 |
#include <commdb.h>
|
|
28 |
#include "smsuset.h"
|
|
29 |
#include "SmsuTimer.h"
|
|
30 |
|
|
31 |
using namespace CommsDat;
|
|
32 |
|
|
33 |
|
|
34 |
/**
|
|
35 |
* CSmspReceiveMode constructor
|
|
36 |
*/
|
|
37 |
CSmspReceiveMode::CSmspReceiveMode(const TSmsSettings& aSmsSettings,
|
|
38 |
RMobileSmsMessaging& aSmsMessaging,
|
|
39 |
const RMobileSmsMessaging::TMobileSmsCapsV1& aSmsCaps,
|
|
40 |
TInt aPriority)
|
|
41 |
: CSmspCommDbEvent(aSmsSettings, aSmsMessaging, aPriority),
|
|
42 |
iSmsReceiveModeLastSet(RMobileSmsMessaging::EReceiveModeUnspecified),
|
|
43 |
iSmsCaps(aSmsCaps)
|
|
44 |
{
|
|
45 |
// NOP
|
|
46 |
} // CSmspReceiveMode::CSmspReceiveMode
|
|
47 |
|
|
48 |
|
|
49 |
/**
|
|
50 |
* CSmspReceiveMode destructor
|
|
51 |
*/
|
|
52 |
CSmspReceiveMode::~CSmspReceiveMode()
|
|
53 |
{
|
|
54 |
Cancel();
|
|
55 |
iCommDbRetryTimer.Close();
|
|
56 |
} // CSmspReceiveMode::~CSmspReceiveMode
|
|
57 |
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Two-phase construction of CSmspReceiveMode
|
|
61 |
*/
|
|
62 |
CSmspReceiveMode* CSmspReceiveMode::NewL(const TSmsSettings& aSmsSettings, RMobileSmsMessaging& aSmsMessaging, const RMobileSmsMessaging::TMobileSmsCapsV1& aSmsCaps, TInt aPriority)
|
|
63 |
{
|
|
64 |
LOGSMSPROT1("CSmspReceiveMode::NewL()");
|
|
65 |
|
|
66 |
CSmspReceiveMode* self = new (ELeave) CSmspReceiveMode(aSmsSettings, aSmsMessaging, aSmsCaps, aPriority);
|
|
67 |
CleanupStack::PushL(self);
|
|
68 |
self->ConstructL();
|
|
69 |
CleanupStack::Pop(self);
|
|
70 |
return self;
|
|
71 |
} // CSmspReceiveMode::NewL
|
|
72 |
|
|
73 |
|
|
74 |
void CSmspReceiveMode::ConstructL()
|
|
75 |
{
|
|
76 |
LOGSMSPROT1("CSmspReceiveMode::ConstructL()");
|
|
77 |
|
|
78 |
CSmspCommDbEvent::ConstructL();
|
|
79 |
User::LeaveIfError(iCommDbRetryTimer.CreateLocal());
|
|
80 |
User::LeaveIfError(iProperty.Attach(KUidSystemCategory, KUidCommDbSMSReceiveModeChange.iUid));
|
|
81 |
} // CSmspReceiveMode::ConstructL
|
|
82 |
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Intially sets the SMS Receive Mode on the TSY or waits for notification of the CommDB global setting SMS_RECEIVE_MODE to change
|
|
86 |
*/
|
|
87 |
void CSmspReceiveMode::Start(TRequestStatus& aStatus)
|
|
88 |
{
|
|
89 |
LOGSMSPROT1("CSmspReceiveMode::Start()");
|
|
90 |
|
|
91 |
Cancel();
|
|
92 |
Queue(aStatus);
|
|
93 |
|
|
94 |
RMobileSmsMessaging::TMobileSmsReceiveMode recvMode(SelectReceiveMode());
|
|
95 |
|
|
96 |
//
|
|
97 |
// Until we manage to read the CommDB the default choice is the best known
|
|
98 |
//
|
|
99 |
if (iSmsReceiveModeLastSet == RMobileSmsMessaging::EReceiveModeUnspecified)
|
|
100 |
{
|
|
101 |
iSmsReceiveModeLastSet = recvMode;
|
|
102 |
}
|
|
103 |
|
|
104 |
TRAPD(err, GetCommDbReceiveModeL(recvMode));
|
|
105 |
if(err == KErrNone)
|
|
106 |
{
|
|
107 |
SetReceiveMode(recvMode);
|
|
108 |
}
|
|
109 |
else
|
|
110 |
{
|
|
111 |
iState = ESmspReceiveModeRetryCommDb;
|
|
112 |
iCommDbRetryCount = KSmspReceiveModeCommDbRetryLimit;
|
|
113 |
iCommDbRetryTimer.After(iStatus, KSmspReceiveModeCommDbRetryDelay);
|
|
114 |
SetActive();
|
|
115 |
}
|
|
116 |
} // CSmspReceiveMode::Start
|
|
117 |
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Wait for notification from property for when the CommDB global setting SMS_RECEIVE_MODE changes
|
|
121 |
*/
|
|
122 |
void CSmspReceiveMode::NotifyOnEvent()
|
|
123 |
{
|
|
124 |
LOGSMSPROT1("CSmspReceiveMode::NotifyOnEvent()");
|
|
125 |
|
|
126 |
iState = ESmspReceiveModeNotifyOnEvent;
|
|
127 |
CSmspCommDbEvent::NotifyOnEvent();
|
|
128 |
} // CSmspReceiveMode::NotifyOnEvent
|
|
129 |
|
|
130 |
|
|
131 |
/**
|
|
132 |
* Sets the SMS Receive Mode on the TSY
|
|
133 |
*
|
|
134 |
* @param aReceiveMode SMS Receive Mode to set on the TSY
|
|
135 |
*/
|
|
136 |
void CSmspReceiveMode::SetReceiveMode(RMobileSmsMessaging::TMobileSmsReceiveMode aReceiveMode)
|
|
137 |
{
|
|
138 |
LOGSMSPROT1("CSmspReceiveMode::SetReceiveMode()");
|
|
139 |
|
|
140 |
aReceiveMode = SelectReceiveMode(aReceiveMode);
|
|
141 |
iSmsReceiveModeLastSet = aReceiveMode;
|
|
142 |
|
|
143 |
iState = ESmspReceiveModeSet;
|
|
144 |
iSmsMessaging.SetReceiveMode(iStatus, aReceiveMode);
|
|
145 |
TimedSetActive(iSmsSettings.Timeout());
|
|
146 |
} // CSmspReceiveMode::SetReceiveMode
|
|
147 |
|
|
148 |
|
|
149 |
void CSmspReceiveMode::DoCancel()
|
|
150 |
{
|
|
151 |
LOGSMSPROT1("CSmspReceiveMode::DoCancel()");
|
|
152 |
|
|
153 |
TimedSetActiveCancel();
|
|
154 |
switch (iState)
|
|
155 |
{
|
|
156 |
case ESmspReceiveModeInit:
|
|
157 |
{
|
|
158 |
// NOP
|
|
159 |
}
|
|
160 |
break;
|
|
161 |
|
|
162 |
case ESmspReceiveModeNotifyOnEvent:
|
|
163 |
{
|
|
164 |
iProperty.Cancel();
|
|
165 |
}
|
|
166 |
break;
|
|
167 |
|
|
168 |
case ESmspReceiveModeSet:
|
|
169 |
{
|
|
170 |
iSmsMessaging.CancelAsyncRequest(EMobileSmsMessagingSetReceiveMode);
|
|
171 |
}
|
|
172 |
break;
|
|
173 |
|
|
174 |
case ESmspReceiveModeRetryCommDb:
|
|
175 |
{
|
|
176 |
iCommDbRetryTimer.Cancel();
|
|
177 |
}
|
|
178 |
break;
|
|
179 |
|
|
180 |
default:
|
|
181 |
{
|
|
182 |
SmspPanic(KSmspPanicUnexpectedState);
|
|
183 |
}
|
|
184 |
break;
|
|
185 |
}
|
|
186 |
|
|
187 |
//
|
|
188 |
// Handle completion of this Active Object. Note that the object
|
|
189 |
// may well still be active at this point...
|
|
190 |
//
|
|
191 |
if (TimedOut())
|
|
192 |
{
|
|
193 |
Complete(KErrTimedOut);
|
|
194 |
}
|
|
195 |
else
|
|
196 |
{
|
|
197 |
Complete(KErrCancel);
|
|
198 |
}
|
|
199 |
} // CSmspReceiveMode::DoCancel
|
|
200 |
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Read Comms Database global setting SMS_RECEIVE_MODE
|
|
204 |
*
|
|
205 |
* @param aReceiveMode Will be set to the CommsDat global setting SMS_RECEIVE_MODE
|
|
206 |
* @return Error code if we cannot create the session, or load from the db
|
|
207 |
*/
|
|
208 |
void CSmspReceiveMode::GetCommDbReceiveModeL(RMobileSmsMessaging::TMobileSmsReceiveMode& aReceiveMode)
|
|
209 |
{
|
|
210 |
LOGSMSPROT1("CSmspReceiveMode::GetCommDbReceiveModeL()");
|
|
211 |
|
|
212 |
#ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
|
|
213 |
CMDBSession* sess = CMDBSession::NewL(KCDVersion1_2);
|
|
214 |
#else
|
|
215 |
CMDBSession* sess = CMDBSession::NewL(KCDVersion1_1);
|
|
216 |
#endif
|
|
217 |
CleanupStack::PushL(sess);
|
|
218 |
|
|
219 |
CMDBField<TUint32>* smsReceiveModeField = new(ELeave) CMDBField<TUint32>(KCDTIdSMSReceiveMode);
|
|
220 |
CleanupStack::PushL(smsReceiveModeField);
|
|
221 |
smsReceiveModeField->SetRecordId(1);
|
|
222 |
|
|
223 |
smsReceiveModeField->LoadL(*sess);
|
|
224 |
aReceiveMode = static_cast<RMobileSmsMessaging::TMobileSmsReceiveMode>(static_cast<TUint32>(*smsReceiveModeField));
|
|
225 |
|
|
226 |
CleanupStack::PopAndDestroy(smsReceiveModeField);
|
|
227 |
CleanupStack::PopAndDestroy(sess);
|
|
228 |
} // CSmspReceiveMode::GetCommDbReceiveModeL
|
|
229 |
|
|
230 |
|
|
231 |
void CSmspReceiveMode::DoRunL()
|
|
232 |
{
|
|
233 |
LOGSMSPROT1("CSmspReceiveMode::DoRunL()");
|
|
234 |
|
|
235 |
switch (iState)
|
|
236 |
{
|
|
237 |
case ESmspReceiveModeSet:
|
|
238 |
{
|
|
239 |
CSmsuActiveBase::Complete(iStatus.Int());
|
|
240 |
|
|
241 |
if (iStatus.Int() == KErrNone)
|
|
242 |
{
|
|
243 |
NotifyOnEvent();
|
|
244 |
}
|
|
245 |
}
|
|
246 |
break;
|
|
247 |
|
|
248 |
case ESmspReceiveModeRetryCommDb:
|
|
249 |
{
|
|
250 |
if (iStatus.Int() == KErrNone)
|
|
251 |
{
|
|
252 |
RMobileSmsMessaging::TMobileSmsReceiveMode recvMode;
|
|
253 |
TRAPD(err, GetCommDbReceiveModeL(recvMode));
|
|
254 |
if(err == KErrNone)
|
|
255 |
{
|
|
256 |
SetReceiveMode(recvMode);
|
|
257 |
}
|
|
258 |
else if(--iCommDbRetryCount > 0)
|
|
259 |
{
|
|
260 |
iCommDbRetryTimer.After(iStatus, KSmspReceiveModeCommDbRetryDelay);
|
|
261 |
SetActive();
|
|
262 |
}
|
|
263 |
else
|
|
264 |
{
|
|
265 |
// Failed to read CommDB even after retries. Set the receive mode to the last known setting
|
|
266 |
LOGSMSPROT2("CSmspReceiveMode::DoRunL in ESmspReceiveModeRetryCommDb state, failed to read CommDb, using mode #%d", iSmsReceiveModeLastSet );
|
|
267 |
SetReceiveMode(iSmsReceiveModeLastSet);
|
|
268 |
}
|
|
269 |
}
|
|
270 |
}
|
|
271 |
break;
|
|
272 |
|
|
273 |
case ESmspReceiveModeNotifyOnEvent:
|
|
274 |
{
|
|
275 |
if (iStatus.Int() == KErrNone)
|
|
276 |
{
|
|
277 |
TInt tempRecvMode;
|
|
278 |
User::LeaveIfError(iProperty.Get(tempRecvMode));
|
|
279 |
const RMobileSmsMessaging::TMobileSmsReceiveMode recvMode = static_cast<RMobileSmsMessaging::TMobileSmsReceiveMode>(tempRecvMode);
|
|
280 |
|
|
281 |
SetReceiveMode(recvMode);
|
|
282 |
}
|
|
283 |
else
|
|
284 |
{
|
|
285 |
NotifyOnEvent();
|
|
286 |
}
|
|
287 |
}
|
|
288 |
break;
|
|
289 |
|
|
290 |
default:
|
|
291 |
{
|
|
292 |
SmspPanic(KSmspPanicUnexpectedState);
|
|
293 |
}
|
|
294 |
break;
|
|
295 |
}
|
|
296 |
|
|
297 |
//
|
|
298 |
// DoRunL() will now return to CSmsuActiveBase which if the object
|
|
299 |
// is not active, will call Complete().
|
|
300 |
//
|
|
301 |
} // CSmspReceiveMode::DoRunL
|
|
302 |
|
|
303 |
|
|
304 |
/**
|
|
305 |
* Finds an SMS Receive Mode supported by the TSY, giving preference to EReceiveUnstoredClientAck and so forth.
|
|
306 |
*
|
|
307 |
* @return An SMS Receive Mode supported by the TSY.
|
|
308 |
*/
|
|
309 |
RMobileSmsMessaging::TMobileSmsReceiveMode CSmspReceiveMode::SelectReceiveMode() const
|
|
310 |
{
|
|
311 |
LOGSMSPROT1("CSmspReceiveMode::SelectReceiveMode()");
|
|
312 |
|
|
313 |
const TUint32 smsControl = iSmsCaps.iSmsControl;
|
|
314 |
RMobileSmsMessaging::TMobileSmsReceiveMode recvMode = RMobileSmsMessaging::EReceiveModeUnspecified;
|
|
315 |
|
|
316 |
if (smsControl & RMobileSmsMessaging::KCapsReceiveUnstoredClientAck)
|
|
317 |
{
|
|
318 |
recvMode = RMobileSmsMessaging::EReceiveUnstoredClientAck;
|
|
319 |
}
|
|
320 |
else if (smsControl & RMobileSmsMessaging::KCapsReceiveUnstoredPhoneAck)
|
|
321 |
{
|
|
322 |
recvMode = RMobileSmsMessaging::EReceiveUnstoredPhoneAck;
|
|
323 |
}
|
|
324 |
else if (smsControl & RMobileSmsMessaging::KCapsReceiveStored)
|
|
325 |
{
|
|
326 |
recvMode = RMobileSmsMessaging::EReceiveStored;
|
|
327 |
}
|
|
328 |
else if (smsControl & RMobileSmsMessaging::KCapsReceiveEither)
|
|
329 |
{
|
|
330 |
recvMode = RMobileSmsMessaging::EReceiveEither;
|
|
331 |
}
|
|
332 |
|
|
333 |
return recvMode;
|
|
334 |
} // CSmspReceiveMode::SelectReceiveMode
|
|
335 |
|
|
336 |
|
|
337 |
/**
|
|
338 |
* Finds an SMS Receive Mode supported by the TSY, giving preference to aPreferredMode.
|
|
339 |
*
|
|
340 |
* @param aPreferredMode SMS Receive Mode that a client would like to use.
|
|
341 |
* @return aPreferredMode if it is supported by the TSY, otherwise return a receive mode that is supported by the TSY.
|
|
342 |
*/
|
|
343 |
RMobileSmsMessaging::TMobileSmsReceiveMode CSmspReceiveMode::SelectReceiveMode(RMobileSmsMessaging::TMobileSmsReceiveMode aPreferredMode) const
|
|
344 |
{
|
|
345 |
LOGSMSPROT1("CSmspReceiveMode::SelectReceiveMode()");
|
|
346 |
|
|
347 |
const TUint32 smsControl = iSmsCaps.iSmsControl;
|
|
348 |
TBool usePreferred = EFalse;
|
|
349 |
|
|
350 |
switch (aPreferredMode)
|
|
351 |
{
|
|
352 |
case RMobileSmsMessaging::EReceiveUnstoredClientAck:
|
|
353 |
|
|
354 |
usePreferred = smsControl & RMobileSmsMessaging::KCapsReceiveUnstoredClientAck;
|
|
355 |
break;
|
|
356 |
|
|
357 |
case RMobileSmsMessaging::EReceiveUnstoredPhoneAck:
|
|
358 |
|
|
359 |
usePreferred = smsControl & RMobileSmsMessaging::KCapsReceiveUnstoredPhoneAck;
|
|
360 |
break;
|
|
361 |
|
|
362 |
case RMobileSmsMessaging::EReceiveStored:
|
|
363 |
|
|
364 |
usePreferred = smsControl & RMobileSmsMessaging::KCapsReceiveStored;
|
|
365 |
break;
|
|
366 |
|
|
367 |
case RMobileSmsMessaging::EReceiveEither:
|
|
368 |
|
|
369 |
usePreferred = smsControl & RMobileSmsMessaging::KCapsReceiveEither;
|
|
370 |
break;
|
|
371 |
|
|
372 |
default:
|
|
373 |
|
|
374 |
//usePreferred = EFalse;
|
|
375 |
break;
|
|
376 |
}
|
|
377 |
|
|
378 |
return usePreferred ? aPreferredMode : SelectReceiveMode();
|
|
379 |
} // CSmspReceiveMode::SelectReceiveMode
|