|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include <ssm/ssmstates.hrh> |
|
17 #include <ssm/ssmstatetransition.h> |
|
18 #include <ssm/ssmstatepolicy.h> |
|
19 |
|
20 #include "ssmserverpanic.h" |
|
21 #include "ssmserver.h" |
|
22 #include "ssmsession.h" |
|
23 #include "ssmclisrv.h" |
|
24 #include "clesessionproxy.h" |
|
25 #include "ssmstatepolicyresolver.h" |
|
26 #include "ssmstatetransitionengine.h" |
|
27 #include "ssmstatepolicyresolverproxy.h" |
|
28 #include "ssmstatetransitionrequest.h" |
|
29 #include "ssmstatepolicyframe.h" |
|
30 #include "ssmswppolicyresolver.h" |
|
31 #include "ssmswprequesthandler.h" |
|
32 |
|
33 // ------------------- Policy Server Security Setup ---------------------- |
|
34 |
|
35 const TUint KRangeCount = 3; |
|
36 const TInt KRanges[KRangeCount] = |
|
37 { |
|
38 0, // op-code 0 not used |
|
39 KSsmFirstUsedOpCode, //range: KFirstUsedSsmOpCode...(EEndOfSsmOpCodes-1) inclusive |
|
40 EEndOfSsmOpCodes |
|
41 }; |
|
42 |
|
43 /** |
|
44 Specifies the appropriate action for each range in KRanges. |
|
45 The nth element of KElementsIndex specifies the appropriate action for the nth range in KRanges. |
|
46 */ |
|
47 const TUint8 KElementsIndex[KRangeCount] = |
|
48 { |
|
49 CPolicyServer::ENotSupported, |
|
50 CPolicyServer::EAlwaysPass, //All request will be accepted and passed on to policy DLL for security checks |
|
51 CPolicyServer::ENotSupported, |
|
52 }; |
|
53 |
|
54 /** |
|
55 Setup a security policy that always allows connection requests for all requests. |
|
56 */ |
|
57 const CPolicyServer::TPolicy KSsmServerPolicy = |
|
58 { |
|
59 CPolicyServer::EAlwaysPass, // Always allow connection requests |
|
60 KRangeCount, |
|
61 KRanges, |
|
62 KElementsIndex, |
|
63 NULL |
|
64 }; |
|
65 |
|
66 // ------------------- SsmServer Implementation ---------------------- |
|
67 |
|
68 /** |
|
69 EPriorityHigh to make sure the server is always scheduled before other AO such |
|
70 as CSsmStateTransitionEngine. |
|
71 */ |
|
72 CSsmServer::CSsmServer() : CPolicyServer(EPriorityHigh, KSsmServerPolicy) |
|
73 { |
|
74 } |
|
75 |
|
76 /** |
|
77 */ |
|
78 CSsmServer::~CSsmServer() |
|
79 { |
|
80 const TInt ignore = User::SetCritical(User::ENotCritical); |
|
81 |
|
82 delete iStateTransitionEngine; |
|
83 delete iSwpRequestHandler; |
|
84 delete iSwpResolver; |
|
85 if(NULL != iSwpCleSession) |
|
86 { |
|
87 iSwpCleSession->ReleaseCle(); |
|
88 } |
|
89 |
|
90 } //lint !e529 not subsequently referenced |
|
91 |
|
92 /** |
|
93 */ |
|
94 CSsmServer* CSsmServer::NewLC() |
|
95 { |
|
96 return CSsmServer::NewLC(ESsmStartup, EDoValidateCommandLists); |
|
97 } |
|
98 |
|
99 /** |
|
100 */ |
|
101 CSsmServer* CSsmServer::NewLC(TUint16 aInitialState) |
|
102 { |
|
103 return CSsmServer::NewLC(aInitialState, EDoValidateCommandLists); |
|
104 } |
|
105 |
|
106 /** |
|
107 */ |
|
108 CSsmServer* CSsmServer::NewLC(TUint16 aInitialState, TValidation aSetting) |
|
109 { |
|
110 CSsmServer* server = new(ELeave) CSsmServer(); |
|
111 CleanupStack::PushL(server); |
|
112 server->ConstructL(aInitialState, aSetting); |
|
113 server->StartL(KSsmServerName); |
|
114 return server; |
|
115 } |
|
116 |
|
117 #ifdef TEST_SSM_SERVER |
|
118 /** |
|
119 Factory method used by automated tests to avoid clash with production server name. |
|
120 */ |
|
121 CSsmServer* CSsmServer::NewLC(const TDesC& aServerName, TUint16 aInitialState) |
|
122 { |
|
123 CSsmServer* server = new(ELeave) CSsmServer(); |
|
124 CleanupStack::PushL(server); |
|
125 server->ConstructL(aInitialState, ENoCommandListValidation); |
|
126 server->StartL(aServerName); |
|
127 return server; |
|
128 } |
|
129 #endif //TEST_SSM_SERVER |
|
130 /** |
|
131 */ |
|
132 void CSsmServer::ConstructL(TUint16 aInitialState, TValidation aSetting) |
|
133 { |
|
134 __ASSERT_ALWAYS( KErrNone == User::SetCritical(User::ESystemCritical), PanicNow(KPanicSysStateMgr,ESsmServerError1)); |
|
135 __ASSERT_ALWAYS( KErrNone == User::RenameThread(KSsmServerName), PanicNow(KPanicSysStateMgr,ESsmServerError2)); |
|
136 |
|
137 // --- Instantiate the "System State" handling classes --- |
|
138 // Create a state policy resolver and load the initial policy |
|
139 CSsmStatePolicyResolver* stateResolver = CSsmStatePolicyResolver::NewLC(); |
|
140 const TSsmState initalState = TSsmState(aInitialState, KSsmAnySubState); |
|
141 stateResolver->GetStatePolicyL(initalState); |
|
142 CCleSessionProxy* stateCleSession = CCleSessionProxy::NewL(); |
|
143 CleanupStack::PushL(stateCleSession); |
|
144 // Create the state transition engine and let it take ownership of stateResolver and stateCleSession |
|
145 iStateTransitionEngine = CSsmStateTransitionEngine::NewL(stateResolver, stateCleSession); |
|
146 CleanupStack::Pop(2, stateResolver); |
|
147 // Configure engine |
|
148 iStateTransitionEngine->PerformCommandListValidation(EDoValidateCommandLists==aSetting); |
|
149 |
|
150 // --- Instantiate the SWP handling classes --- |
|
151 iSwpResolver = CSsmSwpPolicyResolver::NewL(); |
|
152 iSwpCleSession = CCleSessionProxy::NewL(); // Thought: Perhaps the CleSessionProxy should be a CLE session factory, thus allowing a separate session to be created for each engine |
|
153 // Create the swp request handler and wire it up to the proxies |
|
154 iSwpRequestHandler = CSsmSwpRequestHandler::NewL(); |
|
155 iSwpRequestHandler->SetSwpPolicyResolverProxy(iSwpResolver); |
|
156 iSwpRequestHandler->SetCleSessionProxy(iSwpCleSession); |
|
157 iSwpRequestHandler->PerformCommandListValidation(EDoValidateCommandLists==aSetting); |
|
158 |
|
159 //Request initial actions |
|
160 const TSsmStateTransition doStartup(initalState, 0); |
|
161 iStateTransitionEngine->SubmitL(doStartup); |
|
162 } |
|
163 |
|
164 /** |
|
165 */ |
|
166 CSession2* CSsmServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
167 { |
|
168 // Check we're the right version |
|
169 TVersion version(KSsmServMajorVersionNumber,KSsmServMinorVersionNumber,KSsmServBuildVersionNumber); |
|
170 if (!User::QueryVersionSupported(version,aVersion)) |
|
171 { |
|
172 User::Leave(KErrNotSupported); |
|
173 } |
|
174 |
|
175 // version supported, go ahead |
|
176 return CSsmSession::NewL(); |
|
177 } |
|
178 |
|
179 /** |
|
180 */ |
|
181 void CSsmServer::RequestStateTransitionL(const TSsmState& aState, TInt aReason, const RMessage2& aMessage) |
|
182 { |
|
183 __ASSERT_DEBUG(iStateTransitionEngine, PanicNow(KPanicSysStateMgr,ESsmServerError3)); |
|
184 |
|
185 const TSsmStateTransition request(aState, aReason); |
|
186 const MSsmStatePolicy::TResponse response = iStateTransitionEngine->TransitionAllowed(request, aMessage); |
|
187 switch(response) |
|
188 { |
|
189 case MSsmStatePolicy::EDefinitelyAllowed: |
|
190 case MSsmStatePolicy::ECurrentRemainReplaceQueued: |
|
191 { |
|
192 // A leave here will complete the client-request with KErrNoMemory |
|
193 iStateTransitionEngine->SubmitL(request, aMessage); |
|
194 break; |
|
195 } |
|
196 |
|
197 case MSsmStatePolicy::EReplaceCurrentClearQueue: |
|
198 { |
|
199 iStateTransitionEngine->Cancel(NULL); |
|
200 iStateTransitionEngine->SubmitL(request, aMessage); |
|
201 break; |
|
202 } |
|
203 |
|
204 case MSsmStatePolicy::ENotAllowed: |
|
205 default: |
|
206 { |
|
207 aMessage.Complete(KErrNotSupported); |
|
208 break; |
|
209 } |
|
210 } |
|
211 } |
|
212 |
|
213 /** |
|
214 Cancel any transition job that is accepted but not yet started. |
|
215 */ |
|
216 void CSsmServer::RequestStateTransitionCancel(CSession2* aSession) |
|
217 { |
|
218 iStateTransitionEngine->Cancel(aSession); |
|
219 } |
|
220 |
|
221 /** |
|
222 Initiate processing of the request for a system wide property change |
|
223 */ |
|
224 void CSsmServer::RequestSwpChangeL(const TSsmSwp& aSwp, const RMessage2& aMessage) |
|
225 { |
|
226 iSwpRequestHandler->SubmitRequestL(aSwp, aMessage); |
|
227 } |
|
228 |
|
229 /** |
|
230 Cancel processing of pending and running system wide property change requests |
|
231 */ |
|
232 void CSsmServer::RequestSwpChangeCancel(CSession2* aSession) |
|
233 { |
|
234 iSwpRequestHandler->Cancel(aSession); |
|
235 } |
|
236 |
|
237 /** |
|
238 Register the policy file name for this swp |
|
239 This also marks the actual existence of the swp |
|
240 */ |
|
241 void CSsmServer::RequestRegisterSwpMappingL(TUint aSwpKey, const TDesC& aFilename) |
|
242 { |
|
243 iSwpResolver->RegisterSwpMappingL(aSwpKey, aFilename); |
|
244 } //lint !e1746 Suppress parameter 'aSwpKey' could be made const reference |
|
245 |
|
246 /** |
|
247 * Used only for testing purposes |
|
248 * DeRegister the policy file name for this swp |
|
249 */ |
|
250 #ifdef _DEBUG |
|
251 void CSsmServer::RequestDeRegisterSwpMappingL(TUint aSwpKey, const TDesC& aFilename) |
|
252 { |
|
253 iSwpResolver->DeRegisterSwpMappingL(aSwpKey, aFilename); |
|
254 } |
|
255 #endif |
|
256 |
|
257 /** |
|
258 * Used only for testing purposes |
|
259 * Cleanup Transition Engine after the test is over |
|
260 */ |
|
261 #ifdef _DEBUG |
|
262 void CSsmServer::DoCleanupStateTransitionEngine() |
|
263 { |
|
264 iStateTransitionEngine->CleanupTransitionEngine(); |
|
265 } |
|
266 #endif |
|
267 |
|
268 /** |
|
269 * Used only for testing purposes |
|
270 * Cleanup Request Handler after the test is over |
|
271 */ |
|
272 #ifdef _DEBUG |
|
273 void CSsmServer::DoCleanupSwpRequestHandler() |
|
274 { |
|
275 iSwpRequestHandler->CleanupSwpTransitionScheduler(); |
|
276 } |
|
277 #endif |