|
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 CClkSrvMain class. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32err.h> |
|
20 #include <centralrepository.h> |
|
21 |
|
22 // User includes |
|
23 #include "clockserver.h" |
|
24 #include "clockserversession.h" |
|
25 #include "clockservercommon.h" |
|
26 #include "clockserverimpl.h" |
|
27 #include "clockprivatecrkeys.h" |
|
28 #include "clock_debug.h" |
|
29 |
|
30 // Constants |
|
31 const TInt KClockServerMajorVN( 1 ); |
|
32 const TInt KClockServerMinorVN( 0 ); |
|
33 const TInt KClockServerBuildVN( 1 ); |
|
34 |
|
35 // --------------------------------------------------------- |
|
36 // CClkSrvMain::NewL |
|
37 // rest of the details are commented in the header |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 CClkSrvMain* CClkSrvMain::NewL() |
|
41 { |
|
42 __PRINTS( "CClkSrvMain::NewL - Entry" ); |
|
43 |
|
44 CClkSrvMain* clockServer = new( ELeave ) CClkSrvMain( CActive::EPriorityStandard ); |
|
45 CleanupStack::PushL( clockServer ); |
|
46 |
|
47 clockServer->ConstructL(); |
|
48 clockServer->StartL( KNameClockServer ); |
|
49 |
|
50 CleanupStack::Pop( clockServer ); |
|
51 |
|
52 __PRINTS( "CClkSrvMain::NewL - Exit" ); |
|
53 |
|
54 return clockServer; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CClkSrvMain::~CClkSrvMain |
|
59 // rest of the details are commented in the header |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 CClkSrvMain::~CClkSrvMain() |
|
63 { |
|
64 __PRINTS( "CClkSrvMain::~CClkSrvMain - Entry" ); |
|
65 |
|
66 // Destroy the server implementation. |
|
67 if( iClkSrvImpl ) |
|
68 { |
|
69 delete iClkSrvImpl; |
|
70 iClkSrvImpl = NULL; |
|
71 } |
|
72 |
|
73 __PRINTS( "CClkSrvMain::~CClkSrvMain - Exit" ); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // CClkSrvMain::CClkSrvMain |
|
78 // rest of the details are commented in the header |
|
79 // --------------------------------------------------------- |
|
80 // |
|
81 CClkSrvMain::CClkSrvMain( TInt aPriority ) |
|
82 : CServer2( aPriority ), iSessionQue( CClkSrvSession::LinkOffset() ) |
|
83 { |
|
84 __PRINTS( "CClkSrvMain::CClkSrvMain - Entry" ); |
|
85 |
|
86 // No implementation yet |
|
87 |
|
88 __PRINTS( "CClkSrvMain::CClkSrvMain - Exit" ); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CClkSrvMain::ConstructL |
|
93 // rest of the details are commented in the header |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 void CClkSrvMain::ConstructL() |
|
97 { |
|
98 __PRINTS( "CClkSrvMain::ConstructL - Entry" ); |
|
99 |
|
100 iClkSrvImpl = CClkSrvImpl::NewL( this ); |
|
101 |
|
102 // Restore the state of the clockserver system. |
|
103 RestoreStateL(); |
|
104 |
|
105 __PRINTS( "CClkSrvMain::ConstructL - Exit" ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CClkSrvMain::ConstructL |
|
110 // rest of the details are commented in the header |
|
111 // --------------------------------------------------------- |
|
112 // |
|
113 void CClkSrvMain::RestoreStateL() |
|
114 { |
|
115 __PRINTS( "CClkSrvMain::RestoreState - Entry" ); |
|
116 |
|
117 // Here we read from the cenrep the id of the plugin which was active. |
|
118 // If the id is not NULL, we activate the plugin. |
|
119 |
|
120 TInt pluginId( NULL ); |
|
121 // Get the active plugin id. |
|
122 TInt errVal( GetActivePluginL( pluginId ) ); |
|
123 |
|
124 if( ( KErrNone == errVal ) && pluginId ) |
|
125 { |
|
126 // Activate the plugin. |
|
127 iClkSrvImpl->ActivateAllProtocolsL(); |
|
128 } |
|
129 |
|
130 __PRINTS( "CClkSrvMain::RestoreState - Exit" ); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // CClkSrvMain::NewSessionL |
|
135 // rest of the details are commented in the header |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 CSession2* CClkSrvMain::NewSessionL( const TVersion& aVersion, const RMessage2& /*aMessage*/ ) const |
|
139 { |
|
140 __PRINTS( "CClkSrvMain::NewSessionL - Entry" ); |
|
141 |
|
142 TVersion versionObj( KClockServerMajorVN, KClockServerMinorVN, KClockServerBuildVN ); |
|
143 |
|
144 // Check if the version is supported. |
|
145 if( !User::QueryVersionSupported( versionObj, aVersion ) ) |
|
146 { |
|
147 // Version not supported. |
|
148 User::Leave( KErrNotSupported ); |
|
149 } |
|
150 |
|
151 // Create a session and add it to the server's session queue. |
|
152 CClkSrvSession* clockSrvSes = new( ELeave ) CClkSrvSession( iClkSrvImpl ); |
|
153 |
|
154 CClkSrvMain* clockServer = ( CClkSrvMain* )this; |
|
155 |
|
156 // Add the session to the queue. |
|
157 clockServer->SessionQue().AddLast( *clockSrvSes ); |
|
158 |
|
159 __PRINTS( "CClkSrvMain::NewSessionL - Exit" ); |
|
160 |
|
161 // return the session |
|
162 return clockSrvSes; |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------- |
|
166 // CClkSrvMain::NotifyAboutChange |
|
167 // rest of the details are commented in the header |
|
168 // --------------------------------------------------------- |
|
169 // |
|
170 void CClkSrvMain::NotifyAboutChange( TChangedComponent aWhatChanged, TInt aWhoChanged, TInt aNotification ) |
|
171 { |
|
172 __PRINTS( "CClkSrvMain::NotifyAboutChange - Entry" ); |
|
173 |
|
174 __PRINT( "%d", aNotification ); |
|
175 |
|
176 // Get the session que iterator. |
|
177 TDblQueIter< CClkSrvSession > sessionQueIter( SessionQue() ); |
|
178 |
|
179 // Get each session object and notify about the change. |
|
180 CClkSrvSession* clkSrvSession = NULL; |
|
181 |
|
182 while( NULL != ( clkSrvSession = sessionQueIter++ ) ) |
|
183 { |
|
184 __PRINTS( "Notify for Session" ); |
|
185 |
|
186 clkSrvSession->NotifyAboutChange( aWhatChanged, aWhoChanged, aNotification ); |
|
187 } |
|
188 |
|
189 __PRINTS( "CClkSrvMain::NotifyAboutChange - Exit" ); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------- |
|
193 // CClkSrvMain::SessionQue |
|
194 // rest of the details are commented in the header |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 TDblQue< CClkSrvSession >& CClkSrvMain::SessionQue() |
|
198 { |
|
199 __PRINTS( "CClkSrvMain::SessionQue - Entry" ); |
|
200 |
|
201 __PRINTS( "CClkSrvMain::SessionQue - Exit" ); |
|
202 |
|
203 return iSessionQue; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CClkSrvMain::GetActivePluginL |
|
208 // rest of the details are commented in the header. |
|
209 // --------------------------------------------------------- |
|
210 // |
|
211 TInt CClkSrvMain::GetActivePluginL( TInt& aPluginId ) const |
|
212 { |
|
213 __PRINTS( "CClkSrvMain::GetActivePluginL - Entry" ); |
|
214 |
|
215 TInt returnVal( KErrNone ); |
|
216 CRepository* cenRep( NULL ); |
|
217 |
|
218 // Open the repository. |
|
219 TRAPD( errVal, cenRep = CRepository::NewL( KCRUidNitz ) ); |
|
220 if( KErrNone == errVal ) |
|
221 { |
|
222 // Read the key. |
|
223 errVal = cenRep->Get( KActiveProtocol, aPluginId ); |
|
224 |
|
225 if( KErrNone != errVal ) |
|
226 { |
|
227 returnVal = errVal; |
|
228 } |
|
229 |
|
230 delete cenRep; |
|
231 } |
|
232 |
|
233 __PRINTS( "CClkSrvMain::GetActivePluginL - Exit" ); |
|
234 |
|
235 return returnVal; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CClkSrvMain::SetActivePluginL |
|
240 // rest of the details are commented in the header. |
|
241 // --------------------------------------------------------- |
|
242 // |
|
243 TInt CClkSrvMain::SetActivePluginL( TInt aPluginId ) |
|
244 { |
|
245 __PRINTS( "CClkSrvMain::SetActivePluginL - Entry" ); |
|
246 |
|
247 TInt returnVal( KErrNone ); |
|
248 CRepository* cenRep( NULL ); |
|
249 |
|
250 // Open the repository. |
|
251 TRAPD( errVal, cenRep = CRepository::NewL( KCRUidNitz ) ); |
|
252 if( KErrNone == errVal ) |
|
253 { |
|
254 // Update the key. |
|
255 errVal = cenRep->Set( KActiveProtocol, aPluginId ); |
|
256 |
|
257 if( KErrNone != errVal ) |
|
258 { |
|
259 returnVal = errVal; |
|
260 } |
|
261 |
|
262 delete cenRep; |
|
263 } |
|
264 |
|
265 __PRINTS( "CClkSrvMain::SetActivePluginL - Exit" ); |
|
266 |
|
267 return returnVal; |
|
268 } |
|
269 |
|
270 // End of file |