|
1 /* |
|
2 * Copyright (c) 2008-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 * SisRegistryAccess - server and implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @test |
|
23 @internalComponent |
|
24 */ |
|
25 |
|
26 #include <usif/sts/sts.h> |
|
27 #include "sisregistryaccess_server_session.h" |
|
28 #include "sisregistrypackage.h" |
|
29 #include "sisregistryaccess_server_session.h" |
|
30 #include "sisregistryaccess_common.h" |
|
31 #include "dessisdataprovider.h" |
|
32 #include "siscontroller.h" |
|
33 #include "application.h" |
|
34 #include "userselections.h" |
|
35 |
|
36 /////////////////////// Utility functions ////////////////////////////// |
|
37 void StartTimer(TTime& aTimer) |
|
38 { |
|
39 aTimer.HomeTime(); |
|
40 } |
|
41 |
|
42 TInt StopTimer(TTime aStartTimer) |
|
43 { |
|
44 TTime endTime; |
|
45 endTime.HomeTime(); |
|
46 |
|
47 TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(aStartTimer); |
|
48 TInt actualDuration = I64INT(duration.Int64())/1000; // in millisecond |
|
49 return actualDuration; |
|
50 } |
|
51 |
|
52 //////////////////////// Server implementation ///////////////////////// |
|
53 |
|
54 CServer2* CSisRegistryAccessServer::NewLC() |
|
55 { |
|
56 CSisRegistryAccessServer* self=new(ELeave) CSisRegistryAccessServer; |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 CSisRegistryAccessServer::CSisRegistryAccessServer() |
|
63 :CServer2(0, ESharableSessions) |
|
64 { |
|
65 } |
|
66 |
|
67 CSisRegistryAccessServer::~CSisRegistryAccessServer() |
|
68 { |
|
69 iRegistry.Close(); |
|
70 } |
|
71 |
|
72 void CSisRegistryAccessServer::ConstructL() |
|
73 { |
|
74 StartL(KSisRegistryAccessServerName); |
|
75 User::LeaveIfError(iRegistry.Connect()); |
|
76 } |
|
77 |
|
78 CSession2* CSisRegistryAccessServer::NewSessionL(const TVersion&, const RMessage2&) const |
|
79 { |
|
80 return new(ELeave) CSisRegistryAccessSession(); |
|
81 } |
|
82 |
|
83 void CSisRegistryAccessServer::AddSession() |
|
84 { |
|
85 ++iSessionCount; |
|
86 } |
|
87 |
|
88 void CSisRegistryAccessServer::DropSession() |
|
89 { |
|
90 --iSessionCount; |
|
91 if(!iSessionCount) |
|
92 CActiveScheduler::Stop(); |
|
93 } |
|
94 |
|
95 |
|
96 //////////////////////// Session implementation ///////////////////////// |
|
97 CSisRegistryAccessSession::CSisRegistryAccessSession() |
|
98 { |
|
99 } |
|
100 |
|
101 void CSisRegistryAccessSession::CreateL() |
|
102 { |
|
103 Server().AddSession(); |
|
104 } |
|
105 |
|
106 CSisRegistryAccessSession::~CSisRegistryAccessSession() |
|
107 { |
|
108 Server().DropSession(); |
|
109 } |
|
110 |
|
111 void CSisRegistryAccessSession::ServiceL(const RMessage2& aMessage) |
|
112 { |
|
113 // create transaction on SCR for mutable operations |
|
114 Server().RegistrySession().CreateTransactionL(); |
|
115 // SWI regsitry needs a transaction to cover updates to logs during package add/update/removal |
|
116 Usif::RStsSession stsSession; |
|
117 TInt64 transactionID = stsSession.CreateTransactionL(); |
|
118 CleanupClosePushL(stsSession); |
|
119 TInt err(0); |
|
120 |
|
121 TTime timer; |
|
122 StartTimer(timer); |
|
123 |
|
124 TSisRegistryAccessMessages f = static_cast<TSisRegistryAccessMessages>(aMessage.Function()); |
|
125 switch (f) |
|
126 { |
|
127 case EAddEntry: |
|
128 case EUpdateEntry: |
|
129 { |
|
130 TInt len = aMessage.GetDesLengthL(0); |
|
131 HBufC8 *controllerData = HBufC8::NewLC(len); |
|
132 TPtr8 ptrControllerData(controllerData->Des()); |
|
133 aMessage.ReadL(0, ptrControllerData); |
|
134 |
|
135 // create the controller |
|
136 Swi::CDesDataProvider *desProvider = Swi::CDesDataProvider::NewLC(ptrControllerData); |
|
137 Swi::Sis::CController *controller = Swi::Sis::CController::NewLC(*desProvider, Swi::Sis::EAssumeType); |
|
138 // setup the application |
|
139 Swi::CApplication *app = Swi::CApplication::NewLC(); |
|
140 app->SetInstall(*controller); |
|
141 // since the attributes chosen by the user don't have impact on the adding/updating entry tests, |
|
142 // they are set with the constant values. |
|
143 app->UserSelections().SetLanguage(ELangEnglish); |
|
144 app->UserSelections().SetDrive(2); |
|
145 |
|
146 if(EAddEntry == f) |
|
147 { |
|
148 TRAP(err, Server().RegistrySession().AddEntryL(*app, ptrControllerData, transactionID)); |
|
149 } |
|
150 else |
|
151 { |
|
152 TRAP(err, Server().RegistrySession().UpdateEntryL(*app, ptrControllerData, transactionID)); |
|
153 } |
|
154 CleanupStack::PopAndDestroy(4, controllerData); // controllerData, desProvider, controller, app |
|
155 break; |
|
156 } |
|
157 case EDeleteEntry: |
|
158 { |
|
159 // Get Uid and index |
|
160 // Augmentation index - argument 0 |
|
161 TInt packageIndex = aMessage.Int0(); |
|
162 |
|
163 // Uid (ipc argument 1) |
|
164 TUid uid; |
|
165 TPckg<TUid> packageUid(uid); |
|
166 aMessage.ReadL(1, packageUid); |
|
167 |
|
168 // Invoke SisRegistry server API using SisRegistryClient |
|
169 Swi::CSisRegistryPackage* package = Swi::CSisRegistryPackage::NewLC(uid, KNullDesC, KNullDesC); // For the delete API, the name and the vendor of the package are irrelevant |
|
170 package->SetIndex(packageIndex); |
|
171 TRAP(err, Server().RegistrySession().DeleteEntryL(*package, transactionID)); |
|
172 |
|
173 CleanupStack::PopAndDestroy(package); |
|
174 break; |
|
175 } |
|
176 default: |
|
177 { |
|
178 PanicClient(aMessage, EPanicIllegalFunction); |
|
179 break; |
|
180 } |
|
181 } |
|
182 |
|
183 stsSession.CommitL(); |
|
184 CleanupStack::PopAndDestroy(&stsSession); |
|
185 |
|
186 Server().RegistrySession().CommitTransactionL(); |
|
187 |
|
188 TPckg<TInt> timePckg(StopTimer(timer)); |
|
189 if(EDeleteEntry == f) |
|
190 aMessage.WriteL(2, timePckg); |
|
191 else |
|
192 aMessage.WriteL(1, timePckg); |
|
193 |
|
194 aMessage.Complete(err); |
|
195 } |
|
196 |
|
197 void CSisRegistryAccessSession::ServiceError(const RMessage2& aMessage, TInt aError) |
|
198 { |
|
199 if (aError == KErrBadDescriptor) |
|
200 PanicClient(aMessage, EPanicBadDescriptor); |
|
201 CSession2::ServiceError(aMessage,aError); |
|
202 } |
|
203 |
|
204 |
|
205 |