|
1 /* |
|
2 * Copyright (c) 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 "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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 |
|
23 #include "iaupdateselfupdaterctrl.h" |
|
24 #include "iaupdatenode.h" |
|
25 #include "iaupdatebasenode.h" |
|
26 #include "iaupdatependingnodesfile.h" |
|
27 #include "iaupdateridentifier.h" |
|
28 #include "iaupdaterestartinfo.h" |
|
29 #include "iaupdaterendezvous.h" |
|
30 #include "iaupdateselfupdaterobserver.h" |
|
31 #include "iaupdatedebug.h" |
|
32 |
|
33 // Self updater file handling objects |
|
34 #include "iaupdaterfilelistfile.h" |
|
35 |
|
36 // Self updater header for udpater constants |
|
37 #include "iaupdaterdefs.h" |
|
38 |
|
39 |
|
40 CIAUpdateSelfUpdaterCtrl* CIAUpdateSelfUpdaterCtrl::NewL( |
|
41 MIAUpdateSelfUpdaterObserver& aObserver ) |
|
42 { |
|
43 CIAUpdateSelfUpdaterCtrl* self = |
|
44 CIAUpdateSelfUpdaterCtrl::NewLC( aObserver ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 CIAUpdateSelfUpdaterCtrl* CIAUpdateSelfUpdaterCtrl::NewLC( |
|
51 MIAUpdateSelfUpdaterObserver& aObserver ) |
|
52 { |
|
53 CIAUpdateSelfUpdaterCtrl* self = |
|
54 new( ELeave ) CIAUpdateSelfUpdaterCtrl( aObserver ); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 CIAUpdateSelfUpdaterCtrl::CIAUpdateSelfUpdaterCtrl( |
|
62 MIAUpdateSelfUpdaterObserver& aObserver ) |
|
63 : CBase(), |
|
64 iObserver( aObserver ) |
|
65 { |
|
66 |
|
67 } |
|
68 |
|
69 |
|
70 void CIAUpdateSelfUpdaterCtrl::ConstructL() |
|
71 { |
|
72 iRendezvous = CIAUpdateRendezvous::NewL( *this ); |
|
73 iFile = CIAUpdaterFileListFile::NewL(); |
|
74 } |
|
75 |
|
76 |
|
77 CIAUpdateSelfUpdaterCtrl::~CIAUpdateSelfUpdaterCtrl() |
|
78 { |
|
79 delete iRendezvous; |
|
80 delete iFile; |
|
81 } |
|
82 |
|
83 |
|
84 TBool CIAUpdateSelfUpdaterCtrl::DataExists() const |
|
85 { |
|
86 TInt count( iFile->FileList().Count() ); |
|
87 if ( count == 0 ) |
|
88 { |
|
89 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::DataExists no data"); |
|
90 return EFalse; |
|
91 } |
|
92 else |
|
93 { |
|
94 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::DataExists count: %d", count ); |
|
95 return ETrue; |
|
96 } |
|
97 } |
|
98 |
|
99 |
|
100 TBool CIAUpdateSelfUpdaterCtrl::StartL( |
|
101 TInt aIndex, |
|
102 TInt aTotalCount, |
|
103 const RPointerArray< MIAUpdateNode >& aPendingNodes, |
|
104 TBool aSilent ) |
|
105 { |
|
106 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartL begin"); |
|
107 |
|
108 if ( !DataExists() ) |
|
109 { |
|
110 // Nothing to do. |
|
111 return EFalse; |
|
112 } |
|
113 |
|
114 |
|
115 // Set the information if the dialogs should be shown or |
|
116 // if the operation should be silent. Also,set the index |
|
117 // and total count info. |
|
118 // Rest has been set before. |
|
119 File().SetSilent( aSilent ); |
|
120 File().SetPckgStartIndex( aIndex ); |
|
121 File().SetTotalPckgCount( aTotalCount ); |
|
122 |
|
123 // Write data into the file for the self updater to use. |
|
124 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartL write file"); |
|
125 File().WriteDataL(); |
|
126 |
|
127 // Now, that the data is written, reset filelist |
|
128 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartL reset file"); |
|
129 File().Reset(); |
|
130 |
|
131 |
|
132 // Save the pending node infromation |
|
133 CIAUpdatePendingNodesFile* pendingNodesFile( |
|
134 CIAUpdatePendingNodesFile::NewLC() ); |
|
135 pendingNodesFile->SetIndex( aIndex ); |
|
136 for ( TInt i = 0; i < aPendingNodes.Count(); ++i ) |
|
137 { |
|
138 MIAUpdateNode* node( aPendingNodes[ i ] ); |
|
139 MIAUpdateBaseNode& baseNode( node->Base() ); |
|
140 CIAUpdaterIdentifier* identifier( CIAUpdaterIdentifier::NewLC() ); |
|
141 identifier->SetUid( baseNode.Uid() ); |
|
142 identifier->SetIdL( baseNode.MetaId() ); |
|
143 identifier->SetNamespaceL( baseNode.MetaNamespace() ); |
|
144 pendingNodesFile->PendingNodes().AppendL( identifier ); |
|
145 CleanupStack::Pop( identifier ); |
|
146 } |
|
147 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartL write pending nodes file"); |
|
148 pendingNodesFile->WriteDataL(); |
|
149 CleanupStack::PopAndDestroy( pendingNodesFile ); |
|
150 |
|
151 |
|
152 StartUpdaterProcessL(); |
|
153 |
|
154 |
|
155 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartL end"); |
|
156 |
|
157 return ETrue; |
|
158 } |
|
159 |
|
160 |
|
161 void CIAUpdateSelfUpdaterCtrl::Reset() |
|
162 { |
|
163 File().Reset(); |
|
164 } |
|
165 |
|
166 |
|
167 void CIAUpdateSelfUpdaterCtrl::AddFileListL( |
|
168 CIAUpdaterFileList* aFileList ) |
|
169 { |
|
170 // Notice, that the ownership is transferred here. |
|
171 File().FileList().AppendL( aFileList ); |
|
172 } |
|
173 |
|
174 |
|
175 CIAUpdateRestartInfo* CIAUpdateSelfUpdaterCtrl::SelfUpdateRestartInfo() |
|
176 { |
|
177 CIAUpdateRestartInfo* info( NULL ); |
|
178 |
|
179 TRAP_IGNORE( info = CIAUpdateRestartInfo::NewL() ); |
|
180 |
|
181 return info; |
|
182 } |
|
183 |
|
184 |
|
185 void CIAUpdateSelfUpdaterCtrl::RendezvousComplete( |
|
186 TInt aErrorCode ) |
|
187 { |
|
188 // Self updater finished its job and informed about it by setting the |
|
189 // rendezvous complete. |
|
190 Observer().SelfUpdaterComplete( aErrorCode ); |
|
191 } |
|
192 |
|
193 |
|
194 MIAUpdateSelfUpdaterObserver& CIAUpdateSelfUpdaterCtrl::Observer() |
|
195 { |
|
196 return iObserver; |
|
197 } |
|
198 |
|
199 |
|
200 CIAUpdaterFileListFile& CIAUpdateSelfUpdaterCtrl::File() |
|
201 { |
|
202 return *iFile; |
|
203 } |
|
204 |
|
205 |
|
206 CIAUpdateRendezvous& CIAUpdateSelfUpdaterCtrl::RendezvousListener() |
|
207 { |
|
208 return *iRendezvous; |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL() |
|
214 // |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL() |
|
218 { |
|
219 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL begin"); |
|
220 |
|
221 // Start IAD Update |
|
222 // The application is started here by using process handle. |
|
223 // This way we get the process id, which is required for the |
|
224 // rendezvous listener. |
|
225 RProcess process; |
|
226 CleanupClosePushL( process ); |
|
227 // Create the process |
|
228 User::LeaveIfError( |
|
229 process.Create( IAUpdaterDefs::KIAUpdaterExe, KNullDesC ) ); |
|
230 RendezvousListener().StartL( process.Id() ); |
|
231 // Start executing the process. |
|
232 process.Resume(); |
|
233 CleanupStack::PopAndDestroy( &process ); |
|
234 |
|
235 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterCtrl::StartUpdaterProcessL end"); |
|
236 } |