|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Implementation of the scheduled download plugin* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <ipvideo/CCseScheduledProgram.h> |
|
21 #include <ipvideo/CCseSchedulerAPI.h> |
|
22 #include <ipvideo/MCsePluginObserver.h> |
|
23 #include "IptvDebug.h" |
|
24 #include "iptvscheduleddownloadlugin.h" |
|
25 #include "vcnsscheduleddownloadpluginengine.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KIptvRescheduleInterval( 15 ); |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CIptvSchedulerPlugin::NewL |
|
35 // |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CIptvScheduledDownloadPlugin* CIptvScheduledDownloadPlugin::NewL() |
|
39 { |
|
40 CIptvScheduledDownloadPlugin* self = |
|
41 new (ELeave) CIptvScheduledDownloadPlugin(); |
|
42 |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CIptvScheduledDownloadPlugin::CIptvScheduledDownloadPlugin |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CIptvScheduledDownloadPlugin::CIptvScheduledDownloadPlugin() |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CIptvScheduledDownloadPlugin::~CIptvScheduledDownloadPlugin |
|
57 // |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CIptvScheduledDownloadPlugin::~CIptvScheduledDownloadPlugin() |
|
61 { |
|
62 IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvScheduledDownloadPlugin::~CIptvScheduledDownloadPlugin"); |
|
63 |
|
64 if ( iIsDead ) |
|
65 { |
|
66 *iIsDead = ETrue; |
|
67 } |
|
68 delete iEngine; |
|
69 iEngine = NULL; |
|
70 |
|
71 IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvScheduledDownloadPlugin::~CIptvScheduledDownloadPlugin"); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CIptvScheduledDownloadPlugin::RunTaskL |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CIptvScheduledDownloadPlugin::RunTaskL( CCseScheduledProgram& aProg, |
|
80 MCsePluginObserver* aObserver ) |
|
81 { |
|
82 IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvScheduledDownloadPlugin::RunTaskL"); |
|
83 |
|
84 TBool isDead( EFalse ); |
|
85 |
|
86 iIsDead = &isDead; |
|
87 |
|
88 // Is there already a download going on |
|
89 if (iEngine) |
|
90 { |
|
91 IPTVLOGSTRING_HIGH_LEVEL("CIptvScheduledDownloadPlugin::RunTaskL rescheduling"); |
|
92 |
|
93 // Yes, reschedule this for later time |
|
94 TRAP_IGNORE( RescheduleL( |
|
95 aObserver, |
|
96 aProg, |
|
97 TTimeIntervalMinutes( KIptvRescheduleInterval ) ) ); |
|
98 |
|
99 IPTVLOGSTRING_HIGH_LEVEL("CIptvScheduledDownloadPlugin::RunTaskL rescheduled"); |
|
100 return ; |
|
101 } |
|
102 |
|
103 // Create always new engine, we are not deleted because we might be reused |
|
104 // Engine has callbacks which should not be left on when not needed |
|
105 iEngine = CIptvScheduledDownloadPluginEngine::NewL( *aObserver ); |
|
106 |
|
107 // Pass it through to engine. |
|
108 TInt engineReturnValue = 0; |
|
109 TRAPD( err, iEngine->RunTaskL( aProg, engineReturnValue ) ); |
|
110 |
|
111 // When we come out from RunTaskL it might be that the operation was cancelled |
|
112 // by deleting ScheduledDownloadPlugin. In such case we are now running "dead code" |
|
113 // which means the class is already destroyed, but the stack is still around. We need |
|
114 // to get out from here as soon as possible and avoid changing class internal variables. |
|
115 if( isDead ) |
|
116 { |
|
117 IPTVLOGSTRING_HIGH_LEVEL("CIptvScheduledDownloadPlugin::RunTaskL - RunTaskL aborted, GTFO from here"); |
|
118 return; |
|
119 } |
|
120 |
|
121 if (err) |
|
122 { |
|
123 IPTVLOGSTRING2_HIGH_LEVEL("CIptvScheduledDownloadPlugin::RunTaskL engine finished with error %d ", err); |
|
124 |
|
125 aObserver->PluginCompleted( err ); |
|
126 } |
|
127 |
|
128 // Did the plugin ask for reschedule |
|
129 if ( engineReturnValue == CIptvScheduledDownloadPluginEngine::EReschedule) |
|
130 { |
|
131 // Yes, reschedule this for later time |
|
132 aObserver->PluginCompleted( KErrNone ); |
|
133 RescheduleL( |
|
134 aObserver, aProg, TTimeIntervalMinutes( KIptvRescheduleInterval ) ); |
|
135 } |
|
136 else if ( engineReturnValue == CIptvScheduledDownloadPluginEngine::EDontReschedule ) |
|
137 { |
|
138 // Reschedule is no more possible |
|
139 IPTVLOGSTRING_HIGH_LEVEL( |
|
140 "CIptvScheduledDownloadPlugin::RunTaskL Plugin completed without reschedule" ); |
|
141 |
|
142 aObserver->PluginCompleted( KErrNone ); |
|
143 } |
|
144 else |
|
145 { |
|
146 if (engineReturnValue < KErrNone) |
|
147 { |
|
148 aObserver->PluginCompleted( engineReturnValue ); |
|
149 } |
|
150 } |
|
151 |
|
152 delete iEngine; |
|
153 iEngine = NULL; |
|
154 |
|
155 IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvScheduledDownloadPlugin::RunTaskL"); |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CIptvScheduledDownloadPlugin::RescheduleL |
|
160 // |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CIptvScheduledDownloadPlugin::RescheduleL( |
|
164 MCsePluginObserver* /*aObserver*/, |
|
165 CCseScheduledProgram& aProg, |
|
166 TTimeIntervalMinutes aDelay ) |
|
167 { |
|
168 IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvScheduledDownloadPlugin::RescheduleL"); |
|
169 |
|
170 TTime start; |
|
171 start.UniversalTime(); |
|
172 start += aDelay; |
|
173 |
|
174 // Only reschedule if it fits the slot |
|
175 if (start < aProg.EndTime()) |
|
176 { |
|
177 CCseSchedulerApi* scheduler = CCseSchedulerApi::NewL(); |
|
178 CleanupStack::PushL( scheduler ); |
|
179 |
|
180 CCseScheduledProgram* newSchedule = CCseScheduledProgram::NewL(); |
|
181 CleanupStack::PushL( newSchedule ); |
|
182 |
|
183 newSchedule->SetStartTime( start ); |
|
184 newSchedule->SetEndTime( aProg.EndTime() ); |
|
185 newSchedule->SetAppUid( aProg.AppUid() ); |
|
186 newSchedule->SetPluginUid( aProg.PluginUid() ); |
|
187 newSchedule->SetScheduleType( aProg.ScheduleType() ); |
|
188 newSchedule->SetApplicationDataL( aProg.ApplicationData() ); |
|
189 |
|
190 User::LeaveIfError( scheduler->AddSchedule( *newSchedule ) ); |
|
191 |
|
192 IPTVLOGSTRING_HIGH_LEVEL("CIptvScheduledDownloadPlugin::RescheduleL Rescheduling done"); |
|
193 |
|
194 CleanupStack::PopAndDestroy( newSchedule ); |
|
195 |
|
196 CleanupStack::PopAndDestroy( scheduler ); |
|
197 } |
|
198 |
|
199 IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvScheduledDownloadPlugin::RescheduleL"); |
|
200 } |
|
201 // End of File |