|
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 // |
|
15 |
|
16 #include <apacmdln.h> |
|
17 #include "apstart.h" |
|
18 #include "apststd.h" |
|
19 |
|
20 const TInt KAppArcAppListInitialCompletionTimeout = 10000000; //10s |
|
21 |
|
22 CApaAppStart::CApaAppStart() |
|
23 { |
|
24 } |
|
25 |
|
26 CApaAppStart::~CApaAppStart() |
|
27 { |
|
28 iApaLsSession.Close(); |
|
29 } |
|
30 |
|
31 /** |
|
32 Used to create an instance of @c CApaAppStart class |
|
33 |
|
34 @return An instance of @c CApaAppStart |
|
35 */ |
|
36 EXPORT_C CApaAppStart* CApaAppStart::NewL() |
|
37 { |
|
38 CApaAppStart* self = new(ELeave) CApaAppStart(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 /** |
|
43 Wait for apparc server to complete initial population of its app list. If list |
|
44 population doesn't complete within @c KAppArcAppListInitialCompletionTimeout, |
|
45 this function will leave with KErrTimedOut. |
|
46 |
|
47 @panic If Apsexe.exe isn't started. |
|
48 @leave KErrTimedOut if apparc doesn't complete the initial list population within KAppArcAppListInitialCompletionTimeout. |
|
49 @leave With system-wide error-codes for generic errors. |
|
50 */ |
|
51 void CApaAppStart::WaitForApparcToInitialiseL() |
|
52 { |
|
53 // Make sure we have a usable session... |
|
54 if (iApaLsSession.Handle()==KNullHandle) |
|
55 { |
|
56 const TInt err = iApaLsSession.Connect(); |
|
57 if(err != KErrNone) |
|
58 { |
|
59 Panic(EApsexeNotRunning); |
|
60 } |
|
61 } |
|
62 |
|
63 //...and a timer |
|
64 RTimer timer; |
|
65 User::LeaveIfError(timer.CreateLocal()); |
|
66 CleanupClosePushL(timer); |
|
67 |
|
68 // Request apparc to notify us when the initial list population is complete |
|
69 TRequestStatus apparcStatus; |
|
70 iApaLsSession.RegisterListPopulationCompleteObserver(apparcStatus); |
|
71 |
|
72 // Request a timeout. |
|
73 TRequestStatus timerStatus; |
|
74 timer.After(timerStatus, TTimeIntervalMicroSeconds32(KAppArcAppListInitialCompletionTimeout)); |
|
75 |
|
76 // As soon as either request completes, cancel the other |
|
77 User::WaitForRequest(timerStatus, apparcStatus); |
|
78 if (timerStatus == KRequestPending) |
|
79 { |
|
80 timer.Cancel(); |
|
81 User::WaitForRequest(timerStatus); |
|
82 } |
|
83 else |
|
84 { |
|
85 // Timeout |
|
86 User::LeaveIfError(iApaLsSession.CancelListPopulationCompleteObserver()); |
|
87 User::WaitForRequest(apparcStatus); |
|
88 User::Leave(KErrTimedOut); |
|
89 } |
|
90 |
|
91 CleanupStack::PopAndDestroy(&timer); |
|
92 } |
|
93 |
|
94 /** |
|
95 Set up the CApaCommandLine object which will be used to start the app. |
|
96 */ |
|
97 void CApaAppStart::SetupCommandLineL(CApaCommandLine& aCmdLine, |
|
98 const TDesC& aFileName, |
|
99 const TDesC8& aArgs, |
|
100 TBool aViewLess, |
|
101 TBool aStartInBackground) |
|
102 { |
|
103 |
|
104 aCmdLine.SetExecutableNameL(aFileName); |
|
105 aCmdLine.SetTailEndL(aArgs) ; |
|
106 |
|
107 // Define how the app will be launched |
|
108 if (!aStartInBackground && !aViewLess) |
|
109 { |
|
110 aCmdLine.SetCommandL(EApaCommandRun); |
|
111 } |
|
112 else if (aStartInBackground && !aViewLess) |
|
113 { |
|
114 aCmdLine.SetCommandL(EApaCommandBackground); |
|
115 } |
|
116 else if (!aStartInBackground && aViewLess) |
|
117 { |
|
118 aCmdLine.SetCommandL(EApaCommandRunWithoutViews); |
|
119 } |
|
120 else |
|
121 { |
|
122 aCmdLine.SetCommandL(EApaCommandBackgroundAndWithoutViews); |
|
123 } |
|
124 } |
|
125 |
|
126 /** |
|
127 Start an application as defined by the specified command line information. Feedback about |
|
128 when the application is actually up and running is given via @c aRequestStatusForRendezvous. |
|
129 |
|
130 Rule-based launching and non-native applications are supported only after |
|
131 @c WaitForApparcToInitialiseL has been called. |
|
132 @see struct INIT_APPARC. |
|
133 |
|
134 @param aFileName The full filename of the application. |
|
135 @param aArgs The arguments passed to the application. |
|
136 @param aViewLess Indicates whether the application has a view. |
|
137 @param aStartInBackground Indicates whether the application should start in background. |
|
138 @param aThreadId The id of the main thread for the application. |
|
139 @param aRequestStatusForRendezvous To be used for deferred return of the application startup status. |
|
140 |
|
141 @leave With a system-wide error-code e.g. if @c aFileName doesn't exists or if memory couldn't be allcoated. |
|
142 */ |
|
143 void CApaAppStart::StartAppL(const TDesC& aFileName, |
|
144 const TDesC& aArgs, |
|
145 TBool aViewLess, |
|
146 TBool aStartInBackground, |
|
147 TThreadId& aThreadId, |
|
148 TRequestStatus& aRequestStatusForRendezvous) |
|
149 { |
|
150 DoStartAppL(aFileName, aArgs, aViewLess, aStartInBackground, aThreadId, &aRequestStatusForRendezvous); |
|
151 } |
|
152 |
|
153 |
|
154 /** |
|
155 Start an application as defined by the specified command line information. No feedback is provided |
|
156 about when the application is actually up and running. |
|
157 |
|
158 Rule-based launching and non-native applications are supported only after |
|
159 @c WaitForApparcToInitialiseL has been called. |
|
160 @see struct INIT_APPARC. |
|
161 |
|
162 @param aFileName The full filename of the application. |
|
163 @param aArgs The arguments passed to the application. |
|
164 @param aViewLess Indicates whether the application has a view. |
|
165 @param aStartInBackground Indicates whether the application should start in background. |
|
166 @param aThreadId The id of the main thread for the application. |
|
167 |
|
168 @leave With a system-wide error-code e.g. if @c aFileName doesn't exists or if memory couldn't be allcoated. |
|
169 */ |
|
170 void CApaAppStart::StartAppL(const TDesC& aFileName, |
|
171 const TDesC& aArgs, |
|
172 TBool aViewLess, |
|
173 TBool aStartInBackground, |
|
174 TThreadId& aThreadId) |
|
175 { |
|
176 DoStartAppL(aFileName, aArgs, aViewLess, aStartInBackground, aThreadId, NULL); |
|
177 } |
|
178 |
|
179 |
|
180 void CApaAppStart::DoStartAppL(const TDesC &aFileName, |
|
181 const TDesC& aArgs, |
|
182 TBool aViewLess, |
|
183 TBool aStartInBackground, |
|
184 TThreadId& aThreadId, |
|
185 TRequestStatus* aRequestStatusForRendezvous) |
|
186 { |
|
187 // Create an 8-bit variant of aArgs |
|
188 RBuf writableArgs; |
|
189 writableArgs.CreateL(aArgs); |
|
190 CleanupClosePushL(writableArgs); |
|
191 TPtr8 args8 = writableArgs.Collapse(); |
|
192 |
|
193 CApaCommandLine* const cmdLine = CApaCommandLine::NewLC(); |
|
194 SetupCommandLineL(*cmdLine, aFileName, args8, aViewLess, aStartInBackground) ; |
|
195 |
|
196 User::LeaveIfError(iApaLsSession.StartApp(*cmdLine, aThreadId, aRequestStatusForRendezvous)); |
|
197 |
|
198 CleanupStack::PopAndDestroy(cmdLine); |
|
199 CleanupStack::PopAndDestroy(&writableArgs); |
|
200 } |