|
1 /* |
|
2 * Copyright (c) 2002-2007 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: CFServer class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32svr.h> |
|
20 #include <ecom/ecom.h> |
|
21 |
|
22 #include "CFServer.h" |
|
23 #include "CFEngine.h" |
|
24 #include "cftrace.h" |
|
25 #include "cfutils.h" |
|
26 #include "cfcommon.h" |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 /** |
|
31 * Enable file trace macros |
|
32 */ |
|
33 #ifdef TRACE_INTO_FILE |
|
34 |
|
35 #include <f32file.h> |
|
36 |
|
37 /** |
|
38 * Enables logging by creating the log folder. |
|
39 */ |
|
40 LOCAL_C void EnableLog() |
|
41 { |
|
42 RFs fs; |
|
43 if( fs.Connect() == KErrNone ) |
|
44 { |
|
45 fs.MkDirAll( KFullPath ); |
|
46 fs.Close(); |
|
47 } |
|
48 } |
|
49 #define ENABLE_LOG\ |
|
50 {\ |
|
51 EnableLog();\ |
|
52 } |
|
53 |
|
54 #else//TRACE_INTO_FILE not defined |
|
55 |
|
56 #define ENABLE_LOG |
|
57 |
|
58 #endif//TRACE_INTO_FILE |
|
59 |
|
60 // MEMBER FUNCTIONS |
|
61 |
|
62 CCFServer* CCFServer::NewL() |
|
63 { |
|
64 FUNC_LOG; |
|
65 |
|
66 CCFServer* self = CCFServer::NewLC(); |
|
67 CleanupStack::Pop( self ); |
|
68 |
|
69 return self; |
|
70 } |
|
71 |
|
72 CCFServer* CCFServer::NewLC() |
|
73 { |
|
74 FUNC_LOG; |
|
75 |
|
76 CCFServer* self = new( ELeave ) CCFServer( EPriorityNormal ); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 |
|
80 return self; |
|
81 } |
|
82 |
|
83 CCFServer::~CCFServer() |
|
84 { |
|
85 FUNC_LOG; |
|
86 |
|
87 delete iCFEngine; |
|
88 |
|
89 // Call this from here to ease testing of other components |
|
90 REComSession::FinalClose(); |
|
91 } |
|
92 |
|
93 void CCFServer::ConstructL() |
|
94 { |
|
95 FUNC_LOG; |
|
96 |
|
97 // Rename cfw thread |
|
98 User::RenameThread( KContextServerName ); |
|
99 |
|
100 iCFEngine = CCFEngine::NewL( *this ); |
|
101 |
|
102 // Start server |
|
103 StartL( KContextServerName ); |
|
104 } |
|
105 |
|
106 CCFServer::CCFServer( TInt aPriority ): |
|
107 CServer2( aPriority ) |
|
108 { |
|
109 FUNC_LOG; |
|
110 } |
|
111 |
|
112 // METHODS |
|
113 |
|
114 //---------------------------------------------------------------------------- |
|
115 // CCFServer::NewSessionL |
|
116 //---------------------------------------------------------------------------- |
|
117 // |
|
118 CSession2* CCFServer::NewSessionL( |
|
119 const TVersion &aVersion, |
|
120 const RMessage2& /*aMessage*/) const |
|
121 { |
|
122 FUNC_LOG; |
|
123 |
|
124 // check we're the right version |
|
125 TVersion version( KContextServMajorVersionNumber, |
|
126 KContextServMinorVersionNumber, |
|
127 KContextServBuildVersionNumber); |
|
128 |
|
129 if (!User::QueryVersionSupported( version, aVersion ) ) |
|
130 { |
|
131 User::Leave(KErrNotSupported); |
|
132 } |
|
133 |
|
134 CSession2* session = CCFServSession::NewL( |
|
135 ( MCFExtendedContextInterface& )*iCFEngine, |
|
136 ( MCFActionInterface& )*iCFEngine, |
|
137 ( MCFScriptInterface& )*iCFEngine ); |
|
138 |
|
139 // make new session |
|
140 return session; |
|
141 } |
|
142 |
|
143 //---------------------------------------------------------------------------- |
|
144 // CCFServer::NewSessionL |
|
145 //---------------------------------------------------------------------------- |
|
146 // |
|
147 TBool CCFServer::CheckClientSecurity( const RThread& aClientThread, |
|
148 const TSecurityPolicy& aSecurityPolicy ) |
|
149 { |
|
150 FUNC_LOG; |
|
151 |
|
152 // Security check only needed if request is from other process than CF |
|
153 TBool securityPassed = ETrue; |
|
154 if( !CFUtils::RequestFromSameProcess( aClientThread ) ) |
|
155 { |
|
156 securityPassed = aSecurityPolicy.CheckPolicy( aClientThread ); |
|
157 } |
|
158 |
|
159 return securityPassed; |
|
160 } |
|
161 |
|
162 //---------------------------------------------------------------------------- |
|
163 // CCFServer::PanicServer |
|
164 //---------------------------------------------------------------------------- |
|
165 // |
|
166 void CCFServer::PanicServer( TContextServPanic aPanic ) |
|
167 { |
|
168 FUNC_LOG; |
|
169 |
|
170 User::Panic( KContextServerName, aPanic ); |
|
171 } |
|
172 |
|
173 //---------------------------------------------------------------------------- |
|
174 // CCFServer::ThreadFunctionL |
|
175 //---------------------------------------------------------------------------- |
|
176 // |
|
177 void CCFServer::ThreadFunctionL( TAny* /*aThreadParms*/ ) |
|
178 { |
|
179 FUNC_LOG; |
|
180 |
|
181 // Create scheduler |
|
182 CActiveScheduler* activeScheduler = new( ELeave ) CActiveScheduler; |
|
183 CleanupStack::PushL( activeScheduler ); |
|
184 CActiveScheduler::Install( activeScheduler ); |
|
185 |
|
186 // Create Context Framework Server and signal client that we are ready |
|
187 CCFServer* server = CCFServer::NewLC(); |
|
188 RProcess::Rendezvous( KErrNone ); |
|
189 |
|
190 TIMESTAMP( "CF server active scheduler start" ); |
|
191 |
|
192 // Start scheduler |
|
193 CActiveScheduler::Start(); |
|
194 |
|
195 TIMESTAMP( "CF server process exit" ); |
|
196 |
|
197 // Clean up |
|
198 CleanupStack::PopAndDestroy( server ); |
|
199 CleanupStack::PopAndDestroy( activeScheduler ); |
|
200 } |
|
201 |
|
202 //---------------------------------------------------------------------------- |
|
203 // CCFServer::ThreadFunction |
|
204 //---------------------------------------------------------------------------- |
|
205 // |
|
206 TInt CCFServer::ThreadFunction( TAny* aThreadParms ) |
|
207 { |
|
208 FUNC_LOG; |
|
209 |
|
210 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
211 if( cleanupStack ) |
|
212 { |
|
213 TRAPD( err, ThreadFunctionL( aThreadParms ) ); |
|
214 if( err != KErrNone ) |
|
215 { |
|
216 // Signal client that server creation failed |
|
217 RProcess::Rendezvous( err ); |
|
218 } |
|
219 } |
|
220 |
|
221 // Clean up |
|
222 delete cleanupStack; |
|
223 cleanupStack = NULL; |
|
224 |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 // Entry point |
|
229 GLDEF_C TInt E32Main() |
|
230 { |
|
231 ENABLE_LOG; |
|
232 |
|
233 HEAP( "[START] CF server process entry" ); |
|
234 TIMESTAMP( "CF server process entry" ); |
|
235 |
|
236 return CCFServer::ThreadFunction( NULL ); |
|
237 } |