author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:55:16 +0300 | |
branch | RCL_3 |
changeset 118 | 8baec10861af |
parent 114 | a5a39a295112 |
child 130 | 67f2ed48ad91 |
permissions | -rw-r--r-- |
114 | 1 |
/* |
2 |
* Copyright (c) 2008 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: |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// System include files |
|
19 |
||
20 |
// User include files |
|
21 |
#include "ccsrv.h" |
|
22 |
#include "ccsrvsession.h" |
|
23 |
#include "ccresource.h" |
|
24 |
#include "ccsrvapi.h" |
|
25 |
||
26 |
||
27 |
// Local constants |
|
28 |
||
29 |
// Home screen content control server name |
|
30 |
_LIT( KCcSrvName,"ccserver" ); |
|
31 |
||
32 |
// Home screen content control server policy |
|
33 |
//Total number of ranges |
|
34 |
const TUint KCcRangeCount = 2; |
|
35 |
||
36 |
//Definition of the ranges of IPC numbers |
|
37 |
const TInt KCcRanges[KCcRangeCount] = |
|
38 |
{ |
|
39 |
ECcIPCFunctionBase, |
|
40 |
ECcNotSupported |
|
41 |
}; |
|
42 |
||
43 |
// Policy actions for each of the above ranges |
|
44 |
const TUint8 KCcPolicyAction[KCcRangeCount] = |
|
45 |
{ |
|
46 |
0, |
|
47 |
CPolicyServer::ENotSupported |
|
48 |
}; |
|
49 |
||
50 |
// Requested capabilities |
|
51 |
const CPolicyServer::TPolicyElement KCcCapability[] = |
|
52 |
{ |
|
53 |
{_INIT_SECURITY_POLICY_C2( ECapabilityReadDeviceData, ECapabilityWriteDeviceData ), CPolicyServer::EFailClient} |
|
54 |
}; |
|
55 |
||
56 |
const CPolicyServer::TPolicy KCcPolicy = |
|
57 |
{ |
|
58 |
0, |
|
59 |
KCcRangeCount, |
|
60 |
KCcRanges, |
|
61 |
KCcPolicyAction, |
|
62 |
KCcCapability |
|
63 |
}; |
|
64 |
||
65 |
// ----------------------------------------------------------------------------- |
|
66 |
// RunServerL() |
|
67 |
// ----------------------------------------------------------------------------- |
|
68 |
// |
|
69 |
static void RunServerL() |
|
70 |
{ |
|
71 |
User::LeaveIfError(User::RenameThread(KCcSrvName)); |
|
72 |
CActiveScheduler* s=new(ELeave) CActiveScheduler; |
|
73 |
CleanupStack::PushL(s); |
|
74 |
CActiveScheduler::Install(s); |
|
75 |
CCcSrv::NewLC(); |
|
76 |
RProcess::Rendezvous(KErrNone); |
|
77 |
CActiveScheduler::Start(); |
|
78 |
CleanupStack::PopAndDestroy( 2, s ); |
|
79 |
} |
|
80 |
||
81 |
// ----------------------------------------------------------------------------- |
|
82 |
// E32Main |
|
83 |
// Server process entry-point |
|
84 |
// ----------------------------------------------------------------------------- |
|
85 |
// |
|
86 |
TInt E32Main() |
|
87 |
{ |
|
88 |
__UHEAP_MARK; |
|
89 |
CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
90 |
TInt r=KErrNoMemory; |
|
91 |
if (cleanup) |
|
92 |
{ |
|
93 |
TRAP(r,RunServerL()); |
|
94 |
delete cleanup; |
|
95 |
} |
|
96 |
__UHEAP_MARKEND; |
|
97 |
return r; |
|
98 |
} |
|
99 |
||
100 |
// ======== MEMBER FUNCTIONS ======== |
|
101 |
||
102 |
// ----------------------------------------------------------------------------- |
|
103 |
// CCcSrv::NewLC |
|
104 |
// ----------------------------------------------------------------------------- |
|
105 |
// |
|
106 |
CServer2* CCcSrv::NewLC() |
|
107 |
{ |
|
108 |
CCcSrv* self=new ( ELeave ) CCcSrv; |
|
109 |
CleanupStack::PushL( self ); |
|
110 |
self->ConstructL(); |
|
111 |
return self; |
|
112 |
} |
|
113 |
||
114 |
// ----------------------------------------------------------------------- |
|
115 |
// CCcSrv::ConstructL() |
|
116 |
// ----------------------------------------------------------------------- |
|
117 |
// |
|
118 |
void CCcSrv::ConstructL() |
|
119 |
{ |
|
120 |
StartL( KCcSrvName ); |
|
121 |
} |
|
122 |
||
123 |
// ----------------------------------------------------------------------- |
|
124 |
// CCcSrv::CCcSrv() |
|
125 |
// ----------------------------------------------------------------------- |
|
126 |
// |
|
127 |
CCcSrv::CCcSrv() |
|
128 |
:CPolicyServer( 0,KCcPolicy,ESharableSessions ) |
|
129 |
,iLastSessionId( 0 ) |
|
130 |
{ |
|
131 |
} |
|
132 |
||
133 |
// ----------------------------------------------------------------------- |
|
134 |
// CCcSrv::~CCcSrv() |
|
135 |
// ----------------------------------------------------------------------- |
|
136 |
// |
|
137 |
CCcSrv::~CCcSrv() |
|
138 |
{ |
|
139 |
iSessions.Close(); |
|
140 |
iProviders.Close(); |
|
141 |
iObservers.Close(); |
|
142 |
} |
|
143 |
||
144 |
// ----------------------------------------------------------------------------- |
|
145 |
// CCcSrv::NewSessionL |
|
146 |
// ----------------------------------------------------------------------------- |
|
147 |
// |
|
148 |
CSession2* CCcSrv::NewSessionL( |
|
149 |
const TVersion&, |
|
150 |
const RMessage2& /* aMessage */ ) const |
|
151 |
{ |
|
152 |
return new ( ELeave ) CCcSrvSession(); |
|
153 |
} |
|
154 |
||
155 |
// ----------------------------------------------------------------------------- |
|
156 |
// CCcSrv::AddSessionL |
|
157 |
// ----------------------------------------------------------------------------- |
|
158 |
// |
|
159 |
void CCcSrv::AddSessionL( CCcSrvSession* aSession ) |
|
160 |
{ |
|
161 |
// Find next available session id |
|
162 |
while( ETrue ) |
|
163 |
{ |
|
164 |
iLastSessionId = iLastSessionId + 1; |
|
165 |
TBool found( EFalse ); |
|
166 |
for ( TUint32 i = 0; i < iSessions.Count() && !found; i++ ) |
|
167 |
{ |
|
168 |
if ( iSessions[ i ]->Id() == iLastSessionId ) |
|
169 |
{ |
|
170 |
found = ETrue; |
|
171 |
} |
|
172 |
} |
|
173 |
if ( !found ) |
|
174 |
{ |
|
175 |
break; |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
aSession->SetId( iLastSessionId ); |
|
180 |
iSessions.AppendL( aSession ); |
|
181 |
} |
|
182 |
||
183 |
// ----------------------------------------------------------------------------- |
|
184 |
// CCcSrv::DropSession |
|
185 |
// ----------------------------------------------------------------------------- |
|
186 |
// |
|
187 |
void CCcSrv::DropSession( CCcSrvSession* aSession ) |
|
188 |
{ |
|
189 |
// Remove possible provider |
|
190 |
for ( TUint32 i = 0; i < iProviders.Count(); i++ ) |
|
191 |
{ |
|
192 |
if ( iProviders[ i ].iSession->Id() == aSession->Id() ) |
|
193 |
{ |
|
194 |
iProviders.Remove( i ); |
|
195 |
break; |
|
196 |
} |
|
197 |
} |
|
198 |
// Unregister possible observations and remove observer |
|
199 |
for ( TUint32 i = 0; i < iObservers.Count(); ) |
|
200 |
{ |
|
201 |
if ( iObservers[ i ].iObserver == aSession->Id() ) |
|
202 |
{ |
|
203 |
for ( TUint32 j = 0; j < iProviders.Count(); j++ ) |
|
204 |
{ |
|
205 |
if ( iObservers[ i ].iProviderId == iProviders[ j ].iId ) |
|
206 |
{ |
|
207 |
TRAP_IGNORE( iProviders[ j ].iSession-> |
|
208 |
UnregisterObserverSessionL( aSession->Id() ) ); |
|
209 |
} |
|
210 |
} |
|
211 |
iObservers.Remove( i ); |
|
212 |
} |
|
213 |
else |
|
214 |
{ |
|
215 |
// Get next observer |
|
216 |
i++; |
|
217 |
} |
|
218 |
} |
|
219 |
// Remove session |
|
220 |
for ( TUint32 i = 0; i < iSessions.Count(); i++ ) |
|
221 |
{ |
|
222 |
if ( iSessions[ i ]->Id() == aSession->Id() ) |
|
223 |
{ |
|
224 |
iSessions.Remove( i ); |
|
225 |
break; |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
if ( iSessions.Count() == 0 ) |
|
230 |
{ |
|
231 |
// Last session dropped -> stop server |
|
232 |
CActiveScheduler::Stop(); |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
// ----------------------------------------------------------------------------- |
|
237 |
// CCcSrv::RegisterProviderSessionL |
|
238 |
// ----------------------------------------------------------------------------- |
|
239 |
// |
|
240 |
void CCcSrv::RegisterProviderL( |
|
241 |
TUint32 aProvider, |
|
242 |
CCcSrvSession* aSession ) |
|
243 |
{ |
|
244 |
for ( TUint32 i = 0; i < iProviders.Count(); i++ ) |
|
245 |
{ |
|
246 |
if ( iProviders[ i ].iId == aProvider ) |
|
247 |
{ |
|
248 |
User::Leave( KErrAlreadyExists ); |
|
249 |
} |
|
250 |
} |
|
251 |
CCcSrv::TCcProvider provider; |
|
252 |
provider.iId = aProvider; |
|
253 |
provider.iSession = aSession; |
|
118
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
254 |
iProviders.AppendL( provider ); |
114 | 255 |
|
256 |
// Register possible active observers |
|
257 |
for ( TUint32 i = 0; i < iObservers.Count(); i++ ) |
|
258 |
{ |
|
259 |
if ( iObservers[ i ].iProviderId == aProvider ) |
|
260 |
{ |
|
261 |
provider.iSession->RegisterObserverSessionL( iObservers[ i ].iObserver ); |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
} |
|
266 |
||
267 |
// ----------------------------------------------------------------------------- |
|
268 |
// CCcSrv::RegisterObserverL |
|
269 |
// ----------------------------------------------------------------------------- |
|
270 |
// |
|
271 |
void CCcSrv::RegisterObserverL( |
|
272 |
TUint32 aProvider, |
|
273 |
CCcSrvSession* aSession ) |
|
274 |
{ |
|
275 |
for ( TUint32 i = 0; i < iProviders.Count(); i++ ) |
|
276 |
{ |
|
277 |
if ( iProviders[ i ].iId == aProvider ) |
|
278 |
{ |
|
279 |
iProviders[ i ].iSession->RegisterObserverSessionL( aSession->Id() ); |
|
280 |
break; |
|
281 |
} |
|
282 |
} |
|
283 |
CCcSrv::TCcObserver observer; |
|
284 |
observer.iProviderId = aProvider; |
|
285 |
observer.iObserver = aSession->Id(); |
|
118
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
286 |
iObservers.AppendL( observer ); |
114 | 287 |
} |
288 |
||
289 |
// ----------------------------------------------------------------------------- |
|
290 |
// CCcSrv::ResolveProviderAddressL |
|
291 |
// ----------------------------------------------------------------------------- |
|
292 |
// |
|
293 |
void CCcSrv::ResolveProviderAddressL( |
|
294 |
TUint32 aProvider, |
|
295 |
TUint32& aAddress ) |
|
296 |
{ |
|
297 |
TBool found( EFalse ); |
|
298 |
for ( TUint32 i = 0; i < iProviders.Count() && !found; i++ ) |
|
299 |
{ |
|
300 |
if ( iProviders[ i ].iId == aProvider ) |
|
301 |
{ |
|
302 |
aAddress = iProviders[ i ].iSession->Id(); |
|
303 |
found = ETrue; |
|
304 |
} |
|
305 |
} |
|
306 |
if ( !found ) |
|
307 |
{ |
|
308 |
User::Leave( KErrNotFound ); |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
// ----------------------------------------------------------------------------- |
|
313 |
// CCcSrv::GetTrId |
|
314 |
// ----------------------------------------------------------------------------- |
|
315 |
// |
|
316 |
TUint32 CCcSrv::GetTrId() |
|
317 |
{ |
|
318 |
iLastTrId++; |
|
319 |
return iLastTrId; |
|
320 |
} |
|
321 |
||
322 |
// ----------------------------------------------------------------------------- |
|
323 |
// CCcSrv::SendMsgL |
|
324 |
// ----------------------------------------------------------------------------- |
|
325 |
// |
|
326 |
void CCcSrv::SendMsgL( |
|
327 |
CCcSrvMsg& aMessage ) |
|
328 |
{ |
|
329 |
TBool found( EFalse ); |
|
330 |
for ( TUint32 i = 0; i < iSessions.Count() && !found; i++ ) |
|
331 |
{ |
|
332 |
if ( iSessions[ i ]->Id() == aMessage.Receiver() ) |
|
333 |
{ |
|
334 |
iSessions[ i ]->ReceiveMsgL( aMessage ); |
|
335 |
found = ETrue; |
|
336 |
} |
|
337 |
} |
|
338 |
if ( !found ) |
|
339 |
{ |
|
340 |
User::Leave( KErrNotFound ); |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
// End of file |