|
1 /* |
|
2 * Copyright (c) 2005 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: DS Host Server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32std.h> |
|
21 #include <data_caging_path_literals.hrh> |
|
22 #include <f32file.h> |
|
23 #include <e32math.h> |
|
24 |
|
25 #include <nsmldebug.h> |
|
26 #include "nsmldshostconstants.h" |
|
27 #include "Nsmldshostserver.h" |
|
28 #include "Nsmldshostsession.h" |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KNSmlMaxSessionCount = 200; |
|
32 |
|
33 // ======================================= MEMBER FUNCTIONS ======================================= |
|
34 |
|
35 // ------------------------------------------------------------------------------------------------ |
|
36 // CNSmlDSHostServer::~CNSmlDSHostServer |
|
37 // ------------------------------------------------------------------------------------------------ |
|
38 EXPORT_C CNSmlDSHostServer::~CNSmlDSHostServer() |
|
39 { |
|
40 _DBG_FILE("CNSmlDSHostServer::~CNSmlDSHostServer(): begin"); |
|
41 _DBG_FILE("CNSmlDSHostServer::~CNSmlDSHostServer(): end"); |
|
42 } |
|
43 |
|
44 // ------------------------------------------------------------------------------------------------ |
|
45 // CNSmlDSHostServer::InitHostServer |
|
46 // ------------------------------------------------------------------------------------------------ |
|
47 EXPORT_C TInt CNSmlDSHostServer::InitHostServer( TNSmlHostServers aServer, TThreadFunction aFunction ) |
|
48 { |
|
49 const TDesC& serverName = ServerName( aServer ); |
|
50 if ( serverName == KNullDesC ) |
|
51 { |
|
52 return KErrArgument; |
|
53 } |
|
54 |
|
55 // check server not already started |
|
56 TFindServer findHostServer( serverName ); |
|
57 TFullName name; |
|
58 if ( findHostServer.Next( name ) == KErrNone ) |
|
59 { // found server already |
|
60 return KErrGeneral; |
|
61 } |
|
62 |
|
63 TInt error( KErrNone ); |
|
64 error = ThreadFunction( (TAny*) aFunction, aServer ); |
|
65 |
|
66 return error; |
|
67 } |
|
68 |
|
69 // ------------------------------------------------------------------------------------------------ |
|
70 // CNSmlDSHostServer::ServerName |
|
71 // ------------------------------------------------------------------------------------------------ |
|
72 const TDesC& CNSmlDSHostServer::ServerName( TNSmlHostServers aServer ) |
|
73 { |
|
74 if ( aServer > ENSmlHostServerEnd ) |
|
75 { |
|
76 aServer = ENSmlHostServerEnd; |
|
77 } |
|
78 |
|
79 const TDesC* KNSmlHostServerNames[ENSmlHostServerEnd + 1] = |
|
80 { |
|
81 &KNSmlDSHostServer1Name, |
|
82 &KNSmlDSHostServer2Name, |
|
83 &KNullDesC |
|
84 }; |
|
85 |
|
86 return *KNSmlHostServerNames[aServer]; |
|
87 } |
|
88 |
|
89 // ------------------------------------------------------------------------------------------------ |
|
90 // CNSmlDSHostServer::ServerModuleName |
|
91 // ------------------------------------------------------------------------------------------------ |
|
92 const TDesC& CNSmlDSHostServer::ServerModuleName( TNSmlHostServers aServer ) |
|
93 { |
|
94 if ( aServer > ENSmlHostServerEnd ) |
|
95 { |
|
96 aServer = ENSmlHostServerEnd; |
|
97 } |
|
98 |
|
99 const TDesC* KNSmlHostServerModuleNames[ENSmlHostServerEnd + 1] = |
|
100 { |
|
101 &KNSmlDSHostServer1Exe, |
|
102 &KNSmlDSHostServer2Exe, |
|
103 &KNullDesC |
|
104 }; |
|
105 |
|
106 return *KNSmlHostServerModuleNames[aServer]; |
|
107 } |
|
108 |
|
109 // ------------------------------------------------------------------------------------------------ |
|
110 // CNSmlDSHostServer::ThreadFunction |
|
111 // ------------------------------------------------------------------------------------------------ |
|
112 TInt CNSmlDSHostServer::ThreadFunction( TAny* aStarted, TNSmlHostServers aServer ) |
|
113 { |
|
114 __UHEAP_MARK; |
|
115 |
|
116 TThreadFunction function = reinterpret_cast<TThreadFunction>( aStarted ); |
|
117 |
|
118 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
119 __ASSERT_ALWAYS( cleanup, HandleLeaveOnStartup( &aServer ) ); |
|
120 TRAPD(err, HostServerStartUpL( function, aServer ) ); |
|
121 delete cleanup; |
|
122 __UHEAP_MARKEND; |
|
123 |
|
124 return err; |
|
125 } |
|
126 |
|
127 // ------------------------------------------------------------------------------------------------ |
|
128 // CNSmlDSHostServer::HostServerStartUpL |
|
129 // ------------------------------------------------------------------------------------------------ |
|
130 void CNSmlDSHostServer::HostServerStartUpL( TThreadFunction aFunction, TNSmlHostServers aServer ) |
|
131 { |
|
132 CleanupStack::PushL( TCleanupItem ( HandleLeaveOnStartup, &aServer ) ); |
|
133 |
|
134 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler(); |
|
135 CActiveScheduler::Install( scheduler ); |
|
136 |
|
137 __UHEAP_MARK; |
|
138 aFunction( NULL ); |
|
139 __UHEAP_MARKEND; |
|
140 |
|
141 CActiveScheduler::Install( NULL ); |
|
142 delete scheduler; |
|
143 |
|
144 CleanupStack::Pop(); |
|
145 } |
|
146 |
|
147 // ------------------------------------------------------------------------------------------------ |
|
148 // CNSmlDSHostServer::ServerFromThread |
|
149 // ------------------------------------------------------------------------------------------------ |
|
150 TNSmlHostServers CNSmlDSHostServer::ServerFromThread( const RThread &aThread ) |
|
151 { |
|
152 TInt tmp; |
|
153 TName thname = aThread.Name(); |
|
154 TPtrC serverid = thname.Left( 4 ); |
|
155 TLex lex( serverid ); |
|
156 lex.Val(tmp); |
|
157 return static_cast<TNSmlHostServers>( tmp ); |
|
158 } |
|
159 // ------------------------------------------------------------------------------------------------ |
|
160 // CNSmlDSHostServer::NewSessionL |
|
161 // ------------------------------------------------------------------------------------------------ |
|
162 CSession2* CNSmlDSHostServer::NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const |
|
163 { |
|
164 _DBG_FILE("CNSmlDSHostServer::NewSessionL(): begin"); |
|
165 if( iSessionCount >= KNSmlMaxSessionCount ) |
|
166 { |
|
167 User::Leave( KErrCouldNotConnect ); |
|
168 } |
|
169 |
|
170 // check we're the right version |
|
171 TVersion DSHostServerVersion( KNSmlDSHostServerVersionMajor, |
|
172 KNSmlDSHostServerVersionMinor, KNSmlDSHostServerVersionBuild ); |
|
173 |
|
174 if( !User::QueryVersionSupported( DSHostServerVersion, aVersion ) ) |
|
175 { |
|
176 _DBG_FILE("CNSmlDSHostServer::NewSessionL(): wrong version offered -> BAIL OUT!"); |
|
177 User::Leave(KErrNotSupported); |
|
178 } |
|
179 TSecureId id = aMessage.SecureId(); |
|
180 _LIT_SECURITY_POLICY_S0( mySidPolicy, KNSmlSOSServerSecureID ); |
|
181 |
|
182 if ( !mySidPolicy().CheckPolicy( aMessage ) ) |
|
183 { |
|
184 User::Leave( KErrPermissionDenied ); |
|
185 } |
|
186 |
|
187 _DBG_FILE("CNSmlDSHostServer::NewSessionL(): end"); |
|
188 return CNSmlDSHostSession::NewL( *const_cast<CNSmlDSHostServer*>( this ) ); |
|
189 } |
|
190 |
|
191 // ------------------------------------------------------------------------------------------------ |
|
192 // CNSmlDSHostServer::CNSmlDSHostServer |
|
193 // ------------------------------------------------------------------------------------------------ |
|
194 EXPORT_C CNSmlDSHostServer::CNSmlDSHostServer() : CServer2(EPriorityStandard) |
|
195 { |
|
196 _DBG_FILE("CNSmlDSHostServer::CNSmlDSHostServer(): begin"); |
|
197 _DBG_FILE("CNSmlDSHostServer::CNSmlDSHostServer(): end"); |
|
198 } |
|
199 |
|
200 // ------------------------------------------------------------------------------------------------ |
|
201 // CNSmlDSHostServer::IncSessionCount |
|
202 // ------------------------------------------------------------------------------------------------ |
|
203 EXPORT_C void CNSmlDSHostServer::IncSessionCount() |
|
204 { |
|
205 _DBG_FILE("CNSmlDSHostServer::IncSessionCount(): begin"); |
|
206 ++iSessionCount; |
|
207 _DBG_FILE("CNSmlDSHostServer::IncSessionCount(): end"); |
|
208 } |
|
209 |
|
210 // ------------------------------------------------------------------------------------------------ |
|
211 // CNSmlDSHostServer::DecSessionCount |
|
212 // ------------------------------------------------------------------------------------------------ |
|
213 EXPORT_C void CNSmlDSHostServer::DecSessionCount() |
|
214 { |
|
215 _DBG_FILE("CNSmlDSHostServer::DecSessionCount(): begin"); |
|
216 --iSessionCount; |
|
217 if ( !iSessionCount ) |
|
218 { |
|
219 CActiveScheduler::Stop(); |
|
220 } |
|
221 _DBG_FILE("CNSmlDSHostServer::DecSessionCount(): end"); |
|
222 } |
|
223 |
|
224 // ------------------------------------------------------------------------------------------------ |
|
225 // CNSmlDSHostServer::CallNewSessionL |
|
226 // ------------------------------------------------------------------------------------------------ |
|
227 EXPORT_C CSession2* CNSmlDSHostServer::CallNewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const |
|
228 { |
|
229 return CNSmlDSHostServer::NewSessionL( aVersion, aMessage ); |
|
230 } |
|
231 |
|
232 // ------------------------------------------------------------------------------------------------ |
|
233 // CNSmlDSHostServer::HandleLeaveOnStartup |
|
234 // ------------------------------------------------------------------------------------------------ |
|
235 void CNSmlDSHostServer::HandleLeaveOnStartup( TAny* /*aP*/ ) |
|
236 { |
|
237 RProcess::Rendezvous( KErrGeneral ); |
|
238 PanicServer( EMainSchedulerError ); |
|
239 } |
|
240 |
|
241 // ------------------------------------------------------------------------------------------------ |
|
242 // CNSmlDSHostServer::PanicServer |
|
243 // ------------------------------------------------------------------------------------------------ |
|
244 void CNSmlDSHostServer::PanicServer( TNSmlHostServerErrors aPanic ) |
|
245 { |
|
246 _LIT( KTxtDSHostServerBase, "NSmlDSHostServerBase" ); |
|
247 User::Panic( KTxtDSHostServerBase, aPanic ); |
|
248 } |
|
249 |
|
250 // End of File |