|
1 /* |
|
2 * Copyright (c) 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 "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: Implementation of policymanagement components |
|
15 * |
|
16 */ |
|
17 /* PolicyEngineClient.cpp |
|
18 */ |
|
19 |
|
20 #include <e32svr.h> |
|
21 #include <featmgr.h> |
|
22 #include <bldvariant.hrh> |
|
23 |
|
24 #include "CentRepToolClientServer.h" |
|
25 #include "CentRepToolClient.h" |
|
26 |
|
27 |
|
28 #include "debug.h" |
|
29 |
|
30 |
|
31 // Standard server startup code |
|
32 // |
|
33 static TInt StartServer() |
|
34 { |
|
35 RDEBUG("CentRepToolServer: Starting server..."); |
|
36 |
|
37 const TUidType serverUid(KNullUid,KNullUid,KCentRepToolServerUid); |
|
38 |
|
39 // EPOC and EKA 2 is easy, we just create a new server process. Simultaneous |
|
40 // launching of two such processes should be detected when the second one |
|
41 // attempts to create the server object, failing with KErrAlreadyExists. |
|
42 RProcess server; |
|
43 //TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid); |
|
44 TInt r=server.Create(KCentRepToolServerImg,KNullDesC); |
|
45 |
|
46 if (r!=KErrNone) |
|
47 { |
|
48 RDEBUG_2("CenrRepToolClient: server start failed %d",r); |
|
49 return r; |
|
50 } |
|
51 TRequestStatus stat; |
|
52 server.Rendezvous(stat); |
|
53 if (stat!=KRequestPending) |
|
54 server.Kill(0); // abort startup |
|
55 else |
|
56 server.Resume(); // logon OK - start the server |
|
57 RDEBUG("CentRepToolClient: Started"); |
|
58 User::WaitForRequest(stat); // wait for start or death |
|
59 // we can't use the 'exit reason' if the server panicked as this |
|
60 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
61 // from KErrNone |
|
62 r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
63 server.Close(); |
|
64 return r; |
|
65 } |
|
66 |
|
67 |
|
68 // This is the standard retry pattern for server connection |
|
69 EXPORT_C TInt RCentRepTool::Connect() |
|
70 { |
|
71 TRAPD( err, FeatureManager::InitializeLibL() ); |
|
72 if( err != KErrNone ) |
|
73 { |
|
74 return err; |
|
75 } |
|
76 |
|
77 TBool iSupported = FeatureManager::FeatureSupported( KFeatureIdSapPolicyManagement); |
|
78 FeatureManager::UnInitializeLib(); |
|
79 |
|
80 if( !iSupported ) |
|
81 { |
|
82 return KErrNotSupported; |
|
83 } |
|
84 |
|
85 TInt retry=2; |
|
86 for (;;) |
|
87 { |
|
88 TInt r=CreateSession(KCentRepToolServerName,TVersion(0,0,0),1); |
|
89 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
90 return r; |
|
91 if (--retry==0) |
|
92 return r; |
|
93 r=StartServer(); |
|
94 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
95 return r; |
|
96 } |
|
97 } |
|
98 |
|
99 EXPORT_C void RCentRepTool::Close() |
|
100 { |
|
101 RSessionBase::Close(); //basecall |
|
102 } |
|
103 |
|
104 EXPORT_C TInt RCentRepTool::CheckCommitState() |
|
105 { |
|
106 return SendReceive( ECheckCommitState, TIpcArgs()); |
|
107 } |
|
108 |
|
109 EXPORT_C TInt RCentRepTool::PerformRFS() |
|
110 { |
|
111 return SendReceive( EPerformCentRepToolRFS); |
|
112 } |
|
113 |
|
114 |
|
115 EXPORT_C RSettingManagement::RSettingManagement() |
|
116 : iConnected( EFalse) |
|
117 { |
|
118 } |
|
119 |
|
120 EXPORT_C TInt RSettingManagement::Open( TUid aRepositoryId, RCentRepTool &aServer) |
|
121 { |
|
122 TPckg<TUid> uidPack( aRepositoryId); |
|
123 TInt err = CreateSubSession( aServer, ECreateRepositorySubSession, TIpcArgs( &uidPack, NULL)); |
|
124 |
|
125 if ( err == KErrNone ) |
|
126 { |
|
127 iConnected = ETrue; |
|
128 } |
|
129 |
|
130 return err; |
|
131 } |
|
132 |
|
133 EXPORT_C void RSettingManagement::Close() |
|
134 { |
|
135 RSubSessionBase::CloseSubSession(ECloseRepositorySubSession); |
|
136 } |
|
137 |
|
138 EXPORT_C void RSettingManagement::InitSession( TRequestStatus& iRequestStatus) |
|
139 { |
|
140 SendReceive( EInitRepositorySession, iRequestStatus); |
|
141 } |
|
142 |
|
143 |
|
144 |
|
145 EXPORT_C TInt RSettingManagement::SetSIDWRForSetting( TUint32 aSettingId, TUid aSecurityId) |
|
146 { |
|
147 TPckg<TUint32> settingPack( aSettingId); |
|
148 TPckg<TUid> securityIdPack( aSecurityId); |
|
149 return SendReceive( ESetSIDWRForSetting, TIpcArgs(&settingPack, &securityIdPack)); |
|
150 } |
|
151 |
|
152 EXPORT_C TInt RSettingManagement::SetSIDWRForMask( TUint32 aCompareValue, TUint32 aMask, TUid aSecurityId) |
|
153 { |
|
154 TPckg<TUint32> comparePack( aCompareValue); |
|
155 TPckg<TUint32> maskPack( aMask); |
|
156 TPckg<TUid> securityIdPack( aSecurityId); |
|
157 return SendReceive( ESetSIDWRForMask, TIpcArgs(&comparePack, &maskPack, &securityIdPack)); |
|
158 } |
|
159 |
|
160 EXPORT_C TInt RSettingManagement::RestoreSetting( TUint32 aSettingId) |
|
161 { |
|
162 TPckg<TUint32> settingPack( aSettingId); |
|
163 return SendReceive( ERestoreSetting, TIpcArgs(&settingPack)); |
|
164 } |
|
165 |
|
166 EXPORT_C TInt RSettingManagement::RestoreMask( TUint32 aCompareValue, TUint32 aMask) |
|
167 { |
|
168 TPckg<TUint32> comparePack( aCompareValue); |
|
169 TPckg<TUint32> maskPack( aMask);; |
|
170 return SendReceive( ERestoreMask, TIpcArgs(&comparePack, &maskPack)); |
|
171 } |
|
172 |
|
173 EXPORT_C TInt RSettingManagement::AddSIDWRForDefaults( TUid aSecurityId) |
|
174 { |
|
175 TPckg<TUid> securityIdPack( aSecurityId); |
|
176 return SendReceive( EAddSIDWRForDefaults, TIpcArgs(&securityIdPack)); |
|
177 } |
|
178 |
|
179 EXPORT_C TInt RSettingManagement::RestoreDefaults() |
|
180 { |
|
181 return SendReceive( ERestoreDefaults, TIpcArgs()); |
|
182 } |
|
183 |
|
184 EXPORT_C TInt RSettingManagement::Flush() |
|
185 { |
|
186 return SendReceive( EFlushRepository, TIpcArgs()); |
|
187 } |
|
188 |
|
189 |
|
190 EXPORT_C TInt RSettingManagement::SetSIDWRForRange( TUint32 aRangeStart, TUint32 aRangeEnd, TUid aSecurityId) |
|
191 { |
|
192 TPckg<TUint32> rangeStartPack( aRangeStart); |
|
193 TPckg<TUint32> rangeEndPack( aRangeEnd); |
|
194 TPckg<TUid> securityIdPack( aSecurityId); |
|
195 return SendReceive( ESetSIDWRForRange, TIpcArgs(& rangeStartPack, &rangeEndPack, &securityIdPack)); |
|
196 } |
|
197 |
|
198 |
|
199 EXPORT_C TInt RSettingManagement::RestoreRange( TUint32 aRangeStart, TUint32 aRangeEnd) |
|
200 { |
|
201 TPckg<TUint32> rangeStartPack( aRangeStart); |
|
202 TPckg<TUint32> rangeEndPack( aRangeEnd); |
|
203 return SendReceive( ERestoreRange, TIpcArgs(& rangeStartPack, &rangeEndPack)); |
|
204 } |
|
205 |
|
206 |
|
207 EXPORT_C TInt RSettingManagement::RemoveBackupFlagForMask( TUint32 aCompareValue, TUint32 aMask) |
|
208 { |
|
209 TPckg<TUint32> comparePack( aCompareValue); |
|
210 TPckg<TUint32> maskPack( aMask);; |
|
211 return SendReceive( ERemoveBackupFlagForMask, TIpcArgs(&comparePack, &maskPack)); |
|
212 } |
|
213 |
|
214 EXPORT_C TInt RSettingManagement::RestoreBackupFlagForMask( TUint32 aCompareValue, TUint32 aMask) |
|
215 { |
|
216 TPckg<TUint32> comparePack( aCompareValue); |
|
217 TPckg<TUint32> maskPack( aMask);; |
|
218 return SendReceive( ERestoreBackupFlagForMask, TIpcArgs(&comparePack, &maskPack)); |
|
219 } |
|
220 |
|
221 EXPORT_C TInt RSettingManagement::RemoveBackupFlagForRange( TUint32 aRangeStart, TUint32 aRangeEnd) |
|
222 { |
|
223 TPckg<TUint32> rangeStartPack( aRangeStart); |
|
224 TPckg<TUint32> rangeEndPack( aRangeEnd); |
|
225 return SendReceive( ERemoveBackupFlagForRange, TIpcArgs( &rangeStartPack, &rangeEndPack)); |
|
226 } |
|
227 |
|
228 EXPORT_C TInt RSettingManagement::RestoreBackupFlagForRange( TUint32 aRangeStart, TUint32 aRangeEnd) |
|
229 { |
|
230 TPckg<TUint32> rangeStartPack( aRangeStart); |
|
231 TPckg<TUint32> rangeEndPack( aRangeEnd); |
|
232 return SendReceive( ERestoreBackupFlagForRange, TIpcArgs( &rangeStartPack, &rangeEndPack)); |
|
233 } |
|
234 |
|
235 |
|
236 EXPORT_C TInt RSettingManagement::RemoveBackupFlagForDefaults() |
|
237 { |
|
238 return SendReceive( ERemoveBackupFlagForDefaults, TIpcArgs()); |
|
239 } |
|
240 |
|
241 EXPORT_C TInt RSettingManagement::RestoreBackupFlagForDefaults() |
|
242 { |
|
243 return SendReceive( ERestoreBackupFlagForDefaults, TIpcArgs()); |
|
244 } |
|
245 |
|
246 EXPORT_C TInt RAccessCheck::Open( TUid aRepositoryId, RCentRepTool &aServer) |
|
247 { |
|
248 TPckg<TUid> uidPack( aRepositoryId); |
|
249 TInt err = CreateSubSession( aServer, ECreateCheckAccessSession, TIpcArgs( &uidPack, NULL)); |
|
250 |
|
251 return err; |
|
252 } |
|
253 |
|
254 EXPORT_C void RAccessCheck::Close() |
|
255 { |
|
256 RSubSessionBase::CloseSubSession(ECloseCheckAcceessSession); |
|
257 } |
|
258 |
|
259 |
|
260 EXPORT_C TInt RAccessCheck::CheckAccess( TUint32 aSettingId, TAccessType aAccessType, TBool& aAccessValue) |
|
261 { |
|
262 TPckg<TUint32> idPack( aSettingId); |
|
263 TPckg<TAccessType> atPack( aAccessType); |
|
264 TPckg<TBool> boolPack( aAccessValue); |
|
265 |
|
266 return SendReceive( ECheckAccess, TIpcArgs( &idPack, &atPack, &boolPack)); |
|
267 } |
|
268 |
|
269 |