|
1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // serverside.cpp |
|
15 // server side exmaple of how to use the abstract server framework |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32debug.h> |
|
20 #include "lbstestsession.h" |
|
21 #include "lbstestmessageenums.h" |
|
22 #include "lbssystemcontroller.h" |
|
23 #include "tprocessstartparams.h" |
|
24 #include "cprocesslaunch.h" |
|
25 |
|
26 |
|
27 /* Called by the CServer2 code to complete construction of the session |
|
28 */ |
|
29 void CLbsTestSession::CreateL() |
|
30 { |
|
31 CSecureSessionBase::CreateL(); // MUST do this |
|
32 } |
|
33 |
|
34 /* Service new client requests. |
|
35 */ |
|
36 void CLbsTestSession::DispatchL(const RMessage2& aMessage) |
|
37 { |
|
38 switch (aMessage.Function()) |
|
39 { |
|
40 case ELbsTestStopLbsSystem: |
|
41 { |
|
42 StopLbsSystem(aMessage); |
|
43 break; |
|
44 } |
|
45 case ELbsTestStartLbsSystem: |
|
46 { |
|
47 StartLbsSystem(aMessage); |
|
48 break; |
|
49 } |
|
50 case ELbsTestResetLbsSystem: |
|
51 { |
|
52 ResetLbsSystem(aMessage); |
|
53 break; |
|
54 } |
|
55 default: |
|
56 { |
|
57 aMessage.Complete(KErrNotSupported); |
|
58 break; |
|
59 } |
|
60 } |
|
61 } |
|
62 |
|
63 /* Handle leaves from DispatchL |
|
64 */ |
|
65 void CLbsTestSession::DispatchError(const RMessage2& /*aMessage*/, const TInt /*aError*/) |
|
66 { |
|
67 // Do nothing; leave error handling to the default behaviour |
|
68 } |
|
69 |
|
70 /* Force the LBS system to stop. |
|
71 |
|
72 THIS FUNCTION SHOULD ONLY EVER BE USED FOR TEST PURPOSES. |
|
73 |
|
74 This function will tell LbsRoot to stop the LBS system immediately. |
|
75 It will not check to see if there are any active requests still |
|
76 being processed. |
|
77 */ |
|
78 void CLbsTestSession::StopLbsSystem(const RMessage2& aMessage) |
|
79 { |
|
80 TInt err(KErrUnknown); |
|
81 RLbsSystemController systemController; |
|
82 |
|
83 // Open the system controller interface |
|
84 RProcess process; |
|
85 systemController.OpenL(process.SecureId()); |
|
86 CleanupClosePushL(systemController); |
|
87 |
|
88 // Logon to the root process to detect when it has exited |
|
89 if (FindRootProcess(process)) |
|
90 { |
|
91 TRequestStatus status; |
|
92 process.Logon(status); |
|
93 |
|
94 // Force a complete close down of LBS |
|
95 switch (systemController.RequestCompleteCloseDown()) |
|
96 { |
|
97 case ELbsCloseDownRejected: |
|
98 { |
|
99 err = KErrInUse; |
|
100 process.LogonCancel(status); |
|
101 break; |
|
102 } |
|
103 case ELbsCloseDownComplete: |
|
104 { |
|
105 err = KErrNone; |
|
106 break; |
|
107 } |
|
108 case ELbsCloseDownRootNotFound: |
|
109 { |
|
110 err = KErrDied; |
|
111 process.LogonCancel(status); |
|
112 break; |
|
113 } |
|
114 } |
|
115 |
|
116 User::WaitForRequest(status); |
|
117 process.Close(); |
|
118 } |
|
119 |
|
120 /* Wait until the LBS Root process has definitely gone down */ |
|
121 while(FindRootProcess(process)) |
|
122 /* do nothing ... */; |
|
123 |
|
124 CleanupStack::PopAndDestroy(&systemController); |
|
125 aMessage.Complete(err); |
|
126 } |
|
127 |
|
128 /* Start the LBS system |
|
129 |
|
130 THIS FUNCTION SHOULD ONLY EVER BE USED FOR TEST PURPOSES. |
|
131 |
|
132 If LbsRoot is not running then this function will start it. |
|
133 If LbsRoot is already running then this function will request |
|
134 it to start the system. |
|
135 */ |
|
136 void CLbsTestSession::StartLbsSystem(const RMessage2& aMessage) |
|
137 { |
|
138 TProcessStartParams params; |
|
139 _LIT(KLbsRootFileName, "\\sys\\bin\\lbsroot.exe"); |
|
140 _LIT(KLbsRootProcessName, "lbsroot.exe"); |
|
141 params.SetProcessFileName(KLbsRootFileName); |
|
142 params.SetProcessName(KLbsRootProcessName); |
|
143 params.SetRendezvousRequired(ETrue); |
|
144 TInt err = CProcessLaunch::ProcessLaunch(params); |
|
145 |
|
146 aMessage.Complete(err); |
|
147 } |
|
148 |
|
149 /* Reset the internal state of the LBS system |
|
150 |
|
151 THIS FUNCTION SHOULD ONLY EVER BE USED FOR TEST PURPOSES. |
|
152 |
|
153 This function tells the LBS system to reset its internal state |
|
154 and caches. Currently this means that: |
|
155 - The assistance data cache between lbsnetgateway and lbsagpsmanager is cleared. |
|
156 */ |
|
157 void CLbsTestSession::ResetLbsSystem(const RMessage2& aMessage) |
|
158 { |
|
159 RLbsSystemController systemController; |
|
160 |
|
161 // Open the system controller interface |
|
162 RProcess process; |
|
163 systemController.OpenL(process.SecureId()); |
|
164 CleanupClosePushL(systemController); |
|
165 |
|
166 // request a reset of the LBS system |
|
167 systemController.RequestSystemReset(); |
|
168 |
|
169 CleanupStack::PopAndDestroy(&systemController); |
|
170 aMessage.Complete(KErrNone); |
|
171 } |
|
172 |
|
173 TBool CLbsTestSession::FindRootProcess(RProcess& aProcess) |
|
174 { |
|
175 _LIT(KLbsRootProcessName, "lbsroot.exe*"); |
|
176 TInt err(KErrNotFound); |
|
177 TFullName fullName; |
|
178 TFindProcess processFinder(KLbsRootProcessName); |
|
179 while (err = processFinder.Next(fullName), err == KErrNone) |
|
180 { |
|
181 RProcess process; |
|
182 TInt processOpenErr = process.Open(processFinder); |
|
183 if (processOpenErr == KErrNone) |
|
184 { |
|
185 TExitType exitType = process.ExitType(); |
|
186 if (exitType == EExitPending) |
|
187 { |
|
188 // Found a running instance of lbsroot.exe, |
|
189 aProcess = process; |
|
190 return ETrue; |
|
191 } |
|
192 } |
|
193 process.Close(); |
|
194 } |
|
195 |
|
196 return EFalse; |
|
197 } |