36
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// INCLUDE FILES
|
|
15 |
//
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <e32svr.h>
|
|
21 |
#include <ecom/ecom.h>
|
|
22 |
#include <connect/sbdefs.h>
|
|
23 |
|
|
24 |
//#include <LbsIpc.h>
|
|
25 |
//#include <StartPosServer.h>
|
|
26 |
#include <lbsipc.h>
|
|
27 |
#include "lbslocservermessageenums.h"
|
|
28 |
#include "EPos_CPosResourceReader.h"
|
|
29 |
#include <eposserver.rsg>
|
|
30 |
#include <lbs/epos_mposmodulesobserver.h>
|
|
31 |
#ifdef SYMBIAN_FEATURE_MANAGER
|
|
32 |
#include <featdiscovery.h>
|
|
33 |
#include <featureuids.h>
|
|
34 |
#endif
|
|
35 |
#include "epos_cposmodulessettings.h"
|
|
36 |
#include "EPos_CPosServer.h"
|
|
37 |
#include "EPos_ServerPanic.h"
|
|
38 |
#include "EPos_CPosSession.h"
|
|
39 |
#include "EPos_CPosServerDelayedShutdown.h"
|
|
40 |
#include "EPos_CPosModulesStatus.h"
|
|
41 |
#include "EPos_CPosLocMonitorReqHandlerHub.h"
|
|
42 |
|
|
43 |
#include "EPos_Global.h"
|
|
44 |
#include "lbspositioningstatusprops.h"
|
|
45 |
|
|
46 |
// CONSTANTS
|
|
47 |
_LIT(KPosResourceFile, "\\private\\101F97B2\\eposserver.rsc");
|
|
48 |
|
|
49 |
#ifdef _DEBUG
|
|
50 |
_LIT(KTraceFileName, "EPos_CPosServer.cpp");
|
|
51 |
#endif
|
|
52 |
|
|
53 |
// ================= SERVER'S POLICY =======================
|
|
54 |
|
|
55 |
//Definition of the ranges of IPC numbers
|
|
56 |
const TInt eposServerPolicyRanges[] =
|
|
57 |
{
|
|
58 |
0,
|
|
59 |
ELbsServerCancelAsyncRequest,
|
|
60 |
ELbsGetDefaultModuleId,
|
|
61 |
ELbsEmptyLastKnownPositionStore,
|
|
62 |
ELbsServerLastMessageId,
|
|
63 |
|
|
64 |
ELbsPositionerCancelAsyncRequest,
|
|
65 |
ELbsPositionerOpen,
|
|
66 |
ELbsPositionerClose,
|
|
67 |
ELbsSetSingleRequestor,
|
|
68 |
ELbsPositionerLastMessageId,
|
|
69 |
ELbsPositionCustomCodesFirst
|
|
70 |
};
|
|
71 |
|
|
72 |
// Total number of ranges
|
|
73 |
const TUint eposServerPolicyRangeCount =
|
|
74 |
sizeof(eposServerPolicyRanges) / sizeof(TInt);
|
|
75 |
|
|
76 |
// Types of Policies
|
|
77 |
enum TPolicies
|
|
78 |
{
|
|
79 |
EPolicyLocationNeeded = 0,
|
|
80 |
EPolicyWriteUserDataNeeded,
|
|
81 |
};
|
|
82 |
|
|
83 |
// Specific capability checks
|
|
84 |
const CPolicyServer::TPolicyElement eposServerPolicyElements[] =
|
|
85 |
{
|
|
86 |
// policy EPolicyLocationNeeded - fail call if Location not present
|
|
87 |
{_INIT_SECURITY_POLICY_C1(ECapabilityLocation), CPolicyServer::EFailClient},
|
|
88 |
// policy EPolicyWriteUserDataNeeded - fail call if WriteUserData capability not present
|
|
89 |
{_INIT_SECURITY_POLICY_C1(ECapabilityWriteUserData), CPolicyServer::EFailClient}
|
|
90 |
};
|
|
91 |
|
|
92 |
//Policy to implement for each of the above ranges
|
|
93 |
const TUint8 eposServerPolicyElementsIndex[eposServerPolicyRangeCount] =
|
|
94 |
{
|
|
95 |
CPolicyServer::ENotSupported,
|
|
96 |
CPolicyServer::EAlwaysPass, // server cancel
|
|
97 |
EPolicyLocationNeeded, // GetDefModId -> NotifyModStatusEv
|
|
98 |
EPolicyWriteUserDataNeeded, // Empty Last Known position store
|
|
99 |
CPolicyServer::ENotSupported, // reserved server's codes
|
|
100 |
CPolicyServer::EAlwaysPass, // positioner cancel
|
|
101 |
CPolicyServer::EAlwaysPass, // open methods
|
|
102 |
CPolicyServer::EAlwaysPass, // close positioner
|
|
103 |
EPolicyLocationNeeded, // SetSingReq -> GetLastKnownPositionArea
|
|
104 |
CPolicyServer::ENotSupported, // reserved positioner's codes
|
|
105 |
CPolicyServer::ECustomCheck // custom requests
|
|
106 |
};
|
|
107 |
|
|
108 |
//Package all the above together into a policy
|
|
109 |
const CPolicyServer::TPolicy eposServerPolicy =
|
|
110 |
{
|
|
111 |
CPolicyServer::EAlwaysPass, // onConnect
|
|
112 |
eposServerPolicyRangeCount, // number of ranges
|
|
113 |
eposServerPolicyRanges, // ranges array
|
|
114 |
eposServerPolicyElementsIndex, // elements<->ranges index
|
|
115 |
eposServerPolicyElements, // array of elements
|
|
116 |
};
|
|
117 |
|
|
118 |
// ================= MEMBER FUNCTIONS =======================
|
|
119 |
|
|
120 |
/**
|
|
121 |
* C++ constructor.
|
|
122 |
*
|
|
123 |
* @param aPriority Priority at which to run the server active object.
|
|
124 |
* @param aPolicy Reference to a policy object describing the security
|
|
125 |
* checks required for each message type.
|
|
126 |
* @param aServerType Sharable or non-sharable sessions.
|
|
127 |
*/
|
|
128 |
CPosServer::CPosServer(TInt aPriority, const TPolicy &aPolicy, TServerType aServerType)
|
|
129 |
: CPolicyServer(aPriority, aPolicy, aServerType)
|
|
130 |
{
|
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Symbian default constructor.
|
|
135 |
*/
|
|
136 |
void CPosServer::ConstructL()
|
|
137 |
{
|
|
138 |
TBool LocationManagementSupported = EFalse;
|
|
139 |
#ifdef SYMBIAN_FEATURE_MANAGER
|
|
140 |
LocationManagementSupported = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KLocationManagement);
|
|
141 |
#else
|
|
142 |
__ASSERT_ALWAYS(EFalse, User::Invariant()); // Would happen on older versions of symbian OS if this code ever backported
|
|
143 |
#endif
|
|
144 |
// make sure that root process is running
|
|
145 |
if(LocationManagementSupported && !FindRootProcess())
|
|
146 |
{
|
|
147 |
User::Leave(KErrNotReady);
|
|
148 |
}
|
|
149 |
// Backup listener
|
|
150 |
DEBUG_TRACE("Checking for backup or restore...", __LINE__)
|
|
151 |
iBackupListener = CPosBackupListener::NewL();
|
|
152 |
if (iBackupListener->IsBackupOperationOngoing())
|
|
153 |
{
|
|
154 |
User::Leave(KErrNotReady);
|
|
155 |
}
|
|
156 |
iBackupListener->Start(*this);
|
|
157 |
|
|
158 |
|
|
159 |
// Settings and last position handler
|
|
160 |
CPosResourceReader* resources = CPosResourceReader::NewLC(KPosResourceFile);
|
|
161 |
iServerShutdownDelay = resources->ReadInt32L(R_POS_SERVER_SHUTDOWN_DELAY);
|
|
162 |
|
|
163 |
TInt dumpInterval = resources->ReadInt32L(R_POS_SERVER_DUMP_INTERVAL);
|
|
164 |
|
|
165 |
//DEBUG_TRACE("Reading last known position...", __LINE__)
|
|
166 |
// HBufC* lastKnownPositionFileName = resources->ReadHBufCL(R_LAST_KNOWN_POSITION_FILENAME);
|
|
167 |
// CleanupStack::PushL(lastKnownPositionFileName);
|
|
168 |
iLocMonitorReqHandlerHub = CPosLocMonitorReqHandlerHub::NewL();
|
|
169 |
|
|
170 |
|
|
171 |
CleanupStack::PopAndDestroy(resources);
|
|
172 |
|
|
173 |
// Shutdown timer
|
|
174 |
iShutdown = CPosServerDelayedShutdown::NewL();
|
|
175 |
|
|
176 |
|
|
177 |
DEBUG_TRACE("Opening Location Settings...", __LINE__)
|
|
178 |
// Location Settings
|
|
179 |
iModuleSettings = CPosModuleSettings::NewL();
|
|
180 |
iModulesStatus = CPosModulesStatus::NewL(iModuleSettings->PosModules());
|
|
181 |
DEBUG_TRACE("Setting Location Settings observer...", __LINE__)
|
|
182 |
iModuleSettings->AddListenerL(*this);
|
|
183 |
|
|
184 |
// Define the MO Positioning Status property
|
|
185 |
LbsPositioningStatusProps::InitializeMoPropertyL();
|
|
186 |
|
|
187 |
DEBUG_TRACE("Starting server active object...", __LINE__)
|
|
188 |
StartL(KPositionServerName);
|
|
189 |
}
|
|
190 |
|
|
191 |
/**
|
|
192 |
* Two-phased constructor.
|
|
193 |
*/
|
|
194 |
CPosServer* CPosServer::NewL()
|
|
195 |
{
|
|
196 |
CPosServer* self = new (ELeave) CPosServer(EPriority, eposServerPolicy);
|
|
197 |
CleanupStack::PushL(self);
|
|
198 |
self->ConstructL();
|
|
199 |
CleanupStack::Pop(self);
|
|
200 |
return self;
|
|
201 |
}
|
|
202 |
|
|
203 |
/**
|
|
204 |
* Destructor.
|
|
205 |
*/
|
|
206 |
CPosServer::~CPosServer()
|
|
207 |
{
|
|
208 |
delete iLocMonitorReqHandlerHub;
|
|
209 |
|
|
210 |
delete iShutdown;
|
|
211 |
delete iModulesStatus;
|
|
212 |
delete iModuleSettings;
|
|
213 |
delete iBackupListener;
|
|
214 |
|
|
215 |
|
|
216 |
// This is needed because CPositioner might have used ECom (PSYs)
|
|
217 |
REComSession::FinalClose();
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* From MPosModuleSettingsListener.
|
|
222 |
*
|
|
223 |
* Called when a change has been detected in the modules database.
|
|
224 |
* @param aEvent Event information
|
|
225 |
*/
|
|
226 |
void CPosServer::HandleModuleSettingsChangedL(TPosModulesEvent aEvent)
|
|
227 |
{
|
|
228 |
// Notify iModuleStatus
|
|
229 |
iModulesStatus->HandleSettingsChangeL(aEvent);
|
|
230 |
|
|
231 |
// For all sessions, call HandleSettingsChangeL()
|
|
232 |
iSessionIter.SetToFirst();
|
|
233 |
CPosSession* session = static_cast <CPosSession*> (iSessionIter++);
|
|
234 |
while (session)
|
|
235 |
{
|
|
236 |
session->HandleSettingsChangeL(aEvent);
|
|
237 |
session = static_cast <CPosSession*> (iSessionIter++);
|
|
238 |
}
|
|
239 |
}
|
|
240 |
|
|
241 |
/**
|
|
242 |
* From MPosBackupEventCallback
|
|
243 |
*
|
|
244 |
* Called by iBackupListener when a backup or restore
|
|
245 |
* operation either starts. Shuts down the server.
|
|
246 |
*/
|
|
247 |
void CPosServer::HandleBackupOperationEventL()
|
|
248 |
{
|
|
249 |
|
|
250 |
DEBUG_TRACE("HandleBackupOperationEventL", __LINE__)
|
|
251 |
conn::TBURPartType state = conn::EBURUnset;
|
|
252 |
conn::TBackupIncType type = conn::ENoBackup;
|
|
253 |
iBackupListener->GetCurrentValue(state, type);
|
|
254 |
|
|
255 |
// At the moment it just shuts down if backup/restore is in progress
|
|
256 |
if ((state != conn::EBURUnset) && (state != conn::EBURNormal))
|
|
257 |
{
|
|
258 |
iSessionIter.SetToFirst();
|
|
259 |
CPosSession* session = static_cast <CPosSession*> (iSessionIter++);
|
|
260 |
while (session)
|
|
261 |
{
|
|
262 |
session->NotifyServerShutdown();
|
|
263 |
session = static_cast <CPosSession*> (iSessionIter++);
|
|
264 |
}
|
|
265 |
|
|
266 |
// Shutdown the server by shutting down the active scheduler.
|
|
267 |
CActiveScheduler::Stop();
|
|
268 |
}
|
|
269 |
else
|
|
270 |
{
|
|
271 |
iBackupListener->Start(*this); // continue listening
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|
|
275 |
/**
|
|
276 |
* From CServer2
|
|
277 |
*/
|
|
278 |
CSession2* CPosServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
|
|
279 |
{
|
|
280 |
// Check we're the right version
|
|
281 |
TVersion version(KPosMajorVersionNumber,
|
|
282 |
KPosMinorVersionNumber,
|
|
283 |
KPosBuildVersionNumber);
|
|
284 |
if (!User::QueryVersionSupported(version, aVersion))
|
|
285 |
{
|
|
286 |
User::Leave(KErrNotSupported);
|
|
287 |
}
|
|
288 |
|
|
289 |
// Make new session
|
|
290 |
CPosSession* newSession =
|
|
291 |
CPosSession::NewL(
|
|
292 |
*(const_cast<CPosServer*>(this)),
|
|
293 |
*iModuleSettings,
|
|
294 |
*iModulesStatus,
|
|
295 |
*iLocMonitorReqHandlerHub);
|
|
296 |
|
|
297 |
return newSession;
|
|
298 |
}
|
|
299 |
|
|
300 |
/**
|
|
301 |
* From CPolicyServer
|
|
302 |
*/
|
|
303 |
CPolicyServer::TCustomResult CPosServer::CustomSecurityCheckL(const RMessage2& /*aMsg*/, TInt& /*aAction*/,TSecurityInfo& /*aMissing*/)
|
|
304 |
{
|
|
305 |
DEBUG_TRACE("CustomSecurityCheck", __LINE__)
|
|
306 |
return CPolicyServer::EFail;
|
|
307 |
}
|
|
308 |
|
|
309 |
/**
|
|
310 |
* Increment number of sessions
|
|
311 |
*/
|
|
312 |
void CPosServer::IncrementSessions()
|
|
313 |
{
|
|
314 |
DEBUG_TRACE("IncrementSessions", __LINE__)
|
|
315 |
|
|
316 |
iNumSessions++;
|
|
317 |
iShutdown->Cancel();
|
|
318 |
}
|
|
319 |
|
|
320 |
/**
|
|
321 |
* Decrement number of sessions
|
|
322 |
*/
|
|
323 |
void CPosServer::DecrementSessions()
|
|
324 |
{
|
|
325 |
DEBUG_TRACE("DecrementSessions", __LINE__)
|
|
326 |
|
|
327 |
// This panic handles an internal error.
|
|
328 |
__ASSERT_DEBUG(iNumSessions > 0,
|
|
329 |
DebugPanic(EPosServerPanicSessionsCountInconsistency));
|
|
330 |
|
|
331 |
if (--iNumSessions == 0)
|
|
332 |
{
|
|
333 |
iShutdown->Start(iServerShutdownDelay);
|
|
334 |
}
|
|
335 |
}
|
|
336 |
|
|
337 |
TBool CPosServer::FindRootProcess()
|
|
338 |
{
|
|
339 |
_LIT(KLbsRootProcessName, "lbsroot.exe*");
|
|
340 |
TInt err(KErrNotFound);
|
|
341 |
TFullName fullName;
|
|
342 |
TFindProcess processFinder(KLbsRootProcessName);
|
|
343 |
while (err = processFinder.Next(fullName), err == KErrNone)
|
|
344 |
{
|
|
345 |
RProcess process;
|
|
346 |
TInt processOpenErr = process.Open(processFinder);
|
|
347 |
if (processOpenErr == KErrNone)
|
|
348 |
{
|
|
349 |
TExitType exitType = process.ExitType();
|
|
350 |
if (exitType == EExitPending)
|
|
351 |
{
|
|
352 |
// Found a running instance of lbsroot.exe,
|
|
353 |
return ETrue;
|
|
354 |
}
|
|
355 |
}
|
|
356 |
process.Close();
|
|
357 |
}
|
|
358 |
|
|
359 |
return EFalse;
|
|
360 |
}
|
|
361 |
// End of File
|
|
362 |
|