|
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 of the RClkSrvInterface class |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <f32file.h> |
|
20 |
|
21 // User includes |
|
22 #include "clockserverclt.h" |
|
23 #include "clockservercommon.h" |
|
24 #include "clockservercmds.h" |
|
25 #include "clocktimesourceinterface.hrh" |
|
26 #include "clock_debug.h" |
|
27 |
|
28 // Constants |
|
29 const TInt KClockServerMajorVN( 1 ); |
|
30 const TInt KClockServerMinorVN( 0 ); |
|
31 const TInt KClockServerBuildVN( 1 ); |
|
32 const TInt KOneSecond = 1000000; |
|
33 const TInt KMaxRetryTimes = 3; |
|
34 |
|
35 // Literals |
|
36 _LIT( KPanicLabel, "RClkSrvSession:Panic" ); |
|
37 _LIT( KCommand, ""); |
|
38 _LIT(KDC_PROGRAMS_DIR,"\\sys\\bin\\"); |
|
39 _LIT( KClockServer, "Z:clockserver.exe"); |
|
40 |
|
41 // --------------------------------------------------------- |
|
42 // RClkSrvInterface::RClkSrvInterface |
|
43 // rest of the details are commented in the header. |
|
44 // --------------------------------------------------------- |
|
45 // |
|
46 EXPORT_C RClkSrvInterface::RClkSrvInterface() : iWhatChanged( NULL, NULL, NULL ), |
|
47 iWhoChanged( NULL, NULL, NULL ) |
|
48 { |
|
49 __PRINTS( "RClkSrvInterface::RClkSrvInterface - Entry" ); |
|
50 |
|
51 __PRINTS( "RClkSrvInterface::RClkSrvInterface - Exit" ); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // RClkSrvInterface::Connect |
|
56 // rest of the details are commented in the header. |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C TInt RClkSrvInterface::Connect() |
|
60 { |
|
61 __PRINTS( "RClkSrvInterface::Connect - Entry" ); |
|
62 |
|
63 TInt errVal( KErrNone ); |
|
64 |
|
65 // Create the session to the mentioned server. |
|
66 errVal = CreateSession( KNameClockServer, Version(), KClockServerMessageSlots ); |
|
67 |
|
68 // Try to start the server and then try to create session. |
|
69 if( KErrNone != errVal ) |
|
70 { |
|
71 __PRINT( "RClkSrvInterface::Connect - Server has not been started - error code : %d", errVal ); |
|
72 |
|
73 TRAP_IGNORE( StartClockSrvL() ); |
|
74 |
|
75 // Wait till server gets started. |
|
76 TInt seconds(0); |
|
77 while ( KErrNone != errVal ) |
|
78 { |
|
79 errVal = CreateSession( KNameClockServer, Version(), KClockServerMessageSlots ); |
|
80 User::After( KOneSecond ); |
|
81 seconds++; |
|
82 if ( KMaxRetryTimes == seconds ) |
|
83 { |
|
84 errVal = KErrServerTerminated; |
|
85 break; |
|
86 } |
|
87 } |
|
88 |
|
89 } |
|
90 |
|
91 __PRINTS( "RClkSrvInterface::Connect - Exit" ); |
|
92 |
|
93 return errVal; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------- |
|
97 // RClkSrvInterface::Version |
|
98 // rest of the details are commented in the header. |
|
99 // --------------------------------------------------------- |
|
100 // |
|
101 EXPORT_C TVersion RClkSrvInterface::Version() const |
|
102 { |
|
103 __PRINTS( "RClkSrvInterface::Version - Entry" ); |
|
104 |
|
105 __PRINTS( "RClkSrvInterface::Version - Exit" ); |
|
106 |
|
107 return TVersion( KClockServerMajorVN, KClockServerMinorVN, KClockServerBuildVN ); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // RClkSrvInterface::ActivateProtocol |
|
112 // rest of the details are commented in the header. |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C TInt RClkSrvInterface::ActivateProtocol( TInt aClkSrvProtocol ) |
|
116 { |
|
117 __PRINTS( "RClkSrvInterface::ActivateProtocol - Entry" ); |
|
118 __PRINT( "%x", aClkSrvProtocol ); |
|
119 |
|
120 __PRINTS( "RClkSrvInterface::ActivateProtocol - Exit" ); |
|
121 |
|
122 // Send the message and receive completion status (synchronous) |
|
123 return SendReceive( EClkSrvActivateProtocol, TIpcArgs( aClkSrvProtocol ) ); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // RClkSrvInterface::ActivateAllProtocols |
|
128 // rest of the details are commented in the header. |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C TInt RClkSrvInterface::ActivateAllProtocols() |
|
132 { |
|
133 __PRINTS( "RClkSrvInterface::ActivateAllProtocols - Entry" ); |
|
134 |
|
135 __PRINTS( "RClkSrvInterface::ActivateAllProtocols - Exit" ); |
|
136 |
|
137 // Send the message and receive completion status (synchronous) |
|
138 return SendReceive( EClkSrvActivateProtocol, TIpcArgs() ); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // RClkSrvInterface::IsProtocolActive |
|
143 // rest of the details are commented in the header. |
|
144 // --------------------------------------------------------- |
|
145 // |
|
146 EXPORT_C TInt RClkSrvInterface::IsProtocolActive( TInt aClkSrvProtocol, TBool& aActive ) |
|
147 { |
|
148 __PRINTS( "RClkSrvInterface::IsProtocolActive - Entry" ); |
|
149 __PRINT( "%x", aClkSrvProtocol ); |
|
150 |
|
151 TPckg< TBool > boolArg( aActive ); |
|
152 |
|
153 __PRINTS( "RClkSrvInterface::IsProtocolActive - Exit" ); |
|
154 |
|
155 // Send the message and receive completion status (synchronous) |
|
156 return SendReceive( EClkSrvIsProtocolActive, TIpcArgs( aClkSrvProtocol, &boolArg ) ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // RClkSrvInterface::DeActivateProtocol() |
|
161 // rest of the details are commented in the header. |
|
162 // --------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C TInt RClkSrvInterface::DeActivateProtocol( TInt aClkSrvProtocol ) |
|
165 { |
|
166 __PRINTS( "RClkSrvInterface::DeActivateProtocol() - Entry" ); |
|
167 __PRINT( "%x", aClkSrvProtocol ); |
|
168 |
|
169 __PRINTS( "RClkSrvInterface::DeActivateProtocol() - Exit" ); |
|
170 |
|
171 // Send the message and receive completion status (synchronous) |
|
172 return SendReceive( EClkSrvDeactivateProtocol, TIpcArgs( aClkSrvProtocol ) ); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------- |
|
176 // RClkSrvInterface::DeActivateAllProtocols() |
|
177 // rest of the details are commented in the header. |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TInt RClkSrvInterface::DeActivateAllProtocols() |
|
181 { |
|
182 __PRINTS( "RClkSrvInterface::DeActivateAllProtocols() - Entry" ); |
|
183 |
|
184 __PRINTS( "RClkSrvInterface::DeActivateAllProtocols() - Exit" ); |
|
185 |
|
186 // Send the message and receive completion status (synchronous) |
|
187 return SendReceive( EClkSrvDeactivateProtocol, TIpcArgs() ); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------- |
|
191 // RClkSrvInterface::GetProtocolInfo() |
|
192 // rest of the details are commented in the header. |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 EXPORT_C TInt RClkSrvInterface::GetProtocolInfo( TInt aClkSrvProtocol, STimeAttributes& aTimeAttribute ) |
|
196 { |
|
197 __PRINTS( "RClkSrvInterface::GetProtocolInfo() - Entry" ); |
|
198 |
|
199 TPckg< STimeAttributes > timeAttributeArg( aTimeAttribute ); |
|
200 |
|
201 __PRINTS( "RClkSrvInterface::GetProtocolInfo() - Exit" ); |
|
202 |
|
203 // Send the message and receive completion status (synchronous) |
|
204 return SendReceive( EClkSrvGetProtocolInfo, TIpcArgs( aClkSrvProtocol, &timeAttributeArg ) ); |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------- |
|
208 // RClkSrvInterface::GetCurrentMcc() |
|
209 // rest of the details are commented in the header. |
|
210 // --------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C TInt RClkSrvInterface::GetCurrentMcc( TInt& aCurrentMcc ) |
|
213 { |
|
214 __PRINTS( "RClkSrvInterface::GetCurrentMcc() - Entry" ); |
|
215 |
|
216 TPckg< TInt > aCurrentMccBuf( aCurrentMcc ); |
|
217 |
|
218 TInt returnVal( SendReceive( EClkSrvGetCurrentMcc, TIpcArgs( &aCurrentMccBuf ) ) ); |
|
219 |
|
220 __PRINT( "Current MCC - %d", aCurrentMcc ); |
|
221 |
|
222 __PRINTS( "RClkSrvInterface::GetCurrentMcc() - Exit" ); |
|
223 |
|
224 return returnVal; |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------- |
|
228 // RClkSrvInterface::GetCurrentTimeZondId() |
|
229 // rest of the details are commented in the header. |
|
230 // --------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C TInt RClkSrvInterface::GetCurrentTimeZondId( TInt& aCurrentTimeZoneId ) |
|
233 { |
|
234 __PRINTS( "RClkSrvInterface::GetCurrentTimeZondId() - Entry" ); |
|
235 |
|
236 TPckg< TInt > aCurrentTzIdBuf( aCurrentTimeZoneId ); |
|
237 |
|
238 TInt returnVal( SendReceive( EClkSrvGetCurrentTimeZoneId, TIpcArgs( &aCurrentTzIdBuf ) ) ); |
|
239 |
|
240 __PRINT( "Current timezone ID - %d", aCurrentTimeZoneId ); |
|
241 |
|
242 __PRINTS( "RClkSrvInterface::GetCurrentTimeZondId() - Exit" ); |
|
243 |
|
244 return returnVal; |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // RClkSrvInterface::NotifyOnChange() |
|
249 // rest of the details are commented in the header. |
|
250 // --------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C void RClkSrvInterface::NotifyOnChange( TInt32& aWhatChanged, TInt32& aWhoChanged, TRequestStatus& aStatus ) |
|
253 { |
|
254 __PRINTS( "RClkSrvInterface::NotifyOnChange() - Entry" ); |
|
255 |
|
256 iWhatChanged.Set( ( TUint8* )&aWhatChanged, sizeof( aWhatChanged ), sizeof( aWhatChanged ) ); |
|
257 iWhoChanged.Set( ( TUint8* )&aWhoChanged, sizeof( aWhoChanged ), sizeof( aWhoChanged ) ); |
|
258 |
|
259 // Send the message and receive completion status (asynchronous) |
|
260 SendReceive( EClkSrvNotifyOnChange, TIpcArgs( &iWhatChanged, &iWhoChanged ), aStatus ); |
|
261 |
|
262 __PRINTS( "RClkSrvInterface::NotifyOnChange() - Exit" ); |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // RClkSrvInterface::NotifyOnChange() |
|
267 // rest of the details are commented in the header. |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C void RClkSrvInterface::NotifyOnChangeCancel() |
|
271 { |
|
272 __PRINTS( "RClkSrvInterface::NotifyOnChangeCancel() - Entry" ); |
|
273 |
|
274 // Send the message and receive completion status (synchronous) |
|
275 TInt returnVal = SendReceive( EClkSrvCancelNotifyOnChange, TIpcArgs() ); |
|
276 |
|
277 __ASSERT_ALWAYS( KErrNone == returnVal || KErrServerTerminated, |
|
278 Panic( EClkSrvCltNotifyChangeCancel ) ); |
|
279 |
|
280 __PRINTS( "RClkSrvInterface::NotifyOnChangeCancel - Exit" ); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // RClkSrvInterface::IsAutoTimeUpdateOn |
|
285 // rest of the details are commented in the header. |
|
286 // --------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C TInt RClkSrvInterface::IsAutoTimeUpdateOn( TBool& aEnabled ) |
|
289 { |
|
290 __PRINTS( "RClkSrvInterface::IsAutoTimeUpdateOn - Entry" ); |
|
291 |
|
292 TPckg< TBool > boolArg( aEnabled ); |
|
293 |
|
294 __PRINTS( "RClkSrvInterface::IsAutoTimeUpdateOn - Exit" ); |
|
295 |
|
296 // Send the message and receive completion status (synchronous) |
|
297 return SendReceive( EClkSrvIsAutoTimeUpdadeOn, TIpcArgs( &boolArg ) ); |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------- |
|
301 // RClkSrvInterface::IsClockSrvRunning() const |
|
302 // rest of the details are commented in the header. |
|
303 // --------------------------------------------------------- |
|
304 // |
|
305 TInt RClkSrvInterface::IsClockSrvRunning() const |
|
306 { |
|
307 __PRINTS( "RClkSrvInterface::IsClockSrvRunning - Entry" ); |
|
308 |
|
309 TInt retVal( KErrNone ); |
|
310 TFindServer findServer( KNameClockServer ); |
|
311 TFullName name; |
|
312 if ( KErrNone != findServer.Next( name ) ) |
|
313 { |
|
314 __PRINTS( "RClkSrvInterface::Server is not running - Entry" ); |
|
315 |
|
316 RSemaphore semaphore; |
|
317 // Waites for Starter to start the nitz server for max. 3 seconds. |
|
318 for ( TInt i( 0 ); i < KMaxRetryTimes; i++ ) |
|
319 { |
|
320 retVal = semaphore.OpenGlobal( KNameClockServerStartSemaphore ); |
|
321 if ( KErrNone == retVal ) |
|
322 { |
|
323 __PRINTS( "RClkSrvInterface::Server is now running - Entry" ); |
|
324 |
|
325 semaphore.Close(); |
|
326 break; |
|
327 } |
|
328 User::After( KOneSecond ); |
|
329 } |
|
330 } |
|
331 |
|
332 __PRINTS( "RClkSrvInterface::IsClockSrvRunning - Exit" ); |
|
333 |
|
334 return retVal; |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------- |
|
338 // RClkSrvInterface::StartClockSrvL() |
|
339 // rest of the details are commented in the header. |
|
340 // --------------------------------------------------------- |
|
341 // |
|
342 void RClkSrvInterface::StartClockSrvL() |
|
343 { |
|
344 __PRINTS( "RClkSrvInterface::StartClockSrvL - Entry" ); |
|
345 |
|
346 if ( KErrNone != IsClockSrvRunning( ) ) |
|
347 { |
|
348 __PRINTS( "RClkSrvInterface::StartClockSrvL:IsClockSrvRunning - Entry" ); |
|
349 |
|
350 TParse fileparser; |
|
351 fileparser.Set( KClockServer, &KDC_PROGRAMS_DIR, NULL ); |
|
352 |
|
353 RProcess ClockSrvProc; |
|
354 CleanupClosePushL( ClockSrvProc ); |
|
355 User::LeaveIfError( ClockSrvProc.Create( fileparser.FullName( ), KCommand, |
|
356 TUidType( KNullUid, KNullUid, KClockSrvUid ) ) ); |
|
357 |
|
358 |
|
359 ClockSrvProc.Resume(); |
|
360 CleanupStack::PopAndDestroy( &ClockSrvProc ); |
|
361 } |
|
362 |
|
363 __PRINTS( "RClkSrvInterface::StartClockSrvL - Exit" ); |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------- |
|
367 // Panic |
|
368 // rest of the details are commented in the header. |
|
369 // --------------------------------------------------------- |
|
370 // |
|
371 GLDEF_C void Panic( TClkSrvSessionPanic aPanic ) |
|
372 { |
|
373 User::Panic( KPanicLabel, aPanic ); |
|
374 } |
|
375 |
|
376 // End of file |