|
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 "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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include "sysmoncliserv.h" |
|
22 #include "sysmonserver.h" |
|
23 #include "monitor.h" |
|
24 #include "sysmonservsess.h" |
|
25 #include "timerlist.h" |
|
26 |
|
27 #include "shmadebug.h" |
|
28 #include "shmapanic.h" |
|
29 |
|
30 // The process which requests for cancelling all the outstanding monitors should have |
|
31 // the SSM server secure UID. |
|
32 #define KSsmSecureId 0x2000D75B |
|
33 const TInt KSecurityCheckForRequest = 0; |
|
34 |
|
35 // ------------------- Policy Server Security Setup ---------------------- |
|
36 |
|
37 const TUint KRangeCount = 3; |
|
38 const TInt KRanges[KRangeCount] = |
|
39 { |
|
40 EMonitor, //range: EMonitor...(ECancelAllMonitors-1) inclusive |
|
41 ECancelAllMonitors, |
|
42 EMaxSysMonMessage |
|
43 }; |
|
44 |
|
45 /** |
|
46 Specifies the appropriate action for each range in KRanges. |
|
47 The nth element of KElementsIndex specifies the appropriate action for the nth range in KRanges. |
|
48 */ |
|
49 const TUint8 KElementsIndex[KRangeCount] = |
|
50 { |
|
51 CPolicyServer::EAlwaysPass, //Message is processed as normal; either by passing it to the ServiceL() method of a session |
|
52 KSecurityCheckForRequest, |
|
53 CPolicyServer::ENotSupported |
|
54 }; |
|
55 |
|
56 /** |
|
57 Array containing the different security checks performed by this server |
|
58 */ |
|
59 const CPolicyServer::TPolicyElement KPolicyElements[] = |
|
60 { |
|
61 {_INIT_SECURITY_POLICY_S0(KSsmSecureId), CPolicyServer::EFailClient} |
|
62 }; |
|
63 |
|
64 /** |
|
65 Setup a security policy that always allows connection requests for all requests. |
|
66 */ |
|
67 const CPolicyServer::TPolicy KSysmonServerPolicy = |
|
68 { |
|
69 CPolicyServer::EAlwaysPass, // Always allow connection requests |
|
70 KRangeCount, |
|
71 KRanges, |
|
72 KElementsIndex, |
|
73 KPolicyElements |
|
74 }; |
|
75 |
|
76 CSysMonServer* CSysMonServer::NewLC() |
|
77 { |
|
78 CSysMonServer* server = new(ELeave) CSysMonServer(); |
|
79 CleanupStack::PushL(server); |
|
80 server->ConstructL(); |
|
81 return server; |
|
82 } |
|
83 |
|
84 |
|
85 void CSysMonServer::ConstructL() |
|
86 { |
|
87 StartL(KSysMonServerName); |
|
88 } |
|
89 |
|
90 |
|
91 CSysMonServer::CSysMonServer() |
|
92 :CPolicyServer(EPriorityHigh, KSysmonServerPolicy), |
|
93 iShutDownInProgress(EFalse), |
|
94 iMonitors(CMonitor::iOffset), |
|
95 iIter(iMonitors) |
|
96 { |
|
97 } |
|
98 |
|
99 |
|
100 CSysMonServer::~CSysMonServer() |
|
101 { |
|
102 CancelAllMonitors(); |
|
103 } |
|
104 |
|
105 TBool CSysMonServer::ShutDownInProgress() const |
|
106 { |
|
107 return iShutDownInProgress; |
|
108 } |
|
109 |
|
110 void CSysMonServer::CancelAllMonitors() |
|
111 { |
|
112 //timerlist has to be deleted before cancelling the monitors, otherwise the system would crash |
|
113 //in case the time callback is called after the monitor is deleted. |
|
114 delete iTimerList; |
|
115 iTimerList = NULL; |
|
116 |
|
117 DEBUGPRINT1(_L("CSysMonServer CancelAllMonitors")); |
|
118 iShutDownInProgress = ETrue; |
|
119 |
|
120 iIter.SetToFirst(); |
|
121 CMonitor *monitor = NULL; |
|
122 while ((monitor = iIter++) != NULL) |
|
123 { |
|
124 iMonitors.Remove(*monitor); // removing each of the monitors from the list |
|
125 delete monitor; // delete will also cancel monitoring |
|
126 } |
|
127 } |
|
128 |
|
129 |
|
130 /* |
|
131 Call CSysMonServer::AddMonitorL to add monitor to the linked list. |
|
132 Also calls SetActive() on aMonitor. |
|
133 */ |
|
134 void CSysMonServer::AddAndStartMonitorL(CMonitor* aMonitor) |
|
135 { |
|
136 iIter.SetToFirst(); |
|
137 |
|
138 TProcessId id = aMonitor->ProcessId(); |
|
139 CMonitor *monitor = NULL; |
|
140 while ((monitor = iIter++) != NULL) |
|
141 { |
|
142 if (monitor->ProcessId() == id) // check if the process is already been monitored |
|
143 { |
|
144 DEBUGPRINT1(_L("This process is already been monitored.")); |
|
145 User::Leave(KErrAlreadyExists); |
|
146 } |
|
147 } |
|
148 |
|
149 aMonitor->Start(); // activate the monitoring |
|
150 |
|
151 iMonitors.AddFirst(*aMonitor); |
|
152 CleanupStack::Pop(aMonitor); |
|
153 |
|
154 DEBUGPRINT2(_L("Monitor inserted into SysMon server. ProcessId=%Lu"), id.Id()); |
|
155 } |
|
156 |
|
157 |
|
158 void CSysMonServer::CancelMonitor(const TProcessId& aProcessId) |
|
159 { |
|
160 iIter.SetToFirst(); |
|
161 CMonitor *monitor = NULL; |
|
162 while ((monitor = iIter++) != NULL) |
|
163 { |
|
164 if (monitor->ProcessId() == aProcessId) // find the process in the list |
|
165 { |
|
166 break; |
|
167 } |
|
168 } |
|
169 |
|
170 if (monitor == NULL) |
|
171 { |
|
172 return; |
|
173 } |
|
174 |
|
175 iMonitors.Remove(*monitor);// remove the monitor from the list. |
|
176 delete monitor; // delete will also cancel monitoring |
|
177 } |
|
178 |
|
179 CTimerList& CSysMonServer::TimerListL() |
|
180 { |
|
181 if (iTimerList == NULL) |
|
182 { |
|
183 iTimerList = CTimerList::NewL(EPriorityLow); |
|
184 } |
|
185 |
|
186 return *iTimerList; |
|
187 } |
|
188 |
|
189 |
|
190 CSession2* CSysMonServer::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const |
|
191 { |
|
192 return CSysMonSession::NewL(); |
|
193 } |
|
194 |
|
195 |
|
196 static void RunServerL() |
|
197 // |
|
198 // Perform all server initialisation, in particular creation of the |
|
199 // scheduler and server and then run the scheduler |
|
200 // |
|
201 { |
|
202 DEBUGPRINT1(_L("SysMon: Going to run server")); |
|
203 |
|
204 User::SetCritical(User::ESystemCritical); |
|
205 |
|
206 // create and install the active scheduler we need |
|
207 CActiveScheduler* s = new(ELeave) CActiveScheduler; |
|
208 CleanupStack::PushL(s); |
|
209 CActiveScheduler::Install(s); |
|
210 |
|
211 DEBUGPRINT1(_L("SysMon: Creating Server...")); |
|
212 // create the server (leave it on the cleanup stack) |
|
213 CSysMonServer::NewLC(); |
|
214 |
|
215 DEBUGPRINT1(_L("Doing Rendezvous...")); |
|
216 // Initialisation complete, now signal the client |
|
217 RProcess::Rendezvous(KErrNone); |
|
218 |
|
219 DEBUGPRINT1(_L("SysMon: Starting Scheduler...")); |
|
220 // Ready to run |
|
221 CActiveScheduler::Start(); |
|
222 |
|
223 // Cleanup the server and scheduler |
|
224 CleanupStack::PopAndDestroy(2, s); |
|
225 } |
|
226 |
|
227 TInt E32Main() |
|
228 // |
|
229 // Server process entry-point |
|
230 // |
|
231 { |
|
232 __UHEAP_MARK; |
|
233 |
|
234 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
235 TInt r = KErrNoMemory; |
|
236 if (cleanup) |
|
237 { |
|
238 TRAP(r,RunServerL()); |
|
239 delete cleanup; |
|
240 } |
|
241 |
|
242 __UHEAP_MARKEND; |
|
243 return r; |
|
244 }//lint -e765 -e714 Suppress 'not referenced' and 'could be static' |