|
1 // Copyright (c) 2007-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 <s32strm.h> |
|
17 #include "ssmcommandparameters.h" |
|
18 #include "ssmcommandutilprovider.h" |
|
19 #include <ssm/ssmstartupproperties.h> |
|
20 #include "ssmdebug.h" |
|
21 #include "ssmpanic.h" |
|
22 |
|
23 #include "cmdstartprocess.h" |
|
24 #include "cmdstartapp.h" |
|
25 |
|
26 /** |
|
27 Destructor |
|
28 */ |
|
29 CCmdStarterBase::~CCmdStarterBase() |
|
30 { |
|
31 Cancel(); |
|
32 delete iAppInfo; |
|
33 iProcess.Close(); |
|
34 } |
|
35 |
|
36 /** |
|
37 Execute this command |
|
38 @param aStatus Completed to indicate execution of the next command may begin. |
|
39 @panic ECmdNullPtr if the information used to create command is null |
|
40 */ |
|
41 void CCmdStarterBase::Execute(TRequestStatus& aStatus) |
|
42 { |
|
43 __ASSERT_ALWAYS(iUtilProvider, PanicNow(KPanicCmdStarterBase, ECmdNullPtr)); |
|
44 __ASSERT_ALWAYS(iAppInfo, PanicNow(KPanicCmdStarterBase, ECmdNullPtr)); |
|
45 |
|
46 aStatus = KRequestPending; |
|
47 iExecuteRequest = &aStatus; |
|
48 TPtrC fileName = iAppInfo->FileName(); |
|
49 TPtrC args = iAppInfo->Args(); |
|
50 iExecutionBehaviour = iAppInfo->ExecutionBehaviour(); |
|
51 DEBUGPRINT4(_L("Starting : %S with arguments : %S and Execution behaviour : %d"), &fileName, &args, iExecutionBehaviour); |
|
52 |
|
53 iUtilProvider->StartSafe().Start(*iAppInfo, iProcess, iStatus, iCallerIndex); |
|
54 if (iExecutionBehaviour == ESsmDeferredWaitForSignal) |
|
55 { |
|
56 // complete the command request and initiate execution of next command |
|
57 CompleteExecuteRequest(KErrNone); |
|
58 } |
|
59 SetActive(); |
|
60 } |
|
61 |
|
62 /** |
|
63 Releases resources associated with this BIC |
|
64 */ |
|
65 void CCmdStarterBase::Release() |
|
66 { |
|
67 delete this; |
|
68 } |
|
69 |
|
70 /** |
|
71 Cancels the BIC |
|
72 */ |
|
73 void CCmdStarterBase::ExecuteCancel() |
|
74 { |
|
75 //cancel the outstanding request |
|
76 Cancel(); |
|
77 //and complete the request with KErrCancel |
|
78 CompleteDeferredExecuteRequest(KErrCancel); |
|
79 } |
|
80 |
|
81 /** |
|
82 Returns the type of the BIC |
|
83 @return Type of BIC |
|
84 */ |
|
85 TSsmCommandType CCmdStarterBase::Type() const |
|
86 { |
|
87 return iCommandType; |
|
88 } |
|
89 /** |
|
90 */ |
|
91 void CCmdStarterBase::ExternalizeL(RWriteStream& aWriteStream) const |
|
92 { |
|
93 aWriteStream.WriteInt16L(iSeverity); |
|
94 iAppInfo->ExternalizeL(aWriteStream); |
|
95 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
96 aWriteStream.WriteUint16L(iPriority); |
|
97 #endif |
|
98 } |
|
99 |
|
100 /** |
|
101 Handles command's request completion event. |
|
102 Request for ESsmDeferredWaitForSignal & ESsmFireAndForget is completed in |
|
103 Execute() but completion code will be completed here. |
|
104 */ |
|
105 void CCmdStarterBase::RunL() |
|
106 { |
|
107 TInt err = iStatus.Int(); |
|
108 TPtrC fileName = iAppInfo->FileName(); |
|
109 DEBUGPRINT3(_L("%S started with err : %d "), &fileName, err); |
|
110 SSMLOGLEAVEIFERROR(err); |
|
111 |
|
112 // start monitor if required, for cmds with execution behaviour = ESsmWaitForSignal/ESsmDeferredWaitForSignal |
|
113 // Monitor can not be started for ESsmFireAndForget |
|
114 if ((iAppInfo->ExecutionBehaviour() != ESsmFireAndForget) && iAppInfo->IsMonitoringRequired()) |
|
115 { |
|
116 // sysmon doesn't monitor the applications with deferredwaitforsignal |
|
117 // execution behaviour, so changing it to waitforsignal |
|
118 if (iAppInfo->ExecutionBehaviour() == ESsmDeferredWaitForSignal) |
|
119 { |
|
120 iAppInfo->SetExecutionBehaviour(ESsmWaitForSignal); |
|
121 } |
|
122 DEBUGPRINT2(_L("Starting monitor for %S"), &fileName); |
|
123 iUtilProvider->SysMonSessionL().MonitorL(*iAppInfo, iProcess); |
|
124 } |
|
125 |
|
126 CompleteDeferredExecuteRequest(err); |
|
127 } |
|
128 |
|
129 /** |
|
130 Cancellation of an outstanding request. |
|
131 */ |
|
132 void CCmdStarterBase::DoCancel() |
|
133 { |
|
134 iUtilProvider->StartSafe().StartCancel(iCallerIndex); |
|
135 } |
|
136 |
|
137 /** |
|
138 Complete the command request with aError. It gets called when RunL leaves. |
|
139 @param aError Error code with which RunL has left. |
|
140 @return KErrNone as error is handled in this function. |
|
141 */ |
|
142 TInt CCmdStarterBase::RunError(TInt aError) |
|
143 { |
|
144 DEBUGPRINT2A("CCmdStarterBase::RunError called with reason %d", aError); |
|
145 CompleteDeferredExecuteRequest(aError); |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 /** |
|
150 Constructs the object through read stream. |
|
151 @param aReadStream A read stream containing BIC data |
|
152 */ |
|
153 void CCmdStarterBase::ConstructL(RReadStream& aReadStream) |
|
154 { |
|
155 iAppInfo = CSsmStartupProperties::NewL(); |
|
156 InternalizeL(aReadStream); |
|
157 ValidateL(); //validate command's data |
|
158 } |
|
159 |
|
160 /** |
|
161 Constructs an object from resource file. |
|
162 @param aCommandParameters Object data from a resource file |
|
163 */ |
|
164 void CCmdStarterBase::ConstructL(TSsmCommandParameters& aCommandParameters) |
|
165 { |
|
166 RResourceReader& reader = aCommandParameters.MainReader(); |
|
167 iSeverity = static_cast<TCmdErrorSeverity>(reader.ReadInt16L()); |
|
168 iAppInfo = CSsmStartupProperties::NewL(reader, aCommandParameters.ResourceFile(), Type()); |
|
169 iExecutionBehaviour = iAppInfo->ExecutionBehaviour(); |
|
170 ValidateL(); //validate command's data |
|
171 } |
|
172 |
|
173 |
|
174 /** |
|
175 Constructs an object from aAppInfo. |
|
176 @param aAppInfo Startup properties through which command will be constructed. |
|
177 */ |
|
178 void CCmdStarterBase::ConstructL(const CSsmStartupProperties* aAppInfo) |
|
179 { |
|
180 SSMLOGLEAVEIFTRUE(aAppInfo == NULL, KErrArgument); |
|
181 iAppInfo = CSsmStartupProperties::NewL(*aAppInfo); |
|
182 iExecutionBehaviour = iAppInfo->ExecutionBehaviour(); |
|
183 ValidateL(); //validate command's data |
|
184 } |
|
185 /** |
|
186 Constructs an object from aAppInfo, Must be used only by CLE |
|
187 @param aAppInfo Startup properties through which command will be constructed. |
|
188 @param aFalse is dummy variable to bypass the validation of command |
|
189 */ |
|
190 void CCmdStarterBase::ConstructL(const CSsmStartupProperties *aAppInfo, TBool /*aFalse*/) |
|
191 { |
|
192 SSMLOGLEAVEIFTRUE(aAppInfo == NULL, KErrArgument); |
|
193 iAppInfo = CSsmStartupProperties::NewL(*aAppInfo); |
|
194 iExecutionBehaviour = iAppInfo->ExecutionBehaviour(); |
|
195 } |
|
196 |
|
197 /** |
|
198 Overloaded CTOR |
|
199 @param aCommandType Command type, It can be either ESsmCmdStartApp or ESsmCmdStartProcess |
|
200 */ |
|
201 CCmdStarterBase::CCmdStarterBase(TSsmCommandType aCommandType) |
|
202 : iCommandType(aCommandType) |
|
203 { |
|
204 } |
|
205 |
|
206 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
207 /** |
|
208 Overloaded CTOR |
|
209 @param aCommandType Command type, It can be either ESsmCmdStartApp or ESsmCmdStartProcess |
|
210 @param aSeverity Severity of the command |
|
211 @param aPriority The priority of the command in the list |
|
212 */ |
|
213 CCmdStarterBase::CCmdStarterBase(TSsmCommandType aCommandType, TCmdErrorSeverity aSeverity, const TUint16 aPriority) |
|
214 : CSsmDeferrableCommand(aSeverity, aPriority), iCommandType(aCommandType) |
|
215 { |
|
216 } |
|
217 #endif |
|
218 |
|
219 /** |
|
220 Overloaded CTOR |
|
221 @param aCommandType Command type, It can be either ESsmCmdStartApp or ESsmCmdStartProcess |
|
222 @param aSeverity Severity of the command |
|
223 */ |
|
224 CCmdStarterBase::CCmdStarterBase(TSsmCommandType aCommandType, TCmdErrorSeverity aSeverity) |
|
225 : CSsmDeferrableCommand(aSeverity), iCommandType(aCommandType) |
|
226 { |
|
227 } |
|
228 |
|
229 /** |
|
230 Configures the BIC using data contained in a ReadStream |
|
231 @param aReadStream A read stream containing BIC data |
|
232 */ |
|
233 void CCmdStarterBase::InternalizeL(RReadStream& aReadStream) |
|
234 { |
|
235 iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L()); |
|
236 iAppInfo->InternalizeL(aReadStream); |
|
237 iExecutionBehaviour = iAppInfo->ExecutionBehaviour(); |
|
238 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
239 iPriority = aReadStream.ReadUint16L(); |
|
240 #endif |
|
241 } |
|
242 |
|
243 /** |
|
244 Helper function to validate commands data. |
|
245 @leave KErrArgument If execution behaviour is wrong or FileName() of AppInfo is NULL. |
|
246 */ |
|
247 void CCmdStarterBase::ValidateL() |
|
248 { |
|
249 CSsmDeferrableCommand::ValidateL(); |
|
250 SSMLOGLEAVEIFTRUE(iAppInfo->Retries() < 0, KErrArgument); |
|
251 SSMLOGLEAVEIFTRUE(iAppInfo->FileName() == KNullDesC, KErrArgument); |
|
252 } |