1 /* |
|
2 * Copyright (c) 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: Class definition of |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "diagresultsdatabasecommon.h" |
|
20 #include "diagresultsdbserver.h" |
|
21 #include "diagresultsdbsession.h" |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <e32uid.h> |
|
25 |
|
26 //Enter any new accepted UIDs here. |
|
27 const TInt KAcceptedUids[] = |
|
28 { |
|
29 0x2000B0E8, //Phone Doctor |
|
30 0x2000E542, //Diagnostics application |
|
31 0x102073E4, // STIF |
|
32 #if defined( _DEBUG ) || defined( __WINSCW__ ) |
|
33 0x10282CDA, //Results DB test app |
|
34 0x20000FB1, //EUnitAppEnv |
|
35 0x20000FB2, //EUnitEikApp |
|
36 0x20000FB3, //EUnitExeEnv |
|
37 0xED80F513, // DiagFramework Test app |
|
38 #endif // _DEBUG || __WINSCW__ |
|
39 0x2000F8E8 // donno |
|
40 }; |
|
41 |
|
42 const TInt KAcceptedUidCount = sizeof( KAcceptedUids ) / sizeof( TInt ); |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Constructor. |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CDiagResultsDbServer::CDiagResultsDbServer(TInt aPriority, |
|
49 const TPolicy &aPolicy) |
|
50 : CPolicyServer(aPriority, aPolicy), iContainerIndex( NULL ), iSessionCount(0) |
|
51 { |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Destructor. |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CDiagResultsDbServer::~CDiagResultsDbServer() |
|
59 { |
|
60 delete iContainerIndex; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // NewLC. |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 void CDiagResultsDbServer::NewLC(const TPolicy &aPolicy) |
|
68 { |
|
69 CDiagResultsDbServer *pS = new CDiagResultsDbServer( |
|
70 CActive::EPriorityHigh, aPolicy ); |
|
71 CleanupStack::PushL( pS ); |
|
72 pS->StartL( KDiagResultsDatabaseServerName ); |
|
73 pS->ConstructL(); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // ConstructL. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CDiagResultsDbServer::ConstructL() |
|
81 { |
|
82 iContainerIndex = CObjectConIx::NewL(); |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Create a new server session. |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CSession2 *CDiagResultsDbServer::NewSessionL(const TVersion &aVersion, |
|
91 const RMessage2 &/*aMessage*/) const |
|
92 { |
|
93 // check we're the right version |
|
94 TVersion v(KDiagResultsDatabaseServerMajor, KDiagResultsDatabaseServerMinor, |
|
95 KDiagResultsDatabaseServerBuild); |
|
96 if( !User::QueryVersionSupported( v, aVersion ) ) |
|
97 User::Leave( KErrNotSupported ); |
|
98 // make new session |
|
99 return CDiagResultsDbSession::NewL((CDiagResultsDbServer*)this); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Create new object container. |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CPolicyServer::TCustomResult CDiagResultsDbServer::CustomSecurityCheckL( |
|
107 const RMessage2 &aMsg, |
|
108 TInt &/*aAction*/, |
|
109 TSecurityInfo &/*aMissing*/) |
|
110 { |
|
111 CPolicyServer::TCustomResult result = EFail; |
|
112 TInt sid = aMsg.SecureId(); |
|
113 |
|
114 for ( TInt i = 0; i < KAcceptedUidCount; ++i ) |
|
115 { |
|
116 if ( sid == KAcceptedUids[i] ) |
|
117 { |
|
118 if ( aMsg.HasCapability( ECapabilityReadDeviceData ) && |
|
119 aMsg.HasCapability( ECapabilityWriteDeviceData ) ) |
|
120 { |
|
121 result = EPass; |
|
122 break; |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 return result; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // Create new object container. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CObjectCon* CDiagResultsDbServer::NewContainerL() |
|
135 { |
|
136 return iContainerIndex->CreateL(); |
|
137 } |
|
138 |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Remove object from a container index, |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CDiagResultsDbServer::RemoveContainer(CObjectCon* aCon) |
|
145 { |
|
146 iContainerIndex->Remove( aCon ); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // Return the total amount of client sessions. |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 TInt CDiagResultsDbServer::SessionCount() |
|
154 { |
|
155 return iSessionCount; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // Decrease session count when one client leaves and stop server if there are |
|
160 // no more clients. |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void CDiagResultsDbServer::DecreaseSessionCount() |
|
164 { |
|
165 iSessionCount--; |
|
166 if (iSessionCount == 0) |
|
167 { |
|
168 CActiveScheduler::Stop(); |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // One new session created. |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CDiagResultsDbServer::IncreaseSessionCount() |
|
177 { |
|
178 iSessionCount++; |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // Create cleanupStack and call RunserverL. |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CDiagResultsDbServer::RunServer() |
|
186 { |
|
187 __UHEAP_MARK; |
|
188 // |
|
189 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
190 TInt ret = KErrNoMemory; |
|
191 if( cleanup ) |
|
192 { |
|
193 TRAP( ret, CDiagResultsDbServer::RunServerL() ); |
|
194 delete cleanup; |
|
195 } |
|
196 // |
|
197 __UHEAP_MARKEND; |
|
198 if( ret != KErrNone ) |
|
199 { |
|
200 // Signal the client that server creation failed |
|
201 RProcess::Rendezvous( ret ); |
|
202 } |
|
203 return ret; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // Create active scheduler and run server. |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CDiagResultsDbServer::RunServerL() |
|
211 { |
|
212 User::RenameThread(KDiagResultsDatabaseServerName); |
|
213 |
|
214 // Create and install the active scheduler we need |
|
215 CActiveScheduler *as=new (ELeave)CActiveScheduler; |
|
216 CleanupStack::PushL( as ); |
|
217 CActiveScheduler::Install(as); |
|
218 |
|
219 // Create server |
|
220 CDiagResultsDbServer::NewLC(policy); |
|
221 |
|
222 // Initialisation complete, now signal the client |
|
223 |
|
224 RProcess::Rendezvous(KErrNone); |
|
225 |
|
226 // Ready to run |
|
227 CActiveScheduler::Start(); |
|
228 |
|
229 // Cleanup the server and scheduler |
|
230 CleanupStack::PopAndDestroy(2, as); |
|
231 } |
|
232 |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // Main function that is called when server(.EXE) is launched. |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 TInt E32Main() |
|
239 { |
|
240 TInt error(KErrNone); |
|
241 error = CDiagResultsDbServer::RunServer(); |
|
242 return error; |
|
243 } |
|
244 |
|
245 |
|