videofeeds/scheduleddlplugin/inc/vcnsscheduleddownloadpluginengine.h
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 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 engine.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #ifndef CIPTVSCHEDULEDDOWNLOADPLUGINENGINE_H
       
    20 #define CIPTVSCHEDULEDDOWNLOADPLUGINENGINE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <e32cmn.h>
       
    26 #include "iptvvodscheduleddownloaddefinitions.h"
       
    27 
       
    28 #include "CIptvVodDlDownloadList.h"
       
    29 #include "CIptvVodDlDownloadListItem.h"
       
    30 #include "CIptvVodDlDownloadEvent.h"
       
    31 #include "CIptvVodDlClient.h"
       
    32 #include "MIptvVodDlClientObserver.h"
       
    33 #include "iptvbatterywatcherobserver.h"
       
    34 #include "iptvphoneregistrationobserver.h"
       
    35 #include "CIptvServiceManagementClient.h"
       
    36 #include "MIptvServiceManagementClientObserver.h"
       
    37 #include "CIptvVodContentClient.h"
       
    38 #include "MIptvVodContentClientObserver.h"
       
    39 #include "CIptvVodContentContentBriefDetails.h"
       
    40 #include "CIptvVodContentCategoryBriefDetails.h"
       
    41 #include "vcnsscheduleddownloadmpxclient.h"
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 
       
    46 // MACROS
       
    47 // None.
       
    48 
       
    49 // DATA TYPES
       
    50 // None.
       
    51 
       
    52 // FUNCTION PROTOTYPES
       
    53 // None.
       
    54 
       
    55 // FORWARD DECLARATIONS
       
    56 class CCseScheduledProgram;
       
    57 class MCsePluginObserver;
       
    58 class CIptvServiceManagementClient;
       
    59 class CIptvVodContentClient;
       
    60 class CIptvServices;
       
    61 class CIptvVodDlDownloadEvent;
       
    62 class CIptvService;
       
    63 class CIptvBatteryWatcher;
       
    64 class CProfileChangeNotifyHandler;
       
    65 class CIptvPhoneRegistrationWatcher;
       
    66 class CVcxNsScheduledDownloadMpxClient;
       
    67 class CIptvVodContentContentBriefDetails;
       
    68 
       
    69 // CLASS DECLARATION    
       
    70 /**
       
    71 *  Plugin for IPTV to handle reminders
       
    72 *
       
    73 *  @lib iptvscheduleddownloadplugin.lib
       
    74 */
       
    75 class CIptvScheduledDownloadPluginEngine :
       
    76             public CTimer, 
       
    77 			public MIptvServiceManagementClientObserver,
       
    78 			public MIptvVodContentClientObserver,
       
    79 			public MVcxNsMpxClientObserver,
       
    80 			public MBatteryWatcherObserver,
       
    81 			public MProfileChangeObserver,
       
    82 			public MPhoneRegistrationWatcherObserver
       
    83 	{
       
    84 	public:
       
    85 
       
    86         /**
       
    87          * Enumerations for return values.
       
    88          */
       
    89 	    enum TPluginResult
       
    90 	        {
       
    91 	        ENoErr = 0,
       
    92 	        EReschedule,
       
    93 	        EDontReschedule
       
    94 	        };
       
    95 	    
       
    96     public: // Constructors and destructor
       
    97 
       
    98         /**
       
    99          * Two-phased constructor.        
       
   100          */
       
   101     	static CIptvScheduledDownloadPluginEngine* NewL( MCsePluginObserver& aObserver );
       
   102     	
       
   103     	/**
       
   104          * C+ destructor
       
   105          */
       
   106     	virtual ~CIptvScheduledDownloadPluginEngine();
       
   107 
       
   108     public: // New methods
       
   109 
       
   110     	/**
       
   111          * Runs scheduled task. Actions to be taken depends on given schedule
       
   112          *
       
   113          * @param aProg Schedule that has fired.
       
   114          * @return ENoErr, EReschedule or general error code.
       
   115          */
       
   116     	void RunTaskL( CCseScheduledProgram& aProg,
       
   117     	               TInt& aEngineReturnValue );
       
   118 
       
   119     private: // from CTimer, CActive
       
   120 
       
   121         /**
       
   122          * Timeout, too long time has been gone without anything going on.
       
   123          */
       
   124         void RunL();
       
   125 
       
   126     private: // from MIptvServiceManagementClientObserver
       
   127 
       
   128         /**
       
   129          * AddServiceResp.
       
   130          * Callback function for AddServiceReq operation.
       
   131          * @param aRespStatus
       
   132          */
       
   133         void AddServiceResp(TRespStatus aRespStatus);
       
   134 
       
   135         /**
       
   136          * UpdateServiceResp.
       
   137          * Callback function for UpdateServiceReq.
       
   138          * @param aRespStatus
       
   139          */
       
   140         void UpdateServiceResp(TRespStatus aRespStatus);
       
   141 
       
   142         /**
       
   143          * DeleteServiceResp.
       
   144          * Callback function for DeleteServiceReq operation.
       
   145          * @param aRespStatus
       
   146          */        
       
   147         void DeleteServiceResp(TRespStatus aRespStatus);
       
   148 
       
   149         /**
       
   150          * GetServicesResp.
       
   151          * Callback function for GetServicesReq() methods.
       
   152          * @param aRespStatus ESucceeded is returned even if no matching
       
   153          *        services were found. In that case the aServicesArray contains
       
   154          *        empty array. If aRespStatus != ESucceeded, aServicesArray
       
   155          *        pointer is NULL.
       
   156          * @param aServicesArray contains array of pointers to descriptors.
       
   157          *        aServicesArray ownership moves from server to client, ie client
       
   158          *        is responsible for freeing the array.
       
   159          *        Array elements are binary descriptors built with CIptvService::GetL() method.
       
   160          *        CIptvService::SetL() method can be used to init CIptvService class with
       
   161          *        array element data.
       
   162          *        In case of error, aServicesArray is NULL.
       
   163          */
       
   164         void GetServicesResp(TRespStatus aRespStatus, 
       
   165                                      CDesC8ArraySeg* aServicesArray);
       
   166 
       
   167         /**
       
   168          * GetUsedIapResp.
       
   169          * Callback function for GetUsedIapReq() method.
       
   170          * @param aIapId IAP ID which client should use when connecting to service.
       
   171          * @param aIapName
       
   172          * @param aConnectionPermission
       
   173          * @param aRespStatus If != ESucceeded, aIapId, aIapName and aConnectionPermission
       
   174          *                    do not contain valid data.
       
   175          */
       
   176         void GetUsedIapResp( TUint32 aIapId,
       
   177             const TDesC& aIapName,
       
   178             CIptvNetworkSelection::TConnectionPermission aConnectionPermission,
       
   179             TBool aWlanWhenGPRS,
       
   180             CIptvNetworkSelection::TRespStatus aRespStatus );
       
   181 
       
   182         /**
       
   183          * ServerShutdownResp.
       
   184          * Callback function for ServerShutdownReq operation.
       
   185          * @param aRespStatus
       
   186          */
       
   187         void ServerShutdownResp(TRespStatus aRespStatus);
       
   188 
       
   189         /**
       
   190          * Service Manager generated events handle function.
       
   191          * @param aEvent 
       
   192          */        
       
   193         void HandleSmEvent(CIptvSmEvent& aEvent);
       
   194 
       
   195 
       
   196     private: // from MIptvVodContentClientObserver
       
   197 
       
   198         /**
       
   199          * Messages from EPG manager are handled here. Messages are defined in CIptvUtil.h
       
   200          * @since            Engine 1.1
       
   201          * @param aMsg       Message 
       
   202          * @param aServiceId Service id.
       
   203          */
       
   204     	void HandleEpgManagerMsgL(
       
   205     	    TInt aMsg,
       
   206     	    TInt aInfo,
       
   207     	    TIptvServiceId aServiceId);
       
   208 
       
   209 
       
   210     private: // from MIptvVodDlClientObserver
       
   211 
       
   212         /**
       
   213          * NOTE: It is not allowed to delete CIptvVodDlClient object from this callback
       
   214          * function. Do it from other event (for example user initiated event or timer event).
       
   215          */
       
   216     	void HandleVodDlDownloadEvent(CIptvVodDlDownloadEvent& aEvent);
       
   217 
       
   218     private: // from MBatteryWatcherObserver
       
   219 
       
   220         /**
       
   221          * This callback will be called when the battery level is low.
       
   222          */
       
   223         void BatteryLow();
       
   224 
       
   225     private: // from MProfileChangeObserver
       
   226 
       
   227         /**
       
   228          * This is a callback function which is called when a active profile event
       
   229          * completes. User must derive his class from MProfileChangeObserver
       
   230          * and implement this method if he is to use notify services.
       
   231          * @since 2.0
       
   232          * @param aProfileEvent Profile event
       
   233          * @param aProfileId Active profile id
       
   234          */
       
   235         void HandleActiveProfileEventL(
       
   236             TProfileEvent aProfileEvent,
       
   237             TInt aProfileId );
       
   238 
       
   239     private: // from MPhoneRegistrationWatcherObserver
       
   240         /**
       
   241          * This callback will be called when the home network state of the phone
       
   242          * registration changes.
       
   243          */
       
   244         void OnHomeNetwork( TBool aOnHomeNetwork );
       
   245 
       
   246 
       
   247     private: // new methods
       
   248     
       
   249    
       
   250 
       
   251         /**
       
   252          * C++ constructor
       
   253          * 
       
   254          * @param aObserver The observer.
       
   255          */
       
   256     	CIptvScheduledDownloadPluginEngine( MCsePluginObserver& aObserver );
       
   257     	
       
   258     	/**
       
   259          * By default Symbian 2nd phase constructor is private.        
       
   260          */
       
   261     	void ConstructL();
       
   262     	
       
   263         /**
       
   264          * Check that battery is ok.
       
   265          * If not, set the error code to KErrBadPower.
       
   266          */
       
   267         void GetBatteryStatus();
       
   268 
       
   269         /**
       
   270          * Cancel downloads. This will be called usually in low power situation.
       
   271          */
       
   272         void CancelDownloads();
       
   273 
       
   274         /**
       
   275          * Get the used IAP and check that it can be used to connect.
       
   276          * @return KErrNone if all is well, system wide error otherwise.
       
   277          */
       
   278         void GetUsableIapL();
       
   279 
       
   280         /**
       
   281          * Get the service id from the scheduled program.
       
   282          *
       
   283          * @param The program where to get the service.
       
   284          * @return The service id.
       
   285          */
       
   286         TInt GetServiceIdL( CCseScheduledProgram& aProg ) const;
       
   287 
       
   288  		/**
       
   289          * Asks server to update the epg.
       
   290          * Blocks until it is either updated or the update failed.
       
   291          * Calls ActiveWait.
       
   292          */
       
   293     	void UpdateEpgL();
       
   294     	
       
   295     	/**
       
   296          * Start or stop active wait. Does not start or stop unnecessarily.
       
   297          *
       
   298          * @param aStart ETrue tor start, EFalse to stop.
       
   299          */
       
   300     	void ActiveWait( TBool aStart );
       
   301 
       
   302     	/**
       
   303          * Start download for single file.
       
   304          *
       
   305          * @param  CIptvVodContentContentBriefDetails*  aContent 
       
   306          * @return General error code.
       
   307          */
       
   308     	TInt StartDownloadL( CIptvVodContentContentBriefDetails*  aContent );
       
   309 
       
   310         /**
       
   311          * Delete the download from the download list if it is there.
       
   312          *
       
   313          * @param aServiceId The service of the downloaded file.
       
   314          * @param aContentId The content id of the downloaded file.
       
   315          * @return ETrue if the download was in the list.
       
   316          */
       
   317         TBool DeleteFromList( TUint32 aServiceId, TUint32 aContentId );
       
   318 
       
   319         /**
       
   320          * Get the service.
       
   321          */
       
   322         void FetchServiceL();
       
   323 
       
   324         /**
       
   325          * Update the epg and start downloads.
       
   326          *
       
   327          * @return Error code if something goes wrong.
       
   328          */
       
   329         TInt LoadContentL();
       
   330 
       
   331         /**
       
   332          * Return ETrue if the given content contains downloadable content.
       
   333          *
       
   334          * @param aContentId The content id.
       
   335          * @return ETrue if the content can be downloaded, EFalse otherwise.
       
   336          */
       
   337         TBool IsDownloadableL( TIptvContentId aContentId );
       
   338 
       
   339         /**
       
   340          * Update the the last successfull download time.
       
   341          *
       
   342          * @param aTimestamp The time when the download started.
       
   343          */
       
   344         void UpdateLastDownloadTimeL( const TTime& aTimestamp );
       
   345 
       
   346         /**
       
   347          * Restart the timeout. If the timeout occurs,
       
   348          * the plugin will be close all downloads and quit with error
       
   349          * KErrTimedOut.
       
   350          * Calling this method prevents timeout occuring.
       
   351          */
       
   352         void RestartTimeoutTimer();
       
   353 
       
   354         /**
       
   355          * Check if we are in offline mode and if so, cause rescheduling.
       
   356          */
       
   357         void CheckOfflineModeL();
       
   358 
       
   359     private: // data
       
   360 
       
   361         /**
       
   362          * The state of the download.
       
   363          */
       
   364         enum TState
       
   365             {
       
   366             EStarted,
       
   367             EUpdatingContentGuide,
       
   368             EGettingContent,
       
   369             ECheckingDownloadedFiles,
       
   370             EDownloadingFiles,
       
   371             EFinished
       
   372             };
       
   373 
       
   374         /**
       
   375          * The state of the download.
       
   376          */
       
   377         TState  iState;
       
   378 
       
   379  		/**
       
   380          * A list of downloads started. Own.
       
   381          */
       
   382     	CIptvVodDlDownloadList* iVodDownloads;
       
   383     	 	
       
   384     	/**
       
   385          * The download client to use. Own.
       
   386          */
       
   387     	CVcxNsScheduledDownloadMpxClient* iVodDlClient;
       
   388 
       
   389         /**
       
   390          * Pointer back to scheduler.
       
   391          */
       
   392     	MCsePluginObserver& iObserver;
       
   393 
       
   394     	/**
       
   395          * Content API client to use. Own.
       
   396          */
       
   397     	CIptvVodContentClient* iIptvVodContentClient;
       
   398 
       
   399     	/**
       
   400          * The Service ID.
       
   401          */
       
   402     	TInt iServiceID;
       
   403 
       
   404         /**
       
   405          * The service management client to use. Own.
       
   406          */
       
   407         CIptvServiceManagementClient* iIptvServiceManagementClient;
       
   408 
       
   409         /**
       
   410          * Member for the callback and other methods to set in error situation.
       
   411          */
       
   412         TInt* iErrorReason;
       
   413 
       
   414         /**
       
   415          * A list of entries under one category. Own.
       
   416          */
       
   417         RPointerArray<CIptvVodContentContentBriefDetails> iEcgList;
       
   418 
       
   419         /**
       
   420          * A list of categories in a service. Own.
       
   421          */
       
   422         RPointerArray<CIptvVodContentCategoryBriefDetails> iCategoryList;
       
   423 
       
   424     	/**
       
   425          * The IAP to use.
       
   426          */
       
   427     	TUint32 iIapId;
       
   428 
       
   429     	/**
       
   430          * The active scheduler wait to use when something needs to be waited.
       
   431          * Own.
       
   432          */
       
   433     	CActiveSchedulerWait* iActiveSchedulerWait;
       
   434 
       
   435         /**
       
   436          * The service. Own.
       
   437          */
       
   438         CIptvService* iService;
       
   439 
       
   440         /**
       
   441          * The battery watcher. Own.
       
   442          */
       
   443          CIptvBatteryWatcher* iBatteryWatcher;
       
   444 
       
   445         /**
       
   446          * The progilfe change watcher. Own.
       
   447          */
       
   448          CProfileChangeNotifyHandler* iProfChangeHandler;
       
   449 
       
   450         /**
       
   451          * The phone registration watcher. Own.
       
   452          */
       
   453          CIptvPhoneRegistrationWatcher* iPhoneRegistrationWatcher;
       
   454 	};
       
   455 
       
   456 #endif // CIPTVSCHEDULEDDOWNLOADPLUGINENGINE_H
       
   457 
       
   458 // End of file.