|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Handles scheduled update, starts fotaserver and request upd |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <schinfo.h> |
|
21 #include <schtask.h> |
|
22 #include <s32file.h> |
|
23 #include <e32math.h> |
|
24 #include <e32cons.h> |
|
25 |
|
26 #include "FotaSchedDebug.h" |
|
27 #include "fotaengine.h" |
|
28 #include "../../inc/FotaIPCTypes.h" |
|
29 |
|
30 // Constants |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // UpdateFirmwareL |
|
34 // |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 LOCAL_D void UpdateFirmwareL(RFile& aTaskFile) |
|
38 { |
|
39 FLOG(_L("fotaschedulehandler UpdateFirmwareL(RFile& aTaskFile)")); |
|
40 TInt err; |
|
41 CFileStore* store; |
|
42 RStoreReadStream instream; |
|
43 // Get tasks from scheduler's store |
|
44 store = CDirectFileStore::FromLC(aTaskFile); |
|
45 instream.OpenLC(*store,store->Root()); |
|
46 TInt count = instream.ReadInt32L(); |
|
47 FLOG(_L("fotaschedulehandler task count %d"),count ); |
|
48 for (TInt i=0;i<count;i++) |
|
49 { |
|
50 CScheduledTask* task = CScheduledTask::NewLC(instream); |
|
51 HBufC* b = const_cast<HBufC*>(&(task->Data())); |
|
52 TPtr ptr = b->Des(); |
|
53 HBufC8* b8 = HBufC8::NewLC( b->Length() ); |
|
54 b8->Des().Copy(ptr); |
|
55 TFotaScheduledUpdate fotareminder(-1,-1); |
|
56 TPckg<TFotaScheduledUpdate> fotareminderpkg(fotareminder); |
|
57 fotareminderpkg.Copy(b8->Des()); |
|
58 CleanupStack::PopAndDestroy( b8 ); |
|
59 FLOG(_L("fotaschedulehandler packageid:%d sched:%d"),fotareminder.iPkgId, fotareminder.iScheduleId); |
|
60 RFotaEngineSession fota; |
|
61 fota.OpenL(); |
|
62 CleanupClosePushL( fota ); |
|
63 err = fota.ScheduledUpdateL (fotareminder); |
|
64 if(err){} // to remove compiler warning |
|
65 FLOG(_L("fotaschedulehandler 2........ err %d"),err); |
|
66 fota.Close(); |
|
67 FLOG(_L("fotaschedulehandler 3 ")); |
|
68 CleanupStack::PopAndDestroy( &fota); |
|
69 CleanupStack::PopAndDestroy(task); |
|
70 } |
|
71 CleanupStack::PopAndDestroy( &instream ); |
|
72 CleanupStack::PopAndDestroy( store ); |
|
73 } |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // ExecuteL |
|
78 // |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 LOCAL_D TInt ExecuteL() |
|
82 { |
|
83 TInt err = KErrNoMemory; |
|
84 |
|
85 RFile file; |
|
86 |
|
87 // Adopt the task file from the Task Scheduler |
|
88 err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(), |
|
89 TScheduledTaskFile::FileHandleIndex()); |
|
90 FLOG(_L(" err %d"),err ); |
|
91 User::LeaveIfError(err); |
|
92 |
|
93 TRAP(err, UpdateFirmwareL(file)); |
|
94 |
|
95 file.Close(); |
|
96 |
|
97 User::LeaveIfError(err); |
|
98 |
|
99 return err; |
|
100 } |
|
101 |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // Execute |
|
105 // |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 LOCAL_D TInt Execute() |
|
109 { |
|
110 FLOG(_L("fotaschedulehandler Execute()")); |
|
111 TInt err = KErrNoMemory; |
|
112 |
|
113 // construct and install active scheduler |
|
114 CActiveScheduler* scheduler = new CActiveScheduler; |
|
115 if (!scheduler) |
|
116 { |
|
117 return err; |
|
118 } |
|
119 CActiveScheduler::Install(scheduler); |
|
120 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
121 if (cleanupStack) |
|
122 { |
|
123 TRAP(err, ExecuteL()); |
|
124 delete cleanupStack; |
|
125 } |
|
126 delete scheduler; |
|
127 return err; |
|
128 } |
|
129 |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // E32Main |
|
133 // |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 GLDEF_C TInt E32Main() |
|
137 { |
|
138 return Execute(); |
|
139 } |
|
140 |
|
141 |
|
142 |