|
1 /* |
|
2 * Copyright (c) 2008 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 "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: The source file for the CClockNitzPluginImpl class. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32const.h> |
|
20 #include <e32base.h> |
|
21 |
|
22 // User includes |
|
23 #include "clocknitzplugin.h" |
|
24 #include "clocknitzpluginimpl.h" |
|
25 #include "clockpluginobserver.h" |
|
26 #include "clock_debug.h" |
|
27 |
|
28 // Constants |
|
29 const TInt KQuaterHour( 15 ); |
|
30 const TInt KMinute( 60 ); |
|
31 const TInt KTimeZoneValidBit( 0x3F ); |
|
32 const TInt KTimeZoneSignBit( 0x80 ); |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CClockNitzPluginImpl::NewL |
|
36 // rest of the details are commented in the header |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 CClockNitzPluginImpl* CClockNitzPluginImpl::NewL( CClockNitzPlugin* aNitzPlugin ) |
|
40 { |
|
41 __PRINTS( "CClockNitzPluginImpl::NewL - Entry" ); |
|
42 |
|
43 CClockNitzPluginImpl* self = new ( ELeave ) CClockNitzPluginImpl( aNitzPlugin ); |
|
44 CleanupStack::PushL( self ); |
|
45 |
|
46 self->ConstructL(); |
|
47 |
|
48 CleanupStack::Pop(); |
|
49 |
|
50 __PRINTS( "CClockNitzPluginImpl::NewL - Exit" ); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CClockNitzPluginImpl::~CClockNitzPluginImpl |
|
57 // rest of the details are commented in the header |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 CClockNitzPluginImpl::~CClockNitzPluginImpl() |
|
61 { |
|
62 __PRINTS( "CClockNitzPluginImpl::~CClockNitzPluginImpl - Entry" ); |
|
63 |
|
64 if( iNitzSrv ) |
|
65 { |
|
66 iNitzSrv->Stop(); |
|
67 delete iNitzSrv; |
|
68 } |
|
69 |
|
70 __PRINTS( "CClockNitzPluginImpl::~CClockNitzPluginImpl - Exit" ); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------- |
|
74 // CClockNitzPluginImpl::CClockNitzPluginImpl |
|
75 // rest of the details are commented in the header |
|
76 // --------------------------------------------------------- |
|
77 // |
|
78 CClockNitzPluginImpl::CClockNitzPluginImpl( CClockNitzPlugin* aNitzPlugin ) |
|
79 : iNitzPlugin( aNitzPlugin ) |
|
80 { |
|
81 __PRINTS( "CClockNitzPluginImpl::CClockNitzPluginImpl - Entry" ); |
|
82 |
|
83 // No implementation yet. |
|
84 |
|
85 __PRINTS( "CClockNitzPluginImpl::CClockNitzPluginImpl - Exit" ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------- |
|
89 // CClockNitzPluginImpl::ConstructL |
|
90 // rest of the details are commented in the header |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 void CClockNitzPluginImpl::ConstructL() |
|
94 { |
|
95 __PRINTS( "CClockNitzPluginImpl::ConstructL - Entry" ); |
|
96 |
|
97 // Construct the listener. |
|
98 iNitzSrv = CClockNitzListener::NewL( this ); |
|
99 // Start the listener. |
|
100 iNitzSrv->Start(); |
|
101 |
|
102 __PRINTS( "CClockNitzPluginImpl::ConstructL - Exit" ); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // CClockNitzPluginImpl::GetTimeInformationL |
|
107 // rest of the details are commented in the header |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 void CClockNitzPluginImpl::GetTimeInformationL( TInterfaceAttribute aInterfaceAttribute, |
|
111 STimeAttributes* aTimeAttributes ) |
|
112 { |
|
113 __PRINTS( "CClockNitzPluginImpl::GetTimeInformationL - Entry" ); |
|
114 |
|
115 __PRINT( "TInterfaceAttribute: %d", aInterfaceAttribute ); |
|
116 |
|
117 if( !aTimeAttributes ) |
|
118 { |
|
119 __PRINTS( "Time attributes holder is NULL" ); |
|
120 |
|
121 return; |
|
122 } |
|
123 |
|
124 TInt timeZone( NULL ); |
|
125 |
|
126 STimeAttributes* nitzData( aTimeAttributes ); |
|
127 |
|
128 TInt retVal( KErrNone ); |
|
129 if( iNitzSrv ) |
|
130 { |
|
131 // Get the NITZ information from the listener. |
|
132 retVal = iNitzSrv->GetCurrentNITZInfoL( iNitzInfo ); |
|
133 } |
|
134 |
|
135 if( KErrNotFound == retVal ) |
|
136 { |
|
137 __PRINTS( "Unable to get NITZ information" ); |
|
138 |
|
139 return; |
|
140 } |
|
141 |
|
142 // Get the capabilities sent by the n/w. |
|
143 TInt32 nitzCaps( iNitzInfo.iNitzFieldsUsed ); |
|
144 |
|
145 switch( aInterfaceAttribute ) |
|
146 { |
|
147 case EUTCTime: |
|
148 { |
|
149 // Fetch UTC time. |
|
150 if( nitzCaps & RMobilePhone::KCapsTimeAvailable ) |
|
151 { |
|
152 // We have a valid time. |
|
153 nitzData->iUtcDateTime.Set( iNitzInfo.Year(), |
|
154 TMonth( iNitzInfo.Month() ), |
|
155 iNitzInfo.Day(), |
|
156 iNitzInfo.Hour(), |
|
157 iNitzInfo.Minute(), |
|
158 iNitzInfo.Second(), |
|
159 iNitzInfo.MicroSecond() ); |
|
160 } |
|
161 else |
|
162 { |
|
163 TTime invalidTime( -1 ); |
|
164 nitzData->iUtcDateTime = invalidTime.DateTime(); |
|
165 } |
|
166 } |
|
167 break; |
|
168 |
|
169 case EDSTOffset: |
|
170 { |
|
171 // Check if DST is available in the NITZ packet. |
|
172 if( nitzCaps & RMobilePhone::KCapsDSTAvailable ) |
|
173 { |
|
174 // DST is supported by the n/w. |
|
175 nitzData->iDstOffset = iNitzInfo.iDST * KMinute; |
|
176 } |
|
177 else |
|
178 { |
|
179 // Reset the DST data. |
|
180 nitzData->iDstOffset = TTimeIntervalMinutes( -1 ); |
|
181 } |
|
182 } |
|
183 break; |
|
184 |
|
185 case ETZOffset: |
|
186 { |
|
187 // Calculate std offset |
|
188 // We only accept a NitzInfo with time and zone info. We are very picky |
|
189 if( nitzCaps & RMobilePhone::KCapsTimezoneAvailable ) |
|
190 { |
|
191 timeZone = iNitzInfo.iTimeZone & KTimeZoneValidBit; |
|
192 |
|
193 if( iNitzInfo.iTimeZone & KTimeZoneSignBit ) |
|
194 { |
|
195 // Changes sign |
|
196 timeZone = -timeZone; |
|
197 } |
|
198 |
|
199 // Calculate standard UTC offset |
|
200 nitzData->iTimeZoneOffset = timeZone * KQuaterHour; |
|
201 |
|
202 // Check if dst is available. If so, the standard offset above will already have |
|
203 // DST offset included. We've to remove it. The following check tells if dst is |
|
204 // available. |
|
205 if( nitzCaps & RMobilePhone::KCapsDSTAvailable ) |
|
206 { |
|
207 // Deduct the DST offset from the standard offset. |
|
208 nitzData->iTimeZoneOffset = timeZone * KQuaterHour |
|
209 - iNitzInfo.iDST * KMinute; |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 // Invalid timezone. Reset the offset. |
|
215 nitzData->iTimeZoneOffset = TTimeIntervalMinutes( -1 ); |
|
216 } |
|
217 } |
|
218 break; |
|
219 |
|
220 default: |
|
221 { |
|
222 // No implementation yet. |
|
223 } |
|
224 break; |
|
225 } |
|
226 |
|
227 __PRINTS( "CClockNitzPluginImpl::GetTimeInformationL - Exit" ); |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------- |
|
231 // CClockNitzPluginImpl::NotifyOnNITZInfoChange |
|
232 // rest of the details are commented in the header |
|
233 // --------------------------------------------------------- |
|
234 // |
|
235 void CClockNitzPluginImpl::NotifyOnNITZInfoChange( TInterfaceAttribute /*aInterfaceAttribute*/ ) |
|
236 { |
|
237 __PRINTS( "CClockNitzPluginImpl::NotifyOnNITZInfoChange - Entry" ); |
|
238 |
|
239 // Start the listener to get NITZ notifications. |
|
240 if( iNitzSrv ) |
|
241 { |
|
242 iNitzSrv->Start(); |
|
243 } |
|
244 |
|
245 __PRINTS( "CClockNitzPluginImpl::NotifyOnNITZInfoChange - Exit" ); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------- |
|
249 // CClockNitzPluginImpl::NotifyNITZInfoChange |
|
250 // rest of the details are commented in the header |
|
251 // --------------------------------------------------------- |
|
252 // |
|
253 void CClockNitzPluginImpl::NotifyNITZInfoChangeL() |
|
254 { |
|
255 __PRINTS( "CClockNitzPluginImpl::NotifyNITZInfoChange - Entry" ); |
|
256 |
|
257 // Notify the plugin that NITZ info has changed. |
|
258 if( iNitzPlugin ) |
|
259 { |
|
260 iNitzPlugin->NotifyNITZInfoChangeL(); |
|
261 } |
|
262 |
|
263 __PRINTS( "CClockNitzPluginImpl::NotifyNITZInfoChange - Exit" ); |
|
264 } |
|
265 |
|
266 // End of file |