upnpavcontroller/upnpavcontrollerserver/inc/upnpdeviceicondownloader.h
branchIOP_Improvements
changeset 40 08b5eae9f9ff
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_UPNPDEVICEICONDOWNLOADER_H
       
    19 #define C_UPNPDEVICEICONDOWNLOADER_H
       
    20 
       
    21 // Include files
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <httptransferobserver.h>
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class CHttpDownloader;
       
    28 
       
    29 /**
       
    30  * Class for observing device icon download
       
    31  */
       
    32 class MUpnpDeviceIconDownloadObserver
       
    33     {
       
    34 public:
       
    35     /**
       
    36      * Notifies device icon download completed
       
    37      * 
       
    38      * @param aDeviceUuid the device uuid indicates the device the icon belongs
       
    39      * @param aError system wide error code indicates the download status
       
    40      */
       
    41     virtual void DeviceIconDownloadedL( const TDesC8& aDeviceUuid, TInt aError ) = 0;
       
    42     };
       
    43 
       
    44 /**
       
    45  * Class for device icon downloading
       
    46  */
       
    47 class CUpnpDeviceIconDownloader: public CBase,
       
    48                                  public MHttpTransferObserver
       
    49     {
       
    50 
       
    51 public:
       
    52 
       
    53     /**
       
    54      * Static 1st phase constructor
       
    55      * 
       
    56      * @param aObserver download observer
       
    57      * @param aIap used access point
       
    58      * @return new instance
       
    59      */
       
    60     static CUpnpDeviceIconDownloader* NewL(
       
    61             MUpnpDeviceIconDownloadObserver& aObserver,
       
    62             TUint aIap );
       
    63 
       
    64     /**
       
    65      * Destructor
       
    66      */
       
    67     virtual ~CUpnpDeviceIconDownloader();
       
    68     
       
    69 private: // From MHttpTransferObserver
       
    70     void TransferProgress( TAny* aKey, TInt aBytes, TInt aTotalBytes );
       
    71     void ReadyForTransferL( TAny* aKey );
       
    72     void TransferCompleted( TAny* aKey, TInt aStatus );
       
    73 
       
    74 public: // New functions
       
    75     /**
       
    76      * Starts download
       
    77      * 
       
    78      * @param aDeviceUuid uuid of device
       
    79      * @param aDeviceIconUrl url of device icon
       
    80      */
       
    81     void StartDownloadL( const TDesC8& aDeviceUuid, const TDesC8& aDeviceIconUrl );
       
    82 
       
    83     /**
       
    84      * Cancels download
       
    85      * 
       
    86      * @param aDeviceUuid uuid of device
       
    87      */
       
    88     void CancelDownload( const TDesC8& aDeviceUuid );
       
    89 
       
    90     /**
       
    91      * Transfers icon file to the client
       
    92      * 
       
    93      * @param aMessage message from client
       
    94      * @param aSlot message slot to be used
       
    95      * @param aDeviceUuid the device that's icon is transferred
       
    96      */
       
    97     void TransferFileToClientL( const RMessage2& aMessage, TInt aSlot,
       
    98             const TDesC8& aDeviceUuid );
       
    99 
       
   100 private:
       
   101     /**
       
   102      * Private class for download queue handling
       
   103      */    
       
   104     class CEntry : public CBase
       
   105         {
       
   106     public:
       
   107         static CEntry* NewLC( const TDesC8& aDeviceUuid, const TDesC8& aDeviceIconUrl );
       
   108         virtual ~CEntry();
       
   109         inline TPtrC8 DeviceUuid() const { return iDeviceUuid->Des(); }
       
   110         inline TPtrC8 DeviceIconUrl() const { return iDeviceIconUrl->Des(); }
       
   111         static TInt Compare( const TDesC8* aDeviceUuid, const CEntry& aEntry );
       
   112     private:
       
   113         inline CEntry() {}
       
   114         void ConstructL( const TDesC8& aDeviceUuid, const TDesC8& aDeviceIconUrl );
       
   115 
       
   116     private:
       
   117         HBufC8* iDeviceUuid;
       
   118         HBufC8* iDeviceIconUrl;
       
   119         };
       
   120 
       
   121 private:
       
   122     CUpnpDeviceIconDownloader( MUpnpDeviceIconDownloadObserver& aObserver,
       
   123             TUint aIap );
       
   124     void ConstructL();
       
   125     void DownloadNext();
       
   126     void DownloadNextL( CEntry& aNext );
       
   127     void CleanupFilesL();
       
   128     TBool FileExistsL( const TDesC8& aDeviceUuid );
       
   129     void CleanupFilesIfNeededL();
       
   130     void CheckDiskSpaceL();
       
   131     TBool InProgress( const TDesC8& aDeviceUuid );
       
   132 
       
   133 private:
       
   134     MUpnpDeviceIconDownloadObserver& iObserver;
       
   135     TInt iIap;
       
   136     RFs iFs;
       
   137     RPointerArray< CEntry > iQueue;
       
   138     CEntry* iCurrent; // Own, can be NULL
       
   139     CHttpDownloader* iDownloader; // Own
       
   140     TBool iCleanupOnShutdown;
       
   141     };
       
   142 
       
   143 
       
   144 #endif // C_UPNPDEVICEICONDOWNLOADER_H