|
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 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <e32debug.h> |
|
23 #include <e32property.h> |
|
24 #include <s32mem.h> |
|
25 #include <f32file.h> |
|
26 #include <s32file.h> |
|
27 |
|
28 #include "tssm_customcmd.h" |
|
29 #include "tssm_ssmclient.h" |
|
30 #include "ssmdebug.h" |
|
31 |
|
32 #include <ssm/ssmstatemanager.h> |
|
33 #include <ssm/ssmcustomcommand.h> |
|
34 |
|
35 /** |
|
36 Function expects no arguments in buffer. |
|
37 |
|
38 @param aBuffer - contains the argument values passed from System Starter |
|
39 */ |
|
40 EXPORT_C TInt TCustomCmdDllFn1(const TDesC8& /* aBuffer */) |
|
41 { |
|
42 RDebug::Print(_L("TCustomComdDllFn1 - entry: Used to test a panic in a custom cmd")); |
|
43 |
|
44 User::Panic(KSsmCustomCmdTest, ESsmCustomCmdTestPanic1); |
|
45 |
|
46 RDebug::Print(_L("TCustomComdDllFn1 - exit")); |
|
47 return KErrNone; |
|
48 } |
|
49 |
|
50 EXPORT_C void TCustomCmdDllFn2L(const TDesC8& /* aBuffer */) |
|
51 { |
|
52 RDebug::Print(_L("TCustomComdDllFn2 - entry: Used to test a capability error in a custom cmd")); |
|
53 |
|
54 User::Leave(KErrPermissionDenied); |
|
55 |
|
56 RDebug::Print(_L("TCustomComdDllFn2 - exit")); |
|
57 } |
|
58 |
|
59 EXPORT_C TInt TCustomCmdDllFn3(const TDesC8& /* aBuffer */) |
|
60 { |
|
61 RDebug::Print(_L("TCustomComdDllFn3 - entry")); |
|
62 |
|
63 User::Panic(KSsmCustomCmdTest, ESsmCustomCmdTestPanic3); |
|
64 |
|
65 RDebug::Print(_L("TCustomComdDllFn3 - exit")); |
|
66 return KErrNone; |
|
67 } |
|
68 |
|
69 EXPORT_C TInt TCustomCmdDllFn4(const TDesC8& /* aBuffer */) |
|
70 { |
|
71 RDebug::Print(_L("TCustomComdDllFn4 - entry")); |
|
72 |
|
73 User::Panic(KSsmCustomCmdTest, ESsmCustomCmdTestPanic4); |
|
74 |
|
75 RDebug::Print(_L("TCustomComdDllFn4 - exit")); |
|
76 return KErrNone; |
|
77 } |
|
78 |
|
79 /** |
|
80 * This custom command never finishes execution and |
|
81 * when cancelled will cancel an SwP transition |
|
82 * |
|
83 * @internalComponent |
|
84 * @test |
|
85 */ |
|
86 |
|
87 NONSHARABLE_CLASS(CWaitingCancelSwPCustomCmd) : public CBase, public MSsmCustomCommand |
|
88 { |
|
89 public: |
|
90 static CWaitingCancelSwPCustomCmd* NewL(); |
|
91 |
|
92 // from MSsmCustomCommand |
|
93 TInt Initialize(CSsmCustomCommandEnv* /*aCmdEnv*/); |
|
94 void Execute(const TDesC8& /*aParams*/, TRequestStatus& aRequest); |
|
95 void Close(); |
|
96 void Release(); |
|
97 void ExecuteCancel(); |
|
98 |
|
99 ~CWaitingCancelSwPCustomCmd(); |
|
100 |
|
101 private: |
|
102 void ConstructL(); |
|
103 |
|
104 private: |
|
105 TRequestStatus* iRequestStatus; |
|
106 RSsmStateManager iStateManager; |
|
107 }; |
|
108 |
|
109 CWaitingCancelSwPCustomCmd* CWaitingCancelSwPCustomCmd::NewL() |
|
110 { |
|
111 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::NewL() called")); |
|
112 CWaitingCancelSwPCustomCmd* self = new (ELeave) CWaitingCancelSwPCustomCmd(); |
|
113 CleanupStack::PushL(self); |
|
114 self->ConstructL(); |
|
115 CleanupStack::Pop(self); |
|
116 return self; |
|
117 } |
|
118 |
|
119 class RFakeSsmCreator : public RSessionBase |
|
120 { |
|
121 public: |
|
122 TInt Connect() |
|
123 { |
|
124 return CreateSession(KSsmServerNameTest, TVersion(KSsmServMajorVersionNumber, KSsmServMinorVersionNumber, KSsmServBuildVersionNumber)); |
|
125 } |
|
126 }; |
|
127 |
|
128 void CWaitingCancelSwPCustomCmd::ConstructL() |
|
129 { |
|
130 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::ConstructL() called")); |
|
131 // To get connected to the testing SSM server first make a connection using the RFakeSsmCreator class |
|
132 RFakeSsmCreator base; |
|
133 User::LeaveIfError(base.Connect()); |
|
134 // base is now connected to the testing SSM server |
|
135 // transfer ownership of base.Handle() handle ID to iStateManager |
|
136 iStateManager.SetHandle(base.Handle()); |
|
137 // base is not closed before returning as ownership of the handle has been passed to iStateManager |
|
138 // this is just like transfering ownership of pointers |
|
139 } |
|
140 |
|
141 CWaitingCancelSwPCustomCmd::~CWaitingCancelSwPCustomCmd() |
|
142 { |
|
143 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::~CWaitingCancelSwPCustomCmd() called")); |
|
144 iStateManager.Close(); |
|
145 } |
|
146 |
|
147 TInt CWaitingCancelSwPCustomCmd::Initialize(CSsmCustomCommandEnv* /*aCmdEnv*/) |
|
148 { |
|
149 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::Initialize() called")); |
|
150 // Nothing to do |
|
151 return KErrNone; |
|
152 } |
|
153 |
|
154 void CWaitingCancelSwPCustomCmd::Execute(const TDesC8& /*aParams*/, TRequestStatus& aRequest) |
|
155 { |
|
156 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::Execute() called")); |
|
157 iRequestStatus = &aRequest; |
|
158 aRequest = KRequestPending; |
|
159 } |
|
160 |
|
161 void CWaitingCancelSwPCustomCmd::Close() |
|
162 { |
|
163 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::Close() called")); |
|
164 // Nothing to do |
|
165 } |
|
166 |
|
167 void CWaitingCancelSwPCustomCmd::Release() |
|
168 { |
|
169 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::Release() called")); |
|
170 delete this; |
|
171 } |
|
172 |
|
173 void CWaitingCancelSwPCustomCmd::ExecuteCancel() |
|
174 { |
|
175 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::ExecuteCancel() called")); |
|
176 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::ExecuteCancel() - calling iStateManager.RequestSwpChangeCancel()")); |
|
177 // Cancel a change which hasn't been issued |
|
178 iStateManager.RequestSwpChangeCancel(); |
|
179 DEBUGPRINT1(_L("CWaitingCancelSwPCustomCmd::ExecuteCancel() - completing request")); |
|
180 User::RequestComplete(iRequestStatus, KErrCancel); |
|
181 } |
|
182 |
|
183 EXPORT_C MSsmCustomCommand* TCustomCmdDllFn5L() |
|
184 { |
|
185 return CWaitingCancelSwPCustomCmd::NewL(); |
|
186 } |
|
187 |
|
188 /** |
|
189 * This custom command waits until the property specified in |
|
190 * the parameters to change value before continuing. |
|
191 * |
|
192 * @internalComponent |
|
193 * @test |
|
194 */ |
|
195 |
|
196 NONSHARABLE_CLASS(CWaitingPnsCustomCmd) : public CBase, public MSsmCustomCommand |
|
197 { |
|
198 public: |
|
199 static CWaitingPnsCustomCmd* NewL(); |
|
200 |
|
201 // from MSsmCustomCommand |
|
202 TInt Initialize(CSsmCustomCommandEnv* aCmdEnv); |
|
203 void Execute(const TDesC8& aParams, TRequestStatus& aRequest); |
|
204 void Close(); |
|
205 void Release(); |
|
206 void ExecuteCancel(); |
|
207 |
|
208 private: |
|
209 void ConstructL(); |
|
210 ~CWaitingPnsCustomCmd(); |
|
211 |
|
212 private: |
|
213 RProperty iProperty; |
|
214 }; |
|
215 |
|
216 CWaitingPnsCustomCmd* CWaitingPnsCustomCmd::NewL() |
|
217 { |
|
218 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::NewL() called")); |
|
219 CWaitingPnsCustomCmd* self = new (ELeave) CWaitingPnsCustomCmd(); |
|
220 CleanupStack::PushL(self); |
|
221 self->ConstructL(); |
|
222 CleanupStack::Pop(self); |
|
223 return self; |
|
224 } |
|
225 |
|
226 void CWaitingPnsCustomCmd::ConstructL() |
|
227 { |
|
228 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::ConstructL() called")); |
|
229 } |
|
230 |
|
231 CWaitingPnsCustomCmd::~CWaitingPnsCustomCmd() |
|
232 { |
|
233 if(iProperty.Handle() != KNullHandle) |
|
234 { |
|
235 iProperty.Cancel(); |
|
236 } |
|
237 iProperty.Close(); |
|
238 } |
|
239 |
|
240 TInt CWaitingPnsCustomCmd::Initialize(CSsmCustomCommandEnv* /*aCmdEnv*/) |
|
241 { |
|
242 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::Initialize() called")); |
|
243 // Nothing to do |
|
244 return KErrNone; |
|
245 } |
|
246 |
|
247 void CWaitingPnsCustomCmd::Execute(const TDesC8& aParams, TRequestStatus& aRequest) |
|
248 { |
|
249 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::Execute() called")); |
|
250 RDesReadStream stream; |
|
251 stream.Open(aParams); |
|
252 // Read the key value for the property to read |
|
253 TUint32 key = 0; |
|
254 TRAPD(err, key = stream.ReadUint32L()); |
|
255 stream.Close(); |
|
256 |
|
257 if (err != KErrNone) |
|
258 { |
|
259 DEBUGPRINT2(_L("CWaitingPnsCustomCmd::Execute() - failure reading P+S value to wait on: %d"), err); |
|
260 TRequestStatus* trs = &aRequest; |
|
261 User::RequestComplete(trs, err); |
|
262 return; |
|
263 } |
|
264 else |
|
265 { |
|
266 DEBUGPRINT2(_L("CWaitingPnsCustomCmd::Execute() - P+S value to wait on: 0x%x"), key); |
|
267 err = iProperty.Attach(RProcess().SecureId(), key); |
|
268 if (err != KErrNone) |
|
269 { |
|
270 DEBUGPRINT2(_L("CWaitingPnsCustomCmd::Execute() - error attaching to P+S key: %d"), err); |
|
271 TRequestStatus* trs = &aRequest; |
|
272 User::RequestComplete(trs, err); |
|
273 return; |
|
274 } |
|
275 // Successfully attached so subscribe |
|
276 iProperty.Subscribe(aRequest); |
|
277 } |
|
278 } |
|
279 |
|
280 void CWaitingPnsCustomCmd::Close() |
|
281 { |
|
282 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::Close() called")); |
|
283 // Nothing to do |
|
284 } |
|
285 |
|
286 void CWaitingPnsCustomCmd::Release() |
|
287 { |
|
288 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::Release() called")); |
|
289 delete this; |
|
290 } |
|
291 |
|
292 void CWaitingPnsCustomCmd::ExecuteCancel() |
|
293 { |
|
294 DEBUGPRINT1(_L("CWaitingPnsCustomCmd::ExecuteCancel() called")); |
|
295 if(iProperty.Handle() != KNullHandle) |
|
296 { |
|
297 iProperty.Cancel(); |
|
298 } |
|
299 } |
|
300 |
|
301 EXPORT_C MSsmCustomCommand* TCustomCmdDllFn6L() |
|
302 { |
|
303 return CWaitingPnsCustomCmd::NewL(); |
|
304 } |