|
1 /* |
|
2 * Copyright (c) 2004-2009 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <apgcli.h> |
|
20 #include "daemoninstaller.h" |
|
21 #include "swispubsubdefs.h" |
|
22 #include "log.h" |
|
23 |
|
24 const static TInt KAppListRetryWaitTime = 5000000; // 5 secs |
|
25 _LIT(KMCSisInstaller,"Daemon-Installer"); // Minor-Component name |
|
26 |
|
27 namespace Swi |
|
28 { |
|
29 // Two phased construction |
|
30 |
|
31 CSisInstaller* CSisInstaller::NewL(MDaemonInstallBehaviour* aDaemonBehaviour) |
|
32 { |
|
33 CSisInstaller* self = new (ELeave) CSisInstaller(aDaemonBehaviour); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // Install Request constructor |
|
41 |
|
42 CSisInstaller::CSisInstaller(MDaemonInstallBehaviour* aDaemonBehaviour) : CActive(CActive::EPriorityStandard), |
|
43 iDaemonBehaviour(aDaemonBehaviour), |
|
44 iState(MDaemonInstallBehaviour::EStateVerifyAppCacheList), |
|
45 iFileIndex(0), |
|
46 iTimeStep(KAppListRetryWaitTime) |
|
47 { |
|
48 CActiveScheduler::Add(this); |
|
49 } |
|
50 |
|
51 // Install Request destructor |
|
52 |
|
53 CSisInstaller::~CSisInstaller() |
|
54 { |
|
55 Cancel(); |
|
56 iTimer.Close(); |
|
57 iProperty.Close(); |
|
58 iFilesToInstall.ResetAndDestroy(); |
|
59 iFilesToInstall.Close(); |
|
60 } |
|
61 |
|
62 // 2nd phase construction |
|
63 |
|
64 void CSisInstaller::ConstructL() |
|
65 { |
|
66 User::LeaveIfError(iTimer.CreateLocal()); |
|
67 User::LeaveIfError(iProperty.Attach(KUidSystemCategory,KUidSoftwareInstallKey)); |
|
68 } |
|
69 |
|
70 // Set the location of all sis files and the list of them |
|
71 // also take ownership of the pointers to memory |
|
72 |
|
73 void CSisInstaller::AddFileToInstallL(const TDesC& aFileName) |
|
74 { |
|
75 DEBUG_PRINTF2(_L("SWI Daemon - Queueing presintalled SIS file '%S' for processing"), |
|
76 &aFileName); |
|
77 |
|
78 HBufC* fileName = aFileName.AllocLC(); |
|
79 iFilesToInstall.AppendL(fileName); |
|
80 CleanupStack::Pop(fileName); |
|
81 } |
|
82 |
|
83 // Start the request to process the Sisx file |
|
84 |
|
85 void CSisInstaller::StartInstallingL() |
|
86 { |
|
87 if(iFilesToInstall.Count() > 0) |
|
88 { |
|
89 iState = MDaemonInstallBehaviour::EStateVerifyAppCacheList; |
|
90 ReRequestL(); |
|
91 } |
|
92 } |
|
93 |
|
94 // Requesting an asyncronous timer/subscrive event |
|
95 |
|
96 void CSisInstaller::ReRequestL() |
|
97 { |
|
98 switch (iState) |
|
99 { |
|
100 // Verify the app cache list at time intervals |
|
101 case MDaemonInstallBehaviour::EStateVerifyAppCacheList: |
|
102 iTimer.Cancel(); |
|
103 iTimer.After(iStatus,iTimeStep); |
|
104 SetActive(); |
|
105 break; |
|
106 |
|
107 // Verify software installer property |
|
108 case MDaemonInstallBehaviour::EStateVerifySwisProperty: |
|
109 CompleteSelf(); |
|
110 break; |
|
111 |
|
112 case MDaemonInstallBehaviour::EStateVerifySwisIdle: |
|
113 iProperty.Subscribe(iStatus); |
|
114 SetActive(); |
|
115 break; |
|
116 |
|
117 case MDaemonInstallBehaviour::EStateInstall: |
|
118 CompleteSelf(); |
|
119 break; |
|
120 |
|
121 default: |
|
122 // SisInstaller in an incorrect state |
|
123 User::Panic(KMCSisInstaller,KErrNotSupported); |
|
124 break; |
|
125 } |
|
126 } |
|
127 |
|
128 // Complete the request manually |
|
129 |
|
130 void CSisInstaller::CompleteSelf() |
|
131 { |
|
132 TRequestStatus* status = &iStatus; |
|
133 User::RequestComplete(status,KErrNone); |
|
134 SetActive(); |
|
135 } |
|
136 |
|
137 // Cancel the active request |
|
138 |
|
139 void CSisInstaller::DoCancel() |
|
140 { |
|
141 iProperty.Cancel(); |
|
142 iTimer.Cancel(); |
|
143 } |
|
144 |
|
145 void CSisInstaller::Reset() |
|
146 { |
|
147 Cancel(); |
|
148 iFileIndex = 0; |
|
149 iFilesToInstall.ResetAndDestroy(); |
|
150 } |
|
151 |
|
152 // When the software installer has changed state |
|
153 // attemp to install a sisx file |
|
154 |
|
155 void CSisInstaller::RunL() |
|
156 { |
|
157 if (iStatus.Int() != KErrNone) |
|
158 { |
|
159 User::Leave(iStatus.Int()); // Invoke RunError |
|
160 } |
|
161 |
|
162 switch (iState) |
|
163 { |
|
164 // Check the cached list of applications |
|
165 case MDaemonInstallBehaviour::EStateVerifyAppCacheList: |
|
166 iState = iDaemonBehaviour->VerifyAppCacheListL(); |
|
167 ReRequestL(); |
|
168 break; |
|
169 |
|
170 case MDaemonInstallBehaviour::EStateVerifySwisProperty: |
|
171 iState = iDaemonBehaviour->VerifySwisPropertyL(); |
|
172 ReRequestL(); |
|
173 break; |
|
174 |
|
175 // Check the software installer is not busy |
|
176 case MDaemonInstallBehaviour::EStateVerifySwisIdle: |
|
177 iState = iDaemonBehaviour->VerifySwisIdleL(); |
|
178 ReRequestL(); |
|
179 break; |
|
180 |
|
181 // Install a file |
|
182 case MDaemonInstallBehaviour::EStateInstall: |
|
183 { |
|
184 iSisFile.Copy(*iFilesToInstall[iFileIndex]); |
|
185 iDaemonBehaviour->DoInstallRequestL(iSisFile); |
|
186 if (++iFileIndex < iFilesToInstall.Count()) |
|
187 { |
|
188 iState = MDaemonInstallBehaviour::EStateVerifySwisProperty; |
|
189 CompleteSelf(); |
|
190 } |
|
191 else |
|
192 { |
|
193 // All done |
|
194 iDaemonBehaviour->DoNotifyMediaProcessingComplete(); |
|
195 } |
|
196 |
|
197 break; |
|
198 } |
|
199 |
|
200 // Active object in unknown state |
|
201 default: |
|
202 User::Panic(KMCSisInstaller,KErrNotSupported); |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 // If RunL leaves then ignore errors |
|
208 |
|
209 TInt CSisInstaller::RunError(TInt aError) |
|
210 { |
|
211 DEBUG_PRINTF3(_L8("SWI Daemon - Daemon failed in state %d with code %d"), |
|
212 iState, aError); |
|
213 |
|
214 Reset(); |
|
215 TInt err(KErrNone); |
|
216 if (aError == KErrCancel) |
|
217 { |
|
218 iState = MDaemonInstallBehaviour::EStateVerifyAppCacheList; |
|
219 } |
|
220 return err; |
|
221 } |
|
222 } |