|
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( ECapabilityReadUserData, ECapabilityWriteUserData ), 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 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CCcSrv::NewSessionL |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 CSession2* CCcSrv::NewSessionL( |
|
148 const TVersion&, |
|
149 const RMessage2& /* aMessage */ ) const |
|
150 { |
|
151 return new ( ELeave ) CCcSrvSession(); |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CCcSrv::AddSessionL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CCcSrv::AddSessionL( CCcSrvSession* aSession ) |
|
159 { |
|
160 // Find next available session id |
|
161 while( ETrue ) |
|
162 { |
|
163 iLastSessionId = iLastSessionId + 1; |
|
164 TBool found( EFalse ); |
|
165 for ( TUint32 i = 0; i < iSessions.Count() && !found; i++ ) |
|
166 { |
|
167 if ( iSessions[ i ]->Id() == iLastSessionId ) |
|
168 { |
|
169 found = ETrue; |
|
170 } |
|
171 } |
|
172 if ( !found ) |
|
173 { |
|
174 break; |
|
175 } |
|
176 } |
|
177 |
|
178 aSession->SetId( iLastSessionId ); |
|
179 iSessions.AppendL( aSession ); |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CCcSrv::DropSession |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CCcSrv::DropSession( CCcSrvSession* aSession ) |
|
187 { |
|
188 for ( TUint32 i = 0; i < iSessions.Count(); i++ ) |
|
189 { |
|
190 if ( iSessions[ i ]->Id() == aSession->Id() ) |
|
191 { |
|
192 iSessions.Remove( i ); |
|
193 break; |
|
194 } |
|
195 } |
|
196 // Unregister possible observations |
|
197 for ( TUint32 i = 0; i < iProviders.Count(); i++ ) |
|
198 { |
|
199 TRAP_IGNORE( iProviders[ i ].iSession-> |
|
200 UnregisterObserverSessionL( aSession->Id() ) ); |
|
201 } |
|
202 |
|
203 // Remove possible provider |
|
204 for ( TUint32 i = 0; i < iProviders.Count(); i++ ) |
|
205 { |
|
206 if ( iProviders[ i ].iId == aSession->Id() ) |
|
207 { |
|
208 iProviders.Remove( i ); |
|
209 break; |
|
210 } |
|
211 } |
|
212 if ( iSessions.Count() == 0 ) |
|
213 { |
|
214 // Last session dropped -> stop server |
|
215 CActiveScheduler::Stop(); |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CCcSrv::RegisterProviderSessionL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CCcSrv::RegisterProviderL( |
|
224 TUint32 aProvider, |
|
225 CCcSrvSession* aSession ) |
|
226 { |
|
227 for ( TUint32 i = 0; i < iProviders.Count(); i++ ) |
|
228 { |
|
229 if ( iProviders[ i ].iId == aProvider ) |
|
230 { |
|
231 User::Leave( KErrAlreadyExists ); |
|
232 } |
|
233 } |
|
234 CCcSrv::TCcProvider provider; |
|
235 provider.iId = aProvider; |
|
236 provider.iSession = aSession; |
|
237 iProviders.Append( provider ); |
|
238 |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CCcSrv::RegisterObserverL |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 void CCcSrv::RegisterObserverL( |
|
246 TUint32 aProvider, |
|
247 CCcSrvSession* aSession ) |
|
248 { |
|
249 TBool found( EFalse ); |
|
250 for ( TUint32 i = 0; i < iProviders.Count() && !found; i++ ) |
|
251 { |
|
252 if ( iProviders[ i ].iId == aProvider ) |
|
253 { |
|
254 iProviders[ i ].iSession->RegisterObserverSessionL( aSession->Id() ); |
|
255 found = ETrue; |
|
256 } |
|
257 } |
|
258 if ( !found ) |
|
259 { |
|
260 User::Leave( KErrNotFound ); |
|
261 } |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CCcSrv::ResolveProviderAddressL |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 void CCcSrv::ResolveProviderAddressL( |
|
269 TUint32 aProvider, |
|
270 TUint32& aAddress ) |
|
271 { |
|
272 TBool found( EFalse ); |
|
273 for ( TUint32 i = 0; i < iProviders.Count() && !found; i++ ) |
|
274 { |
|
275 if ( iProviders[ i ].iId == aProvider ) |
|
276 { |
|
277 aAddress = iProviders[ i ].iSession->Id(); |
|
278 found = ETrue; |
|
279 } |
|
280 } |
|
281 if ( !found ) |
|
282 { |
|
283 User::Leave( KErrNotFound ); |
|
284 } |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CCcSrv::GetTrId |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 TUint32 CCcSrv::GetTrId() |
|
292 { |
|
293 iLastTrId++; |
|
294 return iLastTrId; |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CCcSrv::SendMsgL |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CCcSrv::SendMsgL( |
|
302 TUint32 aSender, |
|
303 TUint32 aReceiver, |
|
304 CCcSrvMsg& aMessage ) |
|
305 { |
|
306 TBool found( EFalse ); |
|
307 for ( TUint32 i = 0; i < iSessions.Count() && !found; i++ ) |
|
308 { |
|
309 if ( iSessions[ i ]->Id() == aReceiver ) |
|
310 { |
|
311 iSessions[ i ]->ReceiveMsgL( aSender, aReceiver, aMessage ); |
|
312 found = ETrue; |
|
313 } |
|
314 } |
|
315 if ( !found ) |
|
316 { |
|
317 User::Leave( KErrNotFound ); |
|
318 } |
|
319 } |
|
320 |
|
321 // End of file |