|
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 #include <startupproperties.h> |
|
17 #include <ssm/ssmstartupproperties.h> |
|
18 |
|
19 #include "sysmonclisess.h" |
|
20 #include "sysmoncliserv.h" |
|
21 #include "shmadebug.h" |
|
22 |
|
23 /** |
|
24 Default constructor. |
|
25 Creates an instance of the RSysMonSession class |
|
26 @publishedPartner |
|
27 @released |
|
28 */ |
|
29 EXPORT_C RSysMonSession::RSysMonSession() : RSessionBase() |
|
30 { |
|
31 } |
|
32 |
|
33 /** |
|
34 Opens connection with SysMonServer |
|
35 @return returns KErrNone or an error code. |
|
36 @publishedPartner |
|
37 @released |
|
38 */ |
|
39 EXPORT_C void RSysMonSession::OpenL() |
|
40 { |
|
41 DEBUGPRINT1(_L("SysMonCli: Opening session")); |
|
42 User::LeaveIfError(CreateSession(KSysMonServerName, TVersion(0,0,0), 1)); |
|
43 } |
|
44 |
|
45 /** |
|
46 Closes connection with SysMonServer |
|
47 @publishedPartner |
|
48 @released |
|
49 */ |
|
50 EXPORT_C void RSysMonSession::Close() |
|
51 { |
|
52 DEBUGPRINT1(_L("SysMonCli: Closing session")); |
|
53 RSessionBase::Close(); |
|
54 } |
|
55 |
|
56 /** |
|
57 Used to initiate the monitoring of a started component using CStartupProperties. |
|
58 Example use: |
|
59 @code |
|
60 CStartupProperties* prop = CStartupProperties::NewLC(KFilename, KNullDesC); |
|
61 prop->SetMonitored(ETrue); |
|
62 prop->SetStartupType(EStartApp); |
|
63 prop->SetStartMethod(EWaitForStart); |
|
64 prop->SetNoOfRetries(1); |
|
65 prop->SetTimeout(1000); |
|
66 prop->SetRecoveryParams(EIgnoreOnFailure, 0); |
|
67 iMySysMonSession.MonitorL(*prop, process); |
|
68 CleanupStack::PopAndDestroy(prop); |
|
69 @endcode |
|
70 |
|
71 @param aStartupProperties Properties for the component to be monitored. |
|
72 Number of retries and timeout in @c aStartupProperties should only be used with |
|
73 start-method @c EWaitForStart or @c EFireAndForget. |
|
74 Start-method @c EDeferredWaitForStart can not be used for monitoring. |
|
75 @param aProcess The running instance of the component to be monitored. |
|
76 @param aExecuteRecoveryMethodOnFailure Gives the option to initiate monitoring on an already |
|
77 dead process. If the process is already dead, the monitor will be scheduled to recover |
|
78 the process. The default behaviour is to leave and not allow monitoring to be setup if |
|
79 the process is already dead. |
|
80 @capability ECapabilityProtServ |
|
81 @capability ECapabilityPowerMgmt for ERestartOSWithMode |
|
82 @publishedPartner |
|
83 @deprecated Instead of this use RSysMonSession::MonitorL(const CSsmStartupProperties& aSsmStartupProperties, const RProcess& aProcess, TBool aExecuteRecoveryMethodOnFailure) |
|
84 @leave KErrDied if @c aProcess is no longer running and @c aExecuteRecoveryMethodOnFailure is false |
|
85 @leave KErrArgument if @c aStartupProperties contains invalid argument or if @c aProcess contain NULL handle |
|
86 @leave KErrPermissionDenied if client does not have the requied PlatSec capability |
|
87 @leave KErrAlreadyExists if the process is already registered for monitoring |
|
88 */ |
|
89 EXPORT_C void RSysMonSession::MonitorL(const CStartupProperties& aStartupProperties, const RProcess& aProcess, TBool aExecuteRecoveryMethodOnFailure) |
|
90 { |
|
91 DEBUGPRINT1(_L("SysMonCli: Monitor process using StartupProperties")); |
|
92 DoMonitorL(aStartupProperties, &aProcess, aExecuteRecoveryMethodOnFailure); |
|
93 } |
|
94 |
|
95 /** |
|
96 Used by a started component to initiate self-monitoring using CStartupProperties. |
|
97 |
|
98 @param aStartupProperties Properties for itself. |
|
99 Number of retries and timeout in @c aStartupProperties should only be used with |
|
100 start-method @c EWaitForStart or @c EFireAndForget. |
|
101 Start-method @c EDeferredWaitForStart can not be used for monitoring. |
|
102 @capability ECapabilityProtServ for ERestartOS ,ERestartOSWithMode and ECriticalNoRetries |
|
103 @capability ECapabilityPowerMgmt for ERestartOSWithMode |
|
104 @publishedPartner |
|
105 @deprecated Instead of this use RSysMonSession::MonitorSelfL(const CSsmStartupProperties& aSsmStartupProperties) |
|
106 @leave KErrArgument if @c aStartupProperties contains invalid argument or if @c aProcess contain NULL handle |
|
107 @leave KErrPermissionDenied if client does not have the requied PlatSec capability |
|
108 @leave KErrAlreadyExists if the process is already registered for monitoring |
|
109 */ |
|
110 EXPORT_C void RSysMonSession::MonitorSelfL(const CStartupProperties& aStartupProperties) |
|
111 { |
|
112 DEBUGPRINT1(_L("SysMonCli: Monitor self StartupProperties")); |
|
113 DoMonitorL(aStartupProperties, NULL, EFalse); |
|
114 } |
|
115 |
|
116 /** |
|
117 Used to initiate the monitoring of a started component using CSsmStartupProperties |
|
118 Example use: |
|
119 @code |
|
120 CSsmStartupProperties* prop = CSsmStartupProperties::NewLC(KFilename, KNullDesC); |
|
121 prop->SetCommandTypeL(ESsmCmdStartApp); |
|
122 prop->SetExecutionBehaviour(ESsmWaitForSignal); |
|
123 prop->SetMonitorInfo(ESsmIgnoreOnFailure, 0, 1000, 1); |
|
124 iMySysMonSession.MonitorL(*prop, process); |
|
125 CleanupStack::PopAndDestroy(prop); |
|
126 @endcode |
|
127 |
|
128 @param aSsmStartupProperties Properties for the component to be monitored. |
|
129 Number of retries and timeout in @c aSsmStartupProperties should only be used with |
|
130 start-method @c ESsmWaitForSignal or @c ESsmFireAndForget. |
|
131 Start-method @c ESsmDeferredWaitForSignal can not be used for monitoring. |
|
132 @param aProcess The running instance of the component to be monitored. |
|
133 @param aExecuteRecoveryMethodOnFailure Gives the option to initiate monitoring on an already |
|
134 dead process. If the process is already dead, the monitor will be scheduled to recover |
|
135 the process. The default behaviour is to leave and not allow monitoring to be setup if |
|
136 the process is already dead. |
|
137 @capability ECapabilityProtServ |
|
138 @capability ECapabilityPowerMgmt for ERestartOSWithMode |
|
139 @publishedPartner |
|
140 @released |
|
141 @leave KErrDied if @c aProcess is no longer running and @c aExecuteRecoveryMethodOnFailure is false |
|
142 @leave KErrArgument if @c aSsmStartupProperties contains invalid argument or if @c aProcess contain NULL handle |
|
143 @leave KErrPermissionDenied if client does not have the requied PlatSec capability |
|
144 @leave KErrAlreadyExists if the process is already registered for monitoring |
|
145 */ |
|
146 EXPORT_C void RSysMonSession::MonitorL(const CSsmStartupProperties& aSsmStartupProperties, const RProcess& aProcess, TBool aExecuteRecoveryMethodOnFailure) |
|
147 { |
|
148 DEBUGPRINT1(_L("SysMonCli: Monitor process using SsmStartUpProperties")); |
|
149 // Create an old style startupproperties instance using the SsmStartupProperties |
|
150 CStartupProperties* startupProperties = ChangeToOldStylePropertiesL(aSsmStartupProperties); |
|
151 CleanupStack::PushL(startupProperties); |
|
152 DoMonitorL(*startupProperties, &aProcess, aExecuteRecoveryMethodOnFailure); |
|
153 CleanupStack::PopAndDestroy(startupProperties); |
|
154 } |
|
155 |
|
156 /** |
|
157 Used by a started component to initiate self-monitoring using CSsmStartupProperties |
|
158 |
|
159 @param aSsmStartupProperties Properties for itself. |
|
160 Number of retries and timeout in @c aSsmStartupProperties should only be used with |
|
161 start-method @c ESsmWaitForSignal or @c ESsmFireAndForget. |
|
162 Start-method @c ESsmDeferredWaitForSignal can not be used for monitoring. |
|
163 @capability ECapabilityProtServ for ERestartOS ,ERestartOSWithMode and ECriticalNoRetries |
|
164 @capability ECapabilityPowerMgmt for ERestartOSWithMode |
|
165 @publishedPartner |
|
166 @released |
|
167 @leave KErrArgument if @c aSsmStartupProperties contains invalid argument or if @c aProcess contain NULL handle |
|
168 @leave KErrPermissionDenied if client does not have the requied PlatSec capability |
|
169 @leave KErrAlreadyExists if the process is already registered for monitoring |
|
170 */ |
|
171 EXPORT_C void RSysMonSession::MonitorSelfL(const CSsmStartupProperties& aSsmStartupProperties) |
|
172 { |
|
173 DEBUGPRINT1(_L("SysMonCli: Monitor self using SsmStartUpProperties")); |
|
174 // Create an old style startupproperties instance using the SsmStartupProperties |
|
175 CStartupProperties* startupProperties = ChangeToOldStylePropertiesL(aSsmStartupProperties); |
|
176 CleanupStack::PushL(startupProperties); |
|
177 DoMonitorL(*startupProperties, NULL, EFalse); |
|
178 CleanupStack::PopAndDestroy(startupProperties); |
|
179 } |
|
180 |
|
181 void RSysMonSession::DoMonitorL(const CStartupProperties& aStartupProperties, const RProcess* aProcess, TBool aExecuteRecoveryMethodOnFailure) |
|
182 { |
|
183 User::LeaveIfError(Validate(aStartupProperties)); |
|
184 |
|
185 CBufFlat* const propsBuf = CBufFlat::NewL(aStartupProperties.Size()); |
|
186 CleanupStack::PushL(propsBuf); |
|
187 |
|
188 aStartupProperties.ExternalizeL(*propsBuf); |
|
189 TPtr8 propsPtr(propsBuf->Ptr(0)); |
|
190 |
|
191 #ifdef _DEBUG |
|
192 TPtrC fileName = aStartupProperties.FileName(); |
|
193 DEBUGPRINT2(_L("SysMonCli: Initiating monitor for %S"), &fileName); |
|
194 #endif |
|
195 |
|
196 if (aProcess) |
|
197 { |
|
198 if (aProcess->Handle() == KNullHandle) |
|
199 { |
|
200 User::Leave(KErrArgument); |
|
201 } |
|
202 |
|
203 TPckg<TProcessId> pidPckg(aProcess->Id()); |
|
204 TIpcArgs ipcArgs(&propsPtr, &pidPckg, aExecuteRecoveryMethodOnFailure); |
|
205 User::LeaveIfError(SendReceive(EMonitor, ipcArgs)); |
|
206 } |
|
207 else |
|
208 { |
|
209 TIpcArgs ipcArgs(&propsPtr); |
|
210 User::LeaveIfError(SendReceive(EMonitorSelf, ipcArgs)); |
|
211 } |
|
212 |
|
213 CleanupStack::PopAndDestroy(propsBuf); |
|
214 } |
|
215 |
|
216 /** |
|
217 Used to cancel self-monitoring of a component. |
|
218 |
|
219 This function is to be called by the component being monitored either by calling |
|
220 MonitorL() or MonitorSelfL() function. By calling this function before exiting, |
|
221 System Monitor will cancel the monitor request of the component so that System Monitor |
|
222 will not restart it after it exit. |
|
223 @publishedPartner |
|
224 @released |
|
225 */ |
|
226 EXPORT_C void RSysMonSession::CancelMonitorSelfL() |
|
227 { |
|
228 DEBUGPRINT1(_L("SysMonCli: Cancelling monitor")); |
|
229 User::LeaveIfError(SendReceive(ECancelSelf)); |
|
230 } |
|
231 |
|
232 /** Validate CStartupProperties parameter |
|
233 */ |
|
234 TInt RSysMonSession::Validate(const CStartupProperties& aProp) |
|
235 { |
|
236 if ((aProp.FileName().Length() > 0) && (aProp.Monitored()) && (aProp.StartupType() == EStartProcess || aProp.StartupType() == EStartApp)) |
|
237 { |
|
238 if((aProp.StartMethod() == EFireAndForget) || (aProp.StartMethod() == EWaitForStart)) |
|
239 { |
|
240 if(((aProp.NoOfRetries() >= 0) && (aProp.Timeout() >= 0)) && |
|
241 (aProp.RecoveryMethod() >= EIgnoreOnFailure && aProp.RecoveryMethod() <= ECriticalNoRetries)) |
|
242 { |
|
243 return KErrNone; |
|
244 } |
|
245 } |
|
246 } |
|
247 return KErrArgument; |
|
248 } |
|
249 |
|
250 /** |
|
251 Used to cancel monitoring of all the components during device shutdown/fail |
|
252 |
|
253 This function is to be called only by the ssm server. By calling this function early during device shutdown/fail, |
|
254 System Monitor will cancel all the outstanding monitor requests for all the components so that it will |
|
255 not restart them after the application\process finally exit during the device shutdown. |
|
256 @internalTechnology |
|
257 @released |
|
258 */ |
|
259 EXPORT_C TInt RSysMonSession::CancelAllMonitors() |
|
260 { |
|
261 DEBUGPRINT1(_L("SysMonCli: Cancelling all the monitors")); |
|
262 return SendReceive(ECancelAllMonitors); |
|
263 } |
|
264 |
|
265 /** |
|
266 Creates old style startup properties from the given CSsmStartupProperties. |
|
267 @param aSsmStartupProperties Ssm Startup properties. |
|
268 @return Pointer to newly created CStartupProperties object |
|
269 */ |
|
270 CStartupProperties* RSysMonSession::ChangeToOldStylePropertiesL(const CSsmStartupProperties& aSsmStartupProperties) const |
|
271 { |
|
272 |
|
273 CStartupProperties* startupProperties = CStartupProperties::NewL(aSsmStartupProperties.FileName(), aSsmStartupProperties.Args()); |
|
274 CleanupStack::PushL(startupProperties); |
|
275 const TSsmCommandType cmdType = aSsmStartupProperties.CommandType(); |
|
276 switch (cmdType) |
|
277 { |
|
278 case ESsmCmdStartApp: |
|
279 startupProperties->SetStartupType(EStartApp); |
|
280 //also copy the app specific info |
|
281 startupProperties->SetViewless(aSsmStartupProperties.Viewless()); |
|
282 startupProperties->SetStartInBackground(aSsmStartupProperties.StartInBackground()); |
|
283 break; |
|
284 case ESsmCmdStartProcess: |
|
285 startupProperties->SetStartupType(EStartProcess); |
|
286 break; |
|
287 default: |
|
288 User::Leave(KErrArgument); |
|
289 } |
|
290 startupProperties->SetStartMethod(static_cast<TStartMethod>(aSsmStartupProperties.ExecutionBehaviour())); |
|
291 startupProperties->SetTimeout(aSsmStartupProperties.Timeout()); |
|
292 startupProperties->SetNoOfRetries(aSsmStartupProperties.Retries()); |
|
293 startupProperties->SetMonitored(aSsmStartupProperties.IsMonitoringRequired()); |
|
294 if (aSsmStartupProperties.IsMonitoringRequired()) |
|
295 { |
|
296 TSsmMonitorInfo monitorInfo = aSsmStartupProperties.MonitorInfo(); |
|
297 startupProperties->SetNoOfRetries(monitorInfo.iRetries); |
|
298 startupProperties->SetRecoveryParams(static_cast<TRecoveryMethod>(monitorInfo.iRestartPolicy), monitorInfo.iRestartMode); |
|
299 startupProperties->SetTimeout(monitorInfo.iTimeout); |
|
300 } |
|
301 |
|
302 CleanupStack::Pop(startupProperties); |
|
303 return startupProperties; |
|
304 } |
|
305 |