|
1 /* |
|
2 * Copyright (c) 2006-2009 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tintegrityservicesserver.h" |
|
20 #include "tintegrityservicesclientserver.h" |
|
21 #include "integrityservices.h" |
|
22 #include "log.h" |
|
23 #include <e32debug.h> |
|
24 |
|
25 |
|
26 _LIT(KJournalPath, "\\IntegrityServices\\"); |
|
27 |
|
28 using Swi::Test::CIntegrityServicesServer; |
|
29 using Swi::Test::CIntegrityServicesSession; |
|
30 using Swi::Test::CShutdownTimer; |
|
31 |
|
32 static void PanicClient(const RMessagePtr2& aMessage, |
|
33 Swi::Test::TIntegrityServicesServerPanic aPanic) |
|
34 { |
|
35 aMessage.Panic(Swi::Test::KIntegrityServicesServerName, aPanic); |
|
36 } |
|
37 |
|
38 ///// |
|
39 ///// CIntegrityServicesServer |
|
40 ///// |
|
41 |
|
42 CIntegrityServicesServer* CIntegrityServicesServer::NewLC() |
|
43 { |
|
44 CIntegrityServicesServer* self = new(ELeave) CIntegrityServicesServer(); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 void CIntegrityServicesServer::AddSession() |
|
51 { |
|
52 ++iSessionCount; |
|
53 iShutdown->Cancel(); |
|
54 } |
|
55 |
|
56 void CIntegrityServicesServer::DropSession() |
|
57 { |
|
58 if (--iSessionCount==0) |
|
59 { |
|
60 iShutdown->Start(); |
|
61 RDebug::Print(_L("Server shutting down")); |
|
62 } |
|
63 } |
|
64 |
|
65 CIntegrityServicesServer::~CIntegrityServicesServer() |
|
66 { |
|
67 delete iShutdown; |
|
68 RDebug::Print(_L("Server destructor")); |
|
69 } |
|
70 |
|
71 CIntegrityServicesServer::CIntegrityServicesServer() : CServer2(EPriorityNormal, ESharableSessions) |
|
72 { |
|
73 } |
|
74 |
|
75 void CIntegrityServicesServer::ConstructL() |
|
76 { |
|
77 StartL(Swi::Test::KIntegrityServicesServerName); |
|
78 |
|
79 iShutdown = CShutdownTimer::NewL(); |
|
80 |
|
81 // Ensure that the server still exits even if the 1st client fails to |
|
82 // connect |
|
83 iShutdown->Start(); |
|
84 } |
|
85 |
|
86 CSession2* CIntegrityServicesServer::NewSessionL(const TVersion& /*aVersion*/, |
|
87 const RMessage2& /*aMessage*/) const |
|
88 { |
|
89 return CIntegrityServicesSession::NewL(); |
|
90 } |
|
91 |
|
92 CIntegrityServicesSession* CIntegrityServicesSession::NewL() |
|
93 { |
|
94 CIntegrityServicesSession* self = CIntegrityServicesSession::NewLC(); |
|
95 CleanupStack::Pop(self); |
|
96 return self; |
|
97 } |
|
98 |
|
99 |
|
100 CIntegrityServicesSession* CIntegrityServicesSession::NewLC() |
|
101 { |
|
102 CIntegrityServicesSession* self = new(ELeave) CIntegrityServicesSession(); |
|
103 CleanupStack::PushL(self); |
|
104 self->ConstructL(); |
|
105 return self; |
|
106 } |
|
107 |
|
108 CIntegrityServicesSession::CIntegrityServicesSession() : CSession2() |
|
109 { |
|
110 } |
|
111 |
|
112 void CIntegrityServicesSession::ConstructL() |
|
113 { |
|
114 iIntegrityServices = CDummyIntegrityServices::NewL(0, KJournalPath); |
|
115 } |
|
116 |
|
117 void CIntegrityServicesSession::CreateL() |
|
118 { |
|
119 RDebug::Print(_L("Session CreateL")); |
|
120 Server().AddSession(); |
|
121 } |
|
122 |
|
123 |
|
124 |
|
125 CIntegrityServicesSession::~CIntegrityServicesSession() |
|
126 { |
|
127 delete iIntegrityServices; |
|
128 Server().DropSession(); |
|
129 } |
|
130 |
|
131 CIntegrityServicesServer& CIntegrityServicesSession::Server() |
|
132 { |
|
133 return *static_cast<CIntegrityServicesServer*>( |
|
134 const_cast<CServer2*>(CSession2::Server())); |
|
135 } |
|
136 |
|
137 ///// |
|
138 ///// CIntegrityServicesSession |
|
139 ///// |
|
140 |
|
141 void CIntegrityServicesSession::ServiceL(const RMessage2& aMessage) |
|
142 { |
|
143 switch (aMessage.Function()) |
|
144 { |
|
145 case EAdd: |
|
146 { |
|
147 RDebug::Print(_L("ServiceL EAdd")); |
|
148 HBufC16* fileName = HBufC16::NewLC(aMessage.GetDesLength(0)); |
|
149 TPtr16 ptr(fileName->Des()); |
|
150 aMessage.Read(0, ptr); |
|
151 |
|
152 TRAPD(err, iIntegrityServices->AddL(*fileName)); |
|
153 |
|
154 aMessage.Complete(err); |
|
155 CleanupStack::PopAndDestroy(fileName); |
|
156 break; |
|
157 } |
|
158 case ERemove: |
|
159 { |
|
160 RDebug::Print(_L("ServiceL ERemove")); |
|
161 HBufC16* fileName = HBufC16::NewLC(aMessage.GetDesLength(0)); |
|
162 TPtr16 ptr(fileName->Des()); |
|
163 aMessage.Read(0, ptr); |
|
164 |
|
165 TRAPD(err, iIntegrityServices->RemoveL(*fileName)); |
|
166 |
|
167 aMessage.Complete(err); |
|
168 CleanupStack::PopAndDestroy(fileName); |
|
169 |
|
170 break; |
|
171 } |
|
172 case ETemporary: |
|
173 { |
|
174 RDebug::Print(_L("ServiceL ETemporary")); |
|
175 HBufC16* fileName = HBufC16::NewLC(aMessage.GetDesLength(0)); |
|
176 TPtr16 ptr(fileName->Des()); |
|
177 aMessage.Read(0, ptr); |
|
178 |
|
179 TRAPD(err, iIntegrityServices->TemporaryL(*fileName)); |
|
180 |
|
181 aMessage.Complete(err); |
|
182 CleanupStack::PopAndDestroy(fileName); |
|
183 break; |
|
184 } |
|
185 case ECommit: |
|
186 { |
|
187 RDebug::Print(_L("ServiceL ECommit")); |
|
188 TRAPD(err, iIntegrityServices->CommitL()); |
|
189 aMessage.Complete(err); |
|
190 break; |
|
191 } |
|
192 case ERollBack: |
|
193 { |
|
194 RDebug::Print(_L("ServiceL ERollBack")); |
|
195 TBool all; |
|
196 TPckg<TBool> allTransactions(all); |
|
197 aMessage.ReadL(0, allTransactions); |
|
198 |
|
199 TRAPD(err, iIntegrityServices->RollBackL(all)); |
|
200 |
|
201 aMessage.Complete(err); |
|
202 |
|
203 break; |
|
204 } |
|
205 |
|
206 case ESetSimulatedFailure: |
|
207 { |
|
208 HBufC16* aFailType = HBufC16::NewLC(256); |
|
209 HBufC16* aPosition = HBufC16::NewLC(256); |
|
210 HBufC16* aFailFileName = HBufC16::NewLC(256); |
|
211 TPtr16 failType(aFailType->Des()); |
|
212 TPtr16 position(aPosition->Des()); |
|
213 TPtr16 failFileName(aFailFileName->Des()); |
|
214 |
|
215 aMessage.ReadL(0, failType); |
|
216 aMessage.ReadL(1, position); |
|
217 aMessage.ReadL(2, failFileName); |
|
218 RDebug::Print(_L("ServiceL ESetSimulatedFailure %S %S %S"), &aFailType, &aPosition, &aFailFileName); |
|
219 TRAPD(err, iIntegrityServices->SetSimulatedFailure(failType, position, failFileName)); |
|
220 aMessage.Complete(err); |
|
221 CleanupStack::PopAndDestroy(3, aFailType); |
|
222 break; |
|
223 } |
|
224 case ECreateNewTestFile: |
|
225 { |
|
226 RDebug::Print(_L("ServiceL ECreateNewTestFile")); |
|
227 HBufC16* fileName = HBufC16::NewLC(aMessage.GetDesLength(0)); |
|
228 TPtr16 ptr(fileName->Des()); |
|
229 aMessage.Read(0, ptr); |
|
230 |
|
231 TRAPD(err, iIntegrityServices->CreateNewTestFileL(*fileName)); |
|
232 |
|
233 aMessage.Complete(err); |
|
234 CleanupStack::PopAndDestroy(fileName); |
|
235 break; |
|
236 } |
|
237 case ECreateTempTestFile: |
|
238 { |
|
239 RDebug::Print(_L("ServiceL ECreateTempTestFile")); |
|
240 HBufC16* fileName = HBufC16::NewLC(aMessage.GetDesLength(0)); |
|
241 TPtr16 ptr(fileName->Des()); |
|
242 aMessage.Read(0, ptr); |
|
243 |
|
244 TRAPD(err, iIntegrityServices->CreateTempTestFileL(*fileName)); |
|
245 |
|
246 aMessage.Complete(err); |
|
247 CleanupStack::PopAndDestroy(fileName); |
|
248 break; |
|
249 } |
|
250 default: |
|
251 { |
|
252 PanicClient(aMessage, Swi::Test::EPanicIntegrityServicesServerIllegalFunction); |
|
253 break; |
|
254 } |
|
255 } |
|
256 } |
|
257 |
|
258 void CIntegrityServicesSession::ServiceError(const RMessage2& aMessage, TInt aError) |
|
259 { |
|
260 if (aError==KErrBadDescriptor) |
|
261 { |
|
262 PanicClient(aMessage, Swi::Test::EPanicIntegrityServicesServerIllegalFunction); |
|
263 } |
|
264 CSession2::ServiceError(aMessage, aError); |
|
265 } |
|
266 |
|
267 ///// |
|
268 ///// CShutdownTimer |
|
269 ///// |
|
270 inline CShutdownTimer::CShutdownTimer() : CTimer(-1) |
|
271 { |
|
272 CActiveScheduler::Add(this); |
|
273 } |
|
274 |
|
275 inline void CShutdownTimer::ConstructL() |
|
276 { |
|
277 CTimer::ConstructL(); |
|
278 } |
|
279 |
|
280 inline void CShutdownTimer::Start() |
|
281 { |
|
282 After(KShutdownDelay); |
|
283 } |
|
284 |
|
285 CShutdownTimer* CShutdownTimer::NewL() |
|
286 { |
|
287 CShutdownTimer* self = new(ELeave) CShutdownTimer(); |
|
288 CleanupStack::PushL(self); |
|
289 self->ConstructL(); |
|
290 CleanupStack::Pop(self); |
|
291 return self; |
|
292 } |
|
293 |
|
294 // Initiate server exit when the timer expires |
|
295 void CShutdownTimer::RunL() |
|
296 { |
|
297 CActiveScheduler::Stop(); |
|
298 } |