|
1 // Copyright (c) 2005-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 // Name : CSatNotifyTimerMgmt.cpp |
|
15 // Part of : Common SIM ATK TSY / commonsimatktsy |
|
16 // Timer management notification functionality of Sat Tsy |
|
17 // Version : 1.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 //INCLUDES |
|
23 #include <satcs.h> // Etel SAT IPC definitions |
|
24 #include "CSatTsy.h" // Tsy class header |
|
25 #include "CSatNotifyTimerMgmt.h" // Class header |
|
26 #include "CSatNotificationsTsy.h" // Tsy class header |
|
27 #include "CBerTlv.h" // Ber Tlv data handling |
|
28 #include "TTlv.h" // TTlv class |
|
29 #include "CSatDataPackage.h" // Parameter packing |
|
30 #include "TfLogger.h" // For TFLOGSTRING |
|
31 #include "TSatUtility.h" // Utilities |
|
32 #include "cmmmessagemanagerbase.h" // Message manager class for forwarding req. |
|
33 #include "MSatTsy_IPCDefs.h" // Sat Tsy internal request types |
|
34 |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CSatNotifyTimerMgmt::NewL |
|
38 // Two-phased constructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CSatNotifyTimerMgmt* CSatNotifyTimerMgmt::NewL |
|
42 ( |
|
43 CSatNotificationsTsy* aNotificationsTsy |
|
44 ) |
|
45 { |
|
46 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::NewL"); |
|
47 CSatNotifyTimerMgmt* const satNotifyTimerMgmt = |
|
48 new ( ELeave ) CSatNotifyTimerMgmt( aNotificationsTsy ); |
|
49 CleanupStack::PushL( satNotifyTimerMgmt ); |
|
50 satNotifyTimerMgmt->ConstructL(); |
|
51 CleanupStack::Pop( satNotifyTimerMgmt ); |
|
52 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::NewL, end of method"); |
|
53 return satNotifyTimerMgmt; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CSatNotifyTimerMgmt::~CSatNotifyTimerMgmt |
|
58 // Destructor |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CSatNotifyTimerMgmt::~CSatNotifyTimerMgmt |
|
62 ( |
|
63 // None |
|
64 ) |
|
65 { |
|
66 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::~CSatNotifyTimerMgmt"); |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CSatNotifyTimerMgmt::CSatNotifyTimerMgmt |
|
71 // Default C++ constructor |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CSatNotifyTimerMgmt::CSatNotifyTimerMgmt |
|
75 ( |
|
76 CSatNotificationsTsy* aNotificationsTsy |
|
77 ) : iNotificationsTsy ( aNotificationsTsy ) |
|
78 { |
|
79 // None |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CSatNotifyTimerMgmt::ConstructL |
|
84 // Symbian 2nd phase constructor |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CSatNotifyTimerMgmt::ConstructL |
|
88 ( |
|
89 // None |
|
90 ) |
|
91 { |
|
92 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::ConstructL, does nothing"); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CSatNotifyTimerMgmt::CompleteNotifyL |
|
97 // This method completes a NotifyTimerMgmt request by sending terminal response. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TInt CSatNotifyTimerMgmt::CompleteNotifyL |
|
101 ( |
|
102 CSatDataPackage* aDataPackage, |
|
103 TInt aErrorCode |
|
104 ) |
|
105 { |
|
106 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::CompleteNotifyL"); |
|
107 |
|
108 TInt ret( KErrNone ); |
|
109 TInt returnValue( KErrNone ); |
|
110 TUint8 generalResult ( RSat::KSuccess ); |
|
111 |
|
112 // Unpack parameters |
|
113 TPtrC8* data; |
|
114 aDataPackage->UnPackData( &data ); |
|
115 // Get ber tlv |
|
116 CBerTlv berTlv; |
|
117 berTlv.SetData( *data ); |
|
118 |
|
119 // Get command details tlv |
|
120 CTlv commandDetails; |
|
121 berTlv.TlvByTagValue( &commandDetails, KTlvCommandDetailsTag ); |
|
122 // Store command details tlv |
|
123 iNotificationsTsy->iTerminalRespData.iCommandDetails.Copy( |
|
124 commandDetails.Data() ); |
|
125 |
|
126 // Get command qualifier |
|
127 TUint8 cmdQualifier( commandDetails.GetShortInfo( |
|
128 ETLV_CommandQualifier ) ); |
|
129 |
|
130 TUint8 pCmdNumber( commandDetails.GetShortInfo( ETLV_CommandNumber ) ); |
|
131 |
|
132 // Don't do anything if error has occured, otherwise continue.. |
|
133 if ( KErrNone == aErrorCode ) |
|
134 { |
|
135 // Get timer id tlv |
|
136 CTlv timerId; |
|
137 returnValue = berTlv.TlvByTagValue( &timerId, KTlvTimerIdentifierTag ); |
|
138 |
|
139 // Initalize |
|
140 iTimerId = 0; |
|
141 for( TInt i = 0; i < 3; i++ ) |
|
142 { |
|
143 iTimerValue[i] = 0; |
|
144 } |
|
145 |
|
146 if ( KErrNone == returnValue ) |
|
147 { |
|
148 iTimerId = timerId.GetShortInfo( ETLV_TimerIdentifier ); |
|
149 // The Timer Identifier can take 8 different values |
|
150 if ( ( RSat::KTimer8 < iTimerId ) |
|
151 || ( RSat::KTimer1 > iTimerId ) ) |
|
152 { |
|
153 generalResult = RSat::KCmdDataNotUnderstood; |
|
154 } |
|
155 else |
|
156 { |
|
157 // if operation type is startTimer = 0x00; |
|
158 if ( !cmdQualifier ) |
|
159 { |
|
160 // Get timer value tlv |
|
161 CTlv timerValue; |
|
162 returnValue = berTlv.TlvByTagValue( &timerValue, |
|
163 KTlvTimerValueTag ); |
|
164 |
|
165 if ( KErrNotFound != returnValue ) |
|
166 { |
|
167 TPtrC8 temp; |
|
168 TUint32 timeValue( 0 ); |
|
169 |
|
170 // Value of a timer, expressed using |
|
171 // the format hour, minute, second |
|
172 // Semi-octec presentation used (23.040) |
|
173 temp.Set( timerValue.GetData( ETLV_TimerValue ) ); |
|
174 |
|
175 // Convert to seconds |
|
176 timeValue = ConvertToSeconds( temp ); |
|
177 |
|
178 // The possible duration of a timer is |
|
179 // between 1 second and 24 hours |
|
180 if ( KMinTimerValue < timeValue && |
|
181 KMaxTimerValueInSeconds >= timeValue ) |
|
182 { |
|
183 ret = iNotificationsTsy->GetSatTimer()->Start( |
|
184 iTimerId, timeValue ); |
|
185 |
|
186 if ( KErrNone != ret ) |
|
187 { |
|
188 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::\ |
|
189 CompleteNotifyL, Unable to process cmd"); |
|
190 generalResult = RSat::KMeUnableToProcessCmd; |
|
191 } |
|
192 } |
|
193 else |
|
194 { |
|
195 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::\ |
|
196 CompleteNotifyL, Data not understood"); |
|
197 generalResult = RSat::KCmdDataNotUnderstood; |
|
198 } |
|
199 } |
|
200 else |
|
201 { |
|
202 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::\ |
|
203 CompleteNotifyL, Timer value missing"); |
|
204 generalResult = RSat::KErrorRequiredValuesMissing; |
|
205 } |
|
206 } |
|
207 // If operation type is KDeactivateTimer or KGetTimerValue |
|
208 else if ( ( KDeactivateTimer == cmdQualifier ) || |
|
209 ( KGetTimerValue == cmdQualifier ) ) |
|
210 { |
|
211 TInt retValue( KErrNone ); |
|
212 |
|
213 // Get current value of the timer |
|
214 ret = iNotificationsTsy->GetSatTimer()-> |
|
215 CurrentValueOfTimerById( iTimerId ); |
|
216 |
|
217 if ( ( KErrNotFound != ret ) && ( KDeactivateTimer == |
|
218 cmdQualifier ) ) |
|
219 { |
|
220 // Deactivate timer |
|
221 retValue = iNotificationsTsy->GetSatTimer()-> |
|
222 DeleteTimerById( iTimerId ); |
|
223 } |
|
224 |
|
225 // If timer is found convert timer value to semi-octets |
|
226 if ( ( KErrNotFound != ret ) && ( KErrNotFound != |
|
227 retValue ) ) |
|
228 { |
|
229 generalResult = RSat::KSuccess; |
|
230 |
|
231 TInt num[3]; |
|
232 num[0] = ret/3600; //hours |
|
233 num[1] = ( ret%3600 )/60; //minutes |
|
234 num[2] = ( ret%3600 )%60; //seconds |
|
235 |
|
236 TInt i( 0 ); |
|
237 for ( i = 0; i < 3; i++ ) |
|
238 { |
|
239 //convert to semi-octet |
|
240 iTimerValue[i] = |
|
241 TSatUtility::ConvertToSemiOctet( num[i] ); |
|
242 } |
|
243 } |
|
244 else |
|
245 { |
|
246 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::\ |
|
247 CompleteNotifyL, Contradiction with timer state"); |
|
248 generalResult = RSat::KContradictionWithTimerState; |
|
249 } |
|
250 } |
|
251 else |
|
252 { |
|
253 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::\ |
|
254 CompleteNotifyL, Cmd type not understood"); |
|
255 generalResult = RSat::KCmdTypeNotUnderstood; |
|
256 } |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::\ |
|
262 CompleteNotifyL, Required values missing"); |
|
263 generalResult = RSat::KErrorRequiredValuesMissing; |
|
264 } |
|
265 |
|
266 CreateTerminalRespL( pCmdNumber, generalResult ); |
|
267 |
|
268 } // End of if (KErrNone) |
|
269 |
|
270 return ret; |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CSatNotifyTimerMgmt::CreateTerminalRespL |
|
275 // Constructs LocalInfo specific part of terminal response and calls |
|
276 // DOS to send the actual message. |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 TInt CSatNotifyTimerMgmt::CreateTerminalRespL |
|
280 ( |
|
281 TUint8 aPCmdNumber, |
|
282 TUint8 aGeneralResult |
|
283 ) |
|
284 { |
|
285 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::CreateTerminalRespL"); |
|
286 |
|
287 // Create and append response data |
|
288 TTlv tlvSpecificData; |
|
289 // Create General Result TLV here |
|
290 tlvSpecificData.AddTag( KTlvResultTag ); |
|
291 |
|
292 // General result |
|
293 tlvSpecificData.AddByte( aGeneralResult ); |
|
294 |
|
295 // Include timer value and id only when command is performed successfully |
|
296 if( RSat::KSuccess == aGeneralResult ) |
|
297 { |
|
298 // Timer Id |
|
299 // Value KTlvTimerIdentifierTagCRBitOn ( 0xA4 ) is added, |
|
300 // because used KTlvTimerIdentifierTag ( 0x24 ) doesn't |
|
301 // include comprehension bit in tag the value and it is expected |
|
302 // to be present in indications and terminal responses. |
|
303 tlvSpecificData.AddTag( KTlvTimerIdentifierTagCRBitOn ); |
|
304 |
|
305 tlvSpecificData.AddByte( iTimerId ); |
|
306 |
|
307 // Timer value is included when the Command Qualifier is indicating |
|
308 // "deactivate" or "get the current value of the timer" |
|
309 if ( iNotificationsTsy->iTerminalRespData.iCommandDetails[4] ) |
|
310 { |
|
311 tlvSpecificData.AddTag( KTlvTimerValueTag ); |
|
312 // Timer value in semi-octets |
|
313 tlvSpecificData.AddByte( iTimerValue[0] ); // Hours |
|
314 tlvSpecificData.AddByte( iTimerValue[1] ); // Minutes |
|
315 tlvSpecificData.AddByte( iTimerValue[2] ); // Seconds |
|
316 } |
|
317 } |
|
318 else if( ( RSat::KContradictionWithTimerState != aGeneralResult ) && |
|
319 ( RSat::KErrorRequiredValuesMissing != aGeneralResult ) && |
|
320 ( RSat::KCmdDataNotUnderstood != aGeneralResult ) && |
|
321 ( RSat::KCmdTypeNotUnderstood != aGeneralResult ) ) |
|
322 { |
|
323 tlvSpecificData.AddByte( KNoCause ); |
|
324 } |
|
325 else |
|
326 { |
|
327 // None. |
|
328 } |
|
329 |
|
330 // Prepare data |
|
331 iNotificationsTsy->iTerminalRespData.iPCmdNumber = aPCmdNumber; |
|
332 TPtrC8 data = tlvSpecificData.GetDataWithoutTopLevelTag(); |
|
333 |
|
334 // Pack data |
|
335 CSatDataPackage dataPackage; |
|
336 dataPackage.PackData( &iNotificationsTsy->iTerminalRespData, &data ); |
|
337 |
|
338 // Forward request to the DOS |
|
339 return iNotificationsTsy->iSatTsy->MessageManager()->HandleRequestL( |
|
340 ESatTerminalRsp, &dataPackage ); |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CSatNotifyTimerMgmt::ConvertToSeconds |
|
345 // Converts to seconds semi-octet presented value of timer, expressed using |
|
346 // the format hour, minute, second |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 TUint32 CSatNotifyTimerMgmt::ConvertToSeconds |
|
350 ( |
|
351 TPtrC8 time |
|
352 ) |
|
353 { |
|
354 TFLOGSTRING("CSAT: CSatNotifyTimerMgmt::ConvertToSeconds"); |
|
355 TUint32 timeValue( 0 ); |
|
356 // Value of a timer, expressed using |
|
357 // the format hour, minute, second |
|
358 // Semi-octec presentation used (23.040) |
|
359 // time[0] is hours |
|
360 // time[1] is minutes |
|
361 // time[2] is seconds |
|
362 TInt i( 0 ); |
|
363 for ( i = 0; i < 3; i++ ) |
|
364 { |
|
365 TUint value = ( time[i] & 0x0F )*10 + ( ( time[i] & 0xF0 ) >> 4 ); |
|
366 timeValue = timeValue * 60 + value; |
|
367 } |
|
368 return timeValue; |
|
369 } |
|
370 |
|
371 // End of file |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |