|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Starts applications |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <apgcli.h> // for RApaLsSession |
|
20 #include <apacmdln.h> // for CApaCommandLine |
|
21 #include "DevEncStarterAppStarter.h" |
|
22 #include "DevEncLog.h" |
|
23 |
|
24 // ================= MEMBER FUNCTIONS ======================= |
|
25 // |
|
26 // ---------------------------------------------------------- |
|
27 // CDevEncStarterStarter::NewL |
|
28 // Instancies CDevEncStarterStarter object |
|
29 // ---------------------------------------------------------- |
|
30 // |
|
31 CDevEncStarterStarter* CDevEncStarterStarter::NewL( MAppStarterCallback* aCallback ) |
|
32 { |
|
33 CDevEncStarterStarter* self = CDevEncStarterStarter::NewLC(aCallback); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 |
|
39 // ---------------------------------------------------------- |
|
40 // CDevEncStarterStarter::NewL |
|
41 // Instancies CDevEncStarterStarter object |
|
42 // ---------------------------------------------------------- |
|
43 // |
|
44 CDevEncStarterStarter* CDevEncStarterStarter::NewLC( MAppStarterCallback* aCallback ) |
|
45 { |
|
46 CDevEncStarterStarter* self = new ( ELeave ) CDevEncStarterStarter( aCallback ); |
|
47 CleanupStack::PushL ( self ); |
|
48 self->ConstructL(); |
|
49 //CleanupStack::Pop(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------- |
|
54 // CDevEncStarterStarter::ConstructL() |
|
55 // Initializes data objects |
|
56 // ---------------------------------------------------------- |
|
57 // |
|
58 void CDevEncStarterStarter::ConstructL() |
|
59 { |
|
60 CActiveScheduler::Add( this ); |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------- |
|
64 // CDevEncStarterStarter::CDevEncStarterStarter() |
|
65 // Constructor |
|
66 // ---------------------------------------------------------- |
|
67 // |
|
68 CDevEncStarterStarter::CDevEncStarterStarter( MAppStarterCallback* aCallback ) |
|
69 : CActive( EPriorityStandard ), |
|
70 iCallback( aCallback ) |
|
71 { |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------- |
|
75 // CDevEncStarterStarter::CDevEncStarterStarter() |
|
76 // Destructor |
|
77 // ---------------------------------------------------------- |
|
78 // |
|
79 CDevEncStarterStarter::~CDevEncStarterStarter() |
|
80 { |
|
81 Cancel(); |
|
82 } |
|
83 |
|
84 // ---------------------------------------------------------- |
|
85 // CDevEncStarterStarter::CanStartAppL() |
|
86 // |
|
87 // ---------------------------------------------------------- |
|
88 // |
|
89 TBool CDevEncStarterStarter::CanStartAppL( const TUint32& aUid ) |
|
90 { |
|
91 DFLOG2( ">>CDevEncStarterStarter::CanStartAppL %x", aUid ); |
|
92 TBool result( EFalse ); |
|
93 RApaLsSession ls; |
|
94 CleanupClosePushL( ls ); |
|
95 User::LeaveIfError( ls.Connect() ); |
|
96 |
|
97 TApaAppInfo appInfo; |
|
98 TInt err = ls.GetAppInfo( appInfo, TUid::Uid( aUid ) ); |
|
99 |
|
100 if ( err == KErrNone ) |
|
101 { |
|
102 result = ETrue; |
|
103 } |
|
104 CleanupStack::PopAndDestroy(); // ls |
|
105 return result; |
|
106 } |
|
107 |
|
108 // ---------------------------------------------------------- |
|
109 // CDevEncStarterStarter::StartAppL() |
|
110 // |
|
111 // ---------------------------------------------------------- |
|
112 // |
|
113 void CDevEncStarterStarter::StartAppL( const TUint32& aUid ) |
|
114 { |
|
115 DFLOG2( ">>CDevEncStarterStarter::StartAppL %x", aUid ); |
|
116 |
|
117 if ( this->IsActive() ) |
|
118 { |
|
119 DFLOG( "Already active" ); |
|
120 return; |
|
121 } |
|
122 |
|
123 RApaLsSession ls; |
|
124 CleanupClosePushL( ls ); |
|
125 User::LeaveIfError( ls.Connect() ); |
|
126 |
|
127 TApaAppInfo appInfo; |
|
128 TInt err = ls.GetAppInfo( appInfo, TUid::Uid( aUid ) ); |
|
129 |
|
130 if ( err == KErrNone ) |
|
131 { |
|
132 CApaCommandLine* apaCommandLine = CApaCommandLine::NewLC(); |
|
133 apaCommandLine->SetExecutableNameL( appInfo.iFullName ); |
|
134 apaCommandLine->SetCommandL( EApaCommandRun ); |
|
135 TThreadId threadId; |
|
136 DFLOG2( "iStatus = %d", iStatus.Int() ); |
|
137 TRequestStatus* status = &iStatus; |
|
138 TInt startErr = ls.StartApp( *apaCommandLine, threadId, status ); |
|
139 DFLOG2( "iStatus after StartApp = %d", iStatus.Int() ); |
|
140 CleanupStack::PopAndDestroy( apaCommandLine ); |
|
141 if ( startErr == KErrNone ) |
|
142 { |
|
143 iAppUidStarting = aUid; |
|
144 SetActive(); |
|
145 } |
|
146 else |
|
147 { |
|
148 DFLOG2( "Start error %d", startErr ); |
|
149 } |
|
150 } |
|
151 else |
|
152 { |
|
153 FLOG2( "GetAppInfo error %d", err ); |
|
154 } |
|
155 CleanupStack::PopAndDestroy(); // ls |
|
156 DFLOG( "<<CDevEncStarterStarter::StartAppL" ); |
|
157 } |
|
158 |
|
159 // ---------------------------------------------------------- |
|
160 // CDevEncStarterStarter::RunError() |
|
161 // CActive Object method |
|
162 // ---------------------------------------------------------- |
|
163 // |
|
164 TInt CDevEncStarterStarter::RunError( TInt aError ) |
|
165 { |
|
166 DFLOG2( "CDevEncStarterStarter::RunError aError = %d", aError ); |
|
167 return aError; |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------- |
|
171 // CDevEncStarterStarter::RunL() |
|
172 // CActive Object method |
|
173 // ---------------------------------------------------------- |
|
174 // |
|
175 void CDevEncStarterStarter::RunL() |
|
176 { |
|
177 DFLOG2( "CDevEncStarterStarter::RunL, status %d", iStatus.Int() ); |
|
178 if ( iStatus.Int() == KErrNone ) |
|
179 { |
|
180 if ( iCallback ) |
|
181 { |
|
182 DFLOG( "Informing callback object" ); |
|
183 iCallback->AppStarted( iAppUidStarting ); |
|
184 } |
|
185 else |
|
186 { |
|
187 DFLOG( "No callback object registered" ); |
|
188 } |
|
189 } |
|
190 else |
|
191 { |
|
192 DFLOG( "No callback informing because of error" ); |
|
193 } |
|
194 iAppUidStarting = 0; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------- |
|
198 // CDevEncStarterStarter::DoCancel() |
|
199 // CActive Object method |
|
200 // ---------------------------------------------------------- |
|
201 // |
|
202 void CDevEncStarterStarter::DoCancel() |
|
203 { |
|
204 } |
|
205 |
|
206 // End of file |
|
207 |