51
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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: XIMP Framework PSC server class
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "ximpserverdefs.h"
|
|
19 |
#include "ximpserver.h"
|
|
20 |
#include "ximpserversessionadapter.h"
|
|
21 |
#include "ximptrace.h"
|
|
22 |
#include "ximpglobals.h"
|
|
23 |
#include "ximpoperationfactoryimp.h"
|
|
24 |
#include <ecom/ecom.h>
|
|
25 |
|
|
26 |
//Include PSC server namespace
|
|
27 |
using namespace NXIMPSrv;
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
// ==============================================================
|
|
32 |
// =============== PLATSEC POLICY CONFIGURATION =================
|
|
33 |
// ==============================================================
|
|
34 |
static const TInt KXIMPServerPlatSecRangeCount = 3;
|
|
35 |
|
|
36 |
static const TInt KXIMPServerPlatSecPolicyIndex0 = 0;
|
|
37 |
static const TInt KXIMPServerPlatSecPolicyIndex1 = 1;
|
|
38 |
|
|
39 |
//Ranges for the Request values
|
|
40 |
static const TInt KXIMPServerPlatSecRanges[ KXIMPServerPlatSecRangeCount ] =
|
|
41 |
{
|
|
42 |
0,
|
|
43 |
NRequest::ECtxSsQueueBindOperation,
|
|
44 |
NRequest::EOpCodeTop
|
|
45 |
};
|
|
46 |
|
|
47 |
|
|
48 |
// Element indexes for the defined ranges
|
|
49 |
static const TUint8 KXIMPServerPlatSecElementsIndex[ KXIMPServerPlatSecRangeCount ] =
|
|
50 |
{
|
|
51 |
KXIMPServerPlatSecPolicyIndex0,
|
|
52 |
KXIMPServerPlatSecPolicyIndex1,
|
|
53 |
CPolicyServer::ENotSupported
|
|
54 |
};
|
|
55 |
|
|
56 |
|
|
57 |
// Policy elements
|
|
58 |
static const CPolicyServer::TPolicyElement KXIMPServerPlatSecElements[] =
|
|
59 |
{
|
|
60 |
{
|
|
61 |
// Policy 0, KXIMPServerPlatSecPolicyIndex0
|
|
62 |
_INIT_SECURITY_POLICY_C3( ECapabilityReadUserData,
|
|
63 |
ECapabilityWriteUserData,
|
|
64 |
ECapabilityNetworkServices ),
|
|
65 |
CPolicyServer::EFailClient
|
|
66 |
},
|
|
67 |
{
|
|
68 |
// Policy 1, KXIMPServerPlatSecPolicyIndex1
|
|
69 |
_INIT_SECURITY_POLICY_C4( ECapabilityReadDeviceData,
|
|
70 |
ECapabilityReadUserData,
|
|
71 |
ECapabilityWriteUserData,
|
|
72 |
ECapabilityNetworkServices ),
|
|
73 |
CPolicyServer::EFailClient
|
|
74 |
}
|
|
75 |
};
|
|
76 |
|
|
77 |
|
|
78 |
// The platsec policy
|
|
79 |
static const CPolicyServer::TPolicy KXIMPServerPlatSecPolicy =
|
|
80 |
{
|
|
81 |
// Shortcut to the index into Elements,that is used to check a connection attempt
|
|
82 |
KXIMPServerPlatSecPolicyIndex0,
|
|
83 |
|
|
84 |
// Number of ranges in the iRanges array
|
|
85 |
KXIMPServerPlatSecRangeCount,
|
|
86 |
|
|
87 |
// A pointer to an array of ordered ranges of request numbers
|
|
88 |
KXIMPServerPlatSecRanges,
|
|
89 |
|
|
90 |
// A pointer to an array of TUint8 values specifying
|
|
91 |
// the appropriate action to take for each range in iRanges
|
|
92 |
KXIMPServerPlatSecElementsIndex,
|
|
93 |
|
|
94 |
// A pointer to an array of distinct policy elements
|
|
95 |
KXIMPServerPlatSecElements
|
|
96 |
};
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
// -----------------------------------------------------------------------------
|
|
101 |
// CXIMPServer::ExecuteL()
|
|
102 |
// -----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
void CXIMPServer::ExecuteL()
|
|
105 |
{
|
|
106 |
// start scheduler
|
|
107 |
CActiveScheduler* pA = new( ELeave )CActiveScheduler;
|
|
108 |
CleanupStack::PushL( pA );
|
|
109 |
CActiveScheduler::Install( pA );
|
|
110 |
|
|
111 |
// create server
|
|
112 |
CXIMPServer* server = CXIMPServer::NewLC();
|
|
113 |
|
|
114 |
// rename our thread properly
|
|
115 |
// first, find out the UID set by process starter
|
|
116 |
TInt uid = 0;
|
|
117 |
TInt ret = User::GetTIntParameter( NStartupParam::KProtocolUidIndex,
|
|
118 |
uid );
|
|
119 |
User::LeaveIfError( ret );
|
|
120 |
|
|
121 |
// create the "!XIMPCtxSrv9bde667a" server name
|
|
122 |
HBufC* serverName = HBufC::NewLC( NName::KSymbianServer().Length() +
|
|
123 |
NStartupParam::KProtocolUidMaxLen +
|
|
124 |
1 );
|
|
125 |
|
|
126 |
serverName->Des().Copy( NName::KSymbianServer );
|
|
127 |
serverName->Des().AppendNumFixedWidth( uid,
|
|
128 |
EHex,
|
|
129 |
NStartupParam::KProtocolUidMaxLen );
|
|
130 |
|
|
131 |
// and set it
|
|
132 |
User::RenameThread( *serverName );
|
|
133 |
server->StartL( *serverName );
|
|
134 |
|
|
135 |
CleanupStack::PopAndDestroy( serverName );
|
|
136 |
|
|
137 |
//Signal client that we are started
|
|
138 |
RProcess().Rendezvous( KErrNone );
|
|
139 |
|
|
140 |
//Execute the server
|
|
141 |
CActiveScheduler::Start(); // CSI: 3 #
|
|
142 |
|
|
143 |
//Cleanup
|
|
144 |
CleanupStack::PopAndDestroy( server );//server
|
|
145 |
CleanupStack::PopAndDestroy( pA );
|
|
146 |
CActiveScheduler::Install( NULL );
|
|
147 |
}
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
// CXIMPServer::~CXIMPServer()
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
CXIMPServer::~CXIMPServer()
|
|
156 |
{
|
|
157 |
CXIMPGlobals::UninstallD();
|
|
158 |
REComSession::FinalClose();
|
|
159 |
|
|
160 |
#if _BullseyeCoverage
|
|
161 |
cov_write();
|
|
162 |
#endif
|
|
163 |
}
|
|
164 |
|
|
165 |
|
|
166 |
// -----------------------------------------------------------------------------
|
|
167 |
// CXIMPServer::CXIMPServer()
|
|
168 |
// -----------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
CXIMPServer::CXIMPServer()
|
|
171 |
: CPolicyServer( CActive::EPriorityStandard, KXIMPServerPlatSecPolicy )
|
|
172 |
{
|
|
173 |
iSessionId = 1; // start from 1. 0 reserved for host-originated operations
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
// -----------------------------------------------------------------------------
|
|
178 |
// CXIMPServer::NewLC()
|
|
179 |
// -----------------------------------------------------------------------------
|
|
180 |
//
|
|
181 |
CXIMPServer* CXIMPServer::NewLC()
|
|
182 |
{
|
|
183 |
CXIMPServer* self = new( ELeave ) CXIMPServer;
|
|
184 |
CleanupStack::PushL( self );
|
|
185 |
self->ConstructL();
|
|
186 |
return self;
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
// CXIMPServer::ConstructL()
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
//
|
|
194 |
void CXIMPServer::ConstructL()
|
|
195 |
{
|
|
196 |
CXIMPOperationFactory* operationFactory = CXIMPOperationFactory::NewL();
|
|
197 |
CleanupStack::PushL( operationFactory );
|
|
198 |
CXIMPGlobals::InstallL( operationFactory, this );
|
|
199 |
CleanupStack::Pop( operationFactory );
|
|
200 |
iGlobals = CXIMPGlobals::Instance();
|
|
201 |
}
|
|
202 |
|
|
203 |
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
// CXIMPServer::NewSessionL()
|
|
206 |
// -----------------------------------------------------------------------------
|
|
207 |
//
|
|
208 |
CSession2* CXIMPServer::NewSessionL( const TVersion &aVersion,
|
|
209 |
const RMessage2& /* aMessage */ ) const
|
|
210 |
{
|
|
211 |
TVersion srvVersion( NVersion::KMajor,
|
|
212 |
NVersion::KMinor,
|
|
213 |
NVersion::KBuild );
|
|
214 |
|
|
215 |
if( !User::QueryVersionSupported( aVersion, srvVersion ) )
|
|
216 |
{
|
|
217 |
User::Leave( KErrNotSupported );
|
|
218 |
}
|
|
219 |
|
|
220 |
CXIMPServer* self = const_cast< CXIMPServer* >( this );
|
|
221 |
self->iSessionId++;
|
|
222 |
return CXIMPServerSessionAdapter::NewL( iSessionId,
|
|
223 |
*self );
|
|
224 |
};
|
|
225 |
|
|
226 |
|
|
227 |
// -----------------------------------------------------------------------------
|
|
228 |
// CXIMPServer::SessionCreated()
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
//
|
|
231 |
void CXIMPServer::SessionCreated()
|
|
232 |
{
|
|
233 |
iSessionCount++;
|
|
234 |
}
|
|
235 |
|
|
236 |
|
|
237 |
// -----------------------------------------------------------------------------
|
|
238 |
// CXIMPServer::SessionDied()
|
|
239 |
// -----------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
void CXIMPServer::SessionDied()
|
|
242 |
{
|
|
243 |
iSessionCount--;
|
|
244 |
TryToStopScheduling();
|
|
245 |
}
|
|
246 |
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
// CXIMPServer::AllHostsDied()
|
|
249 |
// -----------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
void CXIMPServer::AllHostsDied()
|
|
252 |
{
|
|
253 |
// all hosts have died.
|
|
254 |
iAllHostsDied = ETrue;
|
|
255 |
TryToStopScheduling();
|
|
256 |
}
|
|
257 |
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
// CXIMPServer::AllHostsDied()
|
|
260 |
// -----------------------------------------------------------------------------
|
|
261 |
//
|
|
262 |
void CXIMPServer::TryToStopScheduling()
|
|
263 |
{
|
|
264 |
if( iSessionCount == 0 && iAllHostsDied )
|
|
265 |
{
|
|
266 |
CActiveScheduler::Stop(); // CSI: 4 #
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
// -----------------------------------------------------------------------------
|
|
271 |
// CXIMPServer::TestListener()
|
|
272 |
// -----------------------------------------------------------------------------
|
|
273 |
//
|
|
274 |
MXIMPSrvTestListener* CXIMPServer::TestListener() const
|
|
275 |
{
|
|
276 |
return iTestListener;
|
|
277 |
}
|
|
278 |
|
|
279 |
// -----------------------------------------------------------------------------
|
|
280 |
// CXIMPServer::RegisterTestListener()
|
|
281 |
// -----------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
void CXIMPServer::RegisterTestListener( MXIMPSrvTestListener* aTestSession )
|
|
284 |
{
|
|
285 |
iTestListener = aTestSession;
|
|
286 |
}
|
|
287 |
|
|
288 |
// -----------------------------------------------------------------------------
|
|
289 |
// E32Main()
|
|
290 |
// ENTRY POINT
|
|
291 |
// -----------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
GLDEF_C TInt E32Main()
|
|
294 |
{
|
|
295 |
TRACE( _L("PSC Server E32Main - enter") );
|
|
296 |
|
|
297 |
__UHEAP_MARK;
|
|
298 |
|
|
299 |
CTrapCleanup* tc = CTrapCleanup::New();
|
|
300 |
if( !tc )
|
|
301 |
{
|
|
302 |
return KErrNoMemory;
|
|
303 |
}
|
|
304 |
|
|
305 |
User::RenameThread( NName::KMainThread );
|
|
306 |
|
|
307 |
TRAPD( err, CXIMPServer::ExecuteL() );
|
|
308 |
delete tc;
|
|
309 |
|
|
310 |
__UHEAP_MARKEND;
|
|
311 |
|
|
312 |
TRACE_1( _L("PSC Server E32Main - exit: %d"), err );
|
|
313 |
return err;
|
|
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
// END OF FILE
|
|
318 |
|
|
319 |
|