|
1 /* |
|
2 * Copyright (c) 2005-2006 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: javaregserversession implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "javaregserversession.h" |
|
20 #include "javaregdef.h" |
|
21 #include "javaregproperty.h" |
|
22 #include "javapropertyarray.h" |
|
23 #include "javareguidarrayconv.h" |
|
24 #include "javaregserver.h" |
|
25 #include "logger.h" |
|
26 |
|
27 using namespace Java::Manager::Registry; |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 CJavaRegServerSession::CJavaRegServerSession() : |
|
33 iBackupSession(EFalse), |
|
34 iLegacy(EFalse) |
|
35 { |
|
36 } |
|
37 |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // Destructor |
|
41 // --------------------------------------------------------------------------- |
|
42 CJavaRegServerSession::~CJavaRegServerSession() |
|
43 { |
|
44 // if it was a backup session move registry back to NoBackup state |
|
45 if (iBackupSession) |
|
46 { |
|
47 Server()->SetBackupState(ENoBackup); |
|
48 } |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // Returns the iLegacy member |
|
53 // --------------------------------------------------------------------------- |
|
54 TBool CJavaRegServerSession::IsLegacy() const |
|
55 { |
|
56 return iLegacy; |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Returns server object |
|
62 // --------------------------------------------------------------------------- |
|
63 CJavaRegServer* CJavaRegServerSession::Server() const |
|
64 { |
|
65 return const_cast< CJavaRegServer* >( |
|
66 static_cast< const CJavaRegServer* >(CSession2::Server())); |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // ServiceL |
|
72 // --------------------------------------------------------------------------- |
|
73 void CJavaRegServerSession::ServiceL(const RMessage2& aMessage) |
|
74 { |
|
75 TRAPD(err, DispatchMessageL(aMessage)); |
|
76 aMessage.Complete(err); |
|
77 } |
|
78 |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // DispatchMessageL |
|
82 // --------------------------------------------------------------------------- |
|
83 void CJavaRegServerSession::DispatchMessageL(const RMessage2& aMessage) |
|
84 { |
|
85 JELOG(EJavaStorage, "CJavaRegServerSession::DispatchMessageL()"); |
|
86 |
|
87 TInt function = aMessage.Function(); |
|
88 |
|
89 switch (function) |
|
90 { |
|
91 case EInitializeServerUseIntegr: |
|
92 InitializeServerUseIntegrL(aMessage); |
|
93 break; |
|
94 |
|
95 case EEntryExists: |
|
96 EntryExistsL(aMessage); |
|
97 break; |
|
98 |
|
99 case EGetEntryUids: |
|
100 GetEntryUidsL(aMessage); |
|
101 break; |
|
102 |
|
103 case EGetEntry: |
|
104 { |
|
105 GetEntryL(aMessage); |
|
106 break; |
|
107 } |
|
108 |
|
109 case EGetEntryFromAll: |
|
110 { |
|
111 GetEntryL(aMessage, ETrue); |
|
112 } |
|
113 break; |
|
114 |
|
115 case EFindEntries: |
|
116 FindEntriesL(aMessage); |
|
117 break; |
|
118 |
|
119 case EFindAllEntries: |
|
120 FindAllEntriesL(aMessage); |
|
121 break; |
|
122 |
|
123 case ESetBackupState: |
|
124 SetBackupState(aMessage); |
|
125 break; |
|
126 |
|
127 default: |
|
128 User::Leave(KErrNotSupported); |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // InitializeServerUseIntegrL |
|
134 // --------------------------------------------------------------------------- |
|
135 void CJavaRegServerSession::InitializeServerUseIntegrL( |
|
136 const RMessage2& aMessage) |
|
137 { |
|
138 JELOG(EJavaStorage, "CJavaRegServerSession::InitializeServerUseIntegrL()"); |
|
139 |
|
140 TBool useIntegrity = aMessage.Int0(); |
|
141 iLegacy = aMessage.Int1(); |
|
142 if (useIntegrity) |
|
143 { |
|
144 TTime currentTime; |
|
145 currentTime.UniversalTime(); |
|
146 TInt64 transactionId = currentTime.Int64(); |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // EntryExistsL |
|
153 // --------------------------------------------------------------------------- |
|
154 void CJavaRegServerSession::EntryExistsL(const RMessage2& aMessage) |
|
155 { |
|
156 JELOG(EJavaStorage, "CJavaRegServerSession::EntryExistsL()"); |
|
157 |
|
158 Server()->LeaveIfRestoringL(); |
|
159 |
|
160 // obtain uid |
|
161 TUid uid = UidFromMessageL(0, aMessage); |
|
162 |
|
163 // check if entry exists for uid |
|
164 TBool result = Server()->EntryExistsL(uid); |
|
165 |
|
166 // write back result |
|
167 TPckgBuf<TBool> resultBuf(result); |
|
168 aMessage.WriteL(1, resultBuf) ; |
|
169 } |
|
170 |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // GetEntryUidsL |
|
174 // --------------------------------------------------------------------------- |
|
175 void CJavaRegServerSession::GetEntryUidsL(const RMessage2& aMessage) |
|
176 { |
|
177 JELOG(EJavaStorage, "CJavaRegServerSession::GetEntryUidsL()"); |
|
178 |
|
179 Server()->LeaveIfRestoringL(); |
|
180 |
|
181 TInt drive = aMessage.Int2(); |
|
182 RArray<TUid> uids; |
|
183 CleanupClosePushL(uids); |
|
184 |
|
185 Server()->GetEntryUidsL(uids, drive); |
|
186 WriteBackUidArrayL(uids, aMessage) ; |
|
187 CleanupStack::PopAndDestroy(&uids); |
|
188 } |
|
189 |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // GetEntryL |
|
193 // --------------------------------------------------------------------------- |
|
194 void CJavaRegServerSession::GetEntryL(const RMessage2& aMessage, |
|
195 TBool aAllEntries) |
|
196 { |
|
197 JELOG(EJavaStorage, "CJavaRegServerSession::GetEntryL()"); |
|
198 |
|
199 Server()->LeaveIfRestoringL(); |
|
200 |
|
201 // read uid |
|
202 TUid uid = UidFromMessageL(2, aMessage); |
|
203 |
|
204 // get property |
|
205 CJavaPropertyArray* props = NULL; |
|
206 Server()->GetEntryL(uid, props, aAllEntries); |
|
207 |
|
208 TInt neededLength = 0; |
|
209 |
|
210 // if there is property write it back |
|
211 if (props) |
|
212 { |
|
213 CleanupStack::PushL(props); |
|
214 TInt allocatedLength = aMessage.GetDesMaxLengthL(0); |
|
215 neededLength = props->Size(); |
|
216 |
|
217 if (allocatedLength >= neededLength) |
|
218 { |
|
219 HBufC8* propBuffer = props->SerializedPropertiesL(); |
|
220 CleanupStack::PushL(propBuffer); |
|
221 aMessage.WriteL(0, propBuffer->Des()); |
|
222 CleanupStack::PopAndDestroy(propBuffer); |
|
223 } |
|
224 else |
|
225 { |
|
226 WLOG(EJavaStorage, |
|
227 "Allocated length is to small. Send back the needed length."); |
|
228 } |
|
229 |
|
230 // Delete because not cached. |
|
231 props->DeleteProperties(); |
|
232 CleanupStack::PopAndDestroy(props); |
|
233 } |
|
234 |
|
235 // write back needed length |
|
236 TPckgBuf<TInt> lengthPckg(neededLength); |
|
237 aMessage.WriteL(1, lengthPckg); |
|
238 } |
|
239 |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // FindEntries |
|
243 // --------------------------------------------------------------------------- |
|
244 void CJavaRegServerSession::FindEntriesL(const RMessage2& aMessage) |
|
245 { |
|
246 JELOG(EJavaStorage, "CJavaRegServerSession::FindEntriesL()"); |
|
247 |
|
248 Server()->LeaveIfRestoringL(); |
|
249 |
|
250 RArray<TUid> uids; |
|
251 CleanupClosePushL(uids); |
|
252 |
|
253 // read properties |
|
254 CJavaPropertyArray* props = PropertiesFromMessageL(2, aMessage); |
|
255 CleanupStack::PushL(props); |
|
256 |
|
257 Server()->FindEntriesL(*props, uids); |
|
258 |
|
259 CleanupStack::PopAndDestroy(props); |
|
260 |
|
261 WriteBackUidArrayL(uids, aMessage) ; |
|
262 |
|
263 CleanupStack::PopAndDestroy(&uids); |
|
264 } |
|
265 |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // FindAllEntries |
|
269 // --------------------------------------------------------------------------- |
|
270 void CJavaRegServerSession::FindAllEntriesL(const RMessage2& aMessage) |
|
271 { |
|
272 JELOG(EJavaStorage, "CJavaRegServerSession::FindEntriesL()"); |
|
273 |
|
274 Server()->LeaveIfRestoringL(); |
|
275 |
|
276 RArray<TUid> uids; |
|
277 CleanupClosePushL(uids); |
|
278 |
|
279 // read properties |
|
280 CJavaPropertyArray* props = PropertiesFromMessageL(2, aMessage); |
|
281 CleanupStack::PushL(props); |
|
282 |
|
283 Server()->FindAllEntriesL(*props, uids); |
|
284 |
|
285 CleanupStack::PopAndDestroy(props); |
|
286 |
|
287 WriteBackUidArrayL(uids, aMessage) ; |
|
288 |
|
289 CleanupStack::PopAndDestroy(&uids); |
|
290 } |
|
291 |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // SetBackupState |
|
295 // --------------------------------------------------------------------------- |
|
296 void CJavaRegServerSession::SetBackupState(const RMessage2& aMessage) |
|
297 { |
|
298 JELOG(EJavaStorage, "CJavaRegServerSession::SetBackupState()"); |
|
299 |
|
300 TBackupState state = (TBackupState) aMessage.Int0(); |
|
301 Server()->SetBackupState(state); |
|
302 iBackupSession = ETrue; |
|
303 } |
|
304 |
|
305 |
|
306 // --------------------------------------------------------------------------- |
|
307 // UidFromMessageL |
|
308 // --------------------------------------------------------------------------- |
|
309 TUid CJavaRegServerSession::UidFromMessageL(TInt aIndex, |
|
310 const RMessage2& aMessage) |
|
311 { |
|
312 TUid uid = TUid::Uid(0); |
|
313 TPckg<TUid> uidPack(uid); |
|
314 aMessage.ReadL(aIndex, uidPack); |
|
315 return uid; |
|
316 } |
|
317 |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // PropertiesFromMessageL |
|
321 // --------------------------------------------------------------------------- |
|
322 CJavaPropertyArray* CJavaRegServerSession::PropertiesFromMessageL( |
|
323 TInt aIndex, |
|
324 const RMessage2& aMessage) |
|
325 { |
|
326 TInt length = aMessage.GetDesLengthL(aIndex); |
|
327 HBufC8* propBuffer = HBufC8::NewLC(length); |
|
328 TPtr8 ptr = propBuffer->Des(); |
|
329 aMessage.ReadL(aIndex, ptr); |
|
330 CJavaPropertyArray* props = CJavaPropertyArray::NewL(propBuffer); |
|
331 CleanupStack::PopAndDestroy(propBuffer); |
|
332 |
|
333 return props; |
|
334 } |
|
335 |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // WriteBackUidArrayL |
|
339 // --------------------------------------------------------------------------- |
|
340 void CJavaRegServerSession::WriteBackUidArrayL(RArray<TUid>& aUids, |
|
341 const RMessage2& aMessage) |
|
342 { |
|
343 HBufC16* uidBuffer = NULL; |
|
344 JavaRegUidArrayConverter::StoreTUidsL(aUids, uidBuffer); |
|
345 CleanupStack::PushL(uidBuffer); |
|
346 |
|
347 TInt allocatedLength = aMessage.GetDesMaxLengthL(0); |
|
348 TInt neededLength = uidBuffer->Length(); |
|
349 |
|
350 if (allocatedLength >= neededLength) |
|
351 { |
|
352 aMessage.WriteL(0, uidBuffer->Des()); |
|
353 } |
|
354 else |
|
355 { |
|
356 WLOG(EJavaStorage, |
|
357 "Allocated length is to small. Send back the needed length."); |
|
358 } |
|
359 |
|
360 CleanupStack::PopAndDestroy(uidBuffer); |
|
361 |
|
362 // write back needed length |
|
363 TPckgBuf<TInt> lengthPckg(neededLength); |
|
364 aMessage.WriteL(1, lengthPckg); |
|
365 } |