codhandler/codeng/inc/MediaObject.h
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *      Declaration of class CMediaObjectData.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef MEDIA_OBJECT_H
       
    22 #define MEDIA_OBJECT_H
       
    23 
       
    24 // INCLUDES
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <bamdesca.h>
       
    28 #include "CodDefs.h"
       
    29 #include <f32file.h>
       
    30 #include "HttpDownloadData.h"
       
    31 
       
    32 // ================= CONSTANTS =======================
       
    33 /// OMA 1 DD MIME type.
       
    34 _LIT8( KDdDataType, DD_MIME_TYPE );
       
    35 // OMA 2 DD MIME type.
       
    36 _LIT8( KDd2DataType, DD2_MIME_TYPE );
       
    37 
       
    38 // FORWARD DECLARATION
       
    39 
       
    40 class CDesC8ArrayFlat;
       
    41 class CMediaObjectData;
       
    42 typedef RPointerArray<CMediaObjectData> RMediaObjectArray;
       
    43 
       
    44 class CHeaderField;
       
    45 
       
    46 // CLASS DECLARATION
       
    47 
       
    48 /**
       
    49 * COD / DD Data.
       
    50 */
       
    51 NONSHARABLE_CLASS( CMediaObjectData ): public CBase
       
    52     {
       
    53 
       
    54     public:     // Constructors and destructor
       
    55 
       
    56         /**
       
    57         * Two-phased constructor. Leaves on failure.
       
    58         * @return The created COD data.
       
    59         */      
       
    60         IMPORT_C static CMediaObjectData* NewL();
       
    61         
       
    62         /**
       
    63         * Destructor.
       
    64         */      
       
    65         IMPORT_C virtual ~CMediaObjectData();
       
    66         
       
    67     public:     // New methods
       
    68 
       
    69         /**
       
    70         * Check whether COD data is valid (all mandatory values are filled).
       
    71         * @return ETrue if data is valid.
       
    72         */
       
    73         IMPORT_C TBool IsValid() const;
       
    74 
       
    75         /**
       
    76         * Clear everything. Does not free memory, simply sets all descriptors
       
    77         * to zero length.
       
    78         */
       
    79         IMPORT_C void Reset();
       
    80 
       
    81     public:     // Getters
       
    82     
       
    83         /**
       
    84         * Get Name attribute.
       
    85         * @return Name.
       
    86         */
       
    87         IMPORT_C TPtrC Name() const;
       
    88 
       
    89         /**
       
    90         * Get Vendor attribute.
       
    91         * @return Vendor.
       
    92         */
       
    93         IMPORT_C TPtrC Vendor() const;
       
    94 
       
    95         /**
       
    96         * Get Description attribute.
       
    97         * @return Description.
       
    98         */
       
    99         IMPORT_C TPtrC Description() const;
       
   100 
       
   101         /**
       
   102         * Get Url attribute.
       
   103         * @return Url.
       
   104         */
       
   105         IMPORT_C TPtrC8 Url() const;
       
   106 
       
   107         /**
       
   108         * Get Size attribute.
       
   109         * @return Size.
       
   110         */
       
   111         IMPORT_C TInt Size() const;
       
   112         
       
   113         /**
       
   114         * Get Size attribute.
       
   115         * @return Size.
       
   116         */
       
   117         IMPORT_C TInt DownloadedSize() const;
       
   118 
       
   119         /**
       
   120         * Get media state attribute.
       
   121         * @return Size.
       
   122         */
       
   123         IMPORT_C TMediaObjectState State() const;
       
   124                 
       
   125         /**
       
   126         * Get Type attribute.
       
   127         * @return Type.
       
   128         */
       
   129         IMPORT_C TPtrC8 Type() const;
       
   130 
       
   131         /**
       
   132         * Get Type attribute list.
       
   133         * @return Type list.
       
   134         */
       
   135         IMPORT_C const MDesC8Array& Types() const;
       
   136 
       
   137         /**
       
   138         * Get Install-Notify attribute.
       
   139         * @return Install-Notify.
       
   140         */
       
   141         IMPORT_C TPtrC8 InstallNotify() const;
       
   142 
       
   143         /**
       
   144         * Get Next-URL attribute.
       
   145         * @return Next-URL.
       
   146         */
       
   147         IMPORT_C TPtrC8 NextUrl() const;
       
   148 
       
   149         /**
       
   150         * Get Next-URLatError attribute.
       
   151         * @return URLatError.
       
   152         */
       
   153         IMPORT_C TPtrC8 NextUrlAtError() const;
       
   154 
       
   155         /**
       
   156         * Get Info-URL attribute.
       
   157         * @return Info-URL.
       
   158         */
       
   159         IMPORT_C TPtrC8 InfoUrl() const;
       
   160 
       
   161         /**
       
   162         * Get Price attribute.
       
   163         * @return Price.
       
   164         */
       
   165         IMPORT_C TPtrC Price() const;
       
   166 
       
   167         /**
       
   168         * Get Icon attribute.
       
   169         * @return Icon.
       
   170         */
       
   171         IMPORT_C TPtrC8 Icon() const;
       
   172 
       
   173         /**
       
   174         * Get Version attribute (DD specific).
       
   175         * @return Version.
       
   176         */
       
   177         IMPORT_C TPtrC Version() const;
       
   178 
       
   179         /**
       
   180         * Get source URI.
       
   181         * @return Source URI.
       
   182         */
       
   183         IMPORT_C TPtrC8 SourceUri() const;
       
   184 
       
   185         /**
       
   186         * Get Order.
       
   187         * @return ETrue if order tag is "Post", EFails iin case of "any".
       
   188         */
       
   189         IMPORT_C TBool IsPostOrder() const;
       
   190 
       
   191         /**
       
   192         * ProgressiveDownload (DD specific).
       
   193         * @return iProgressiveDl.
       
   194         */
       
   195         IMPORT_C TBool ProgressiveDownload() const;
       
   196 
       
   197         /**
       
   198         * Check if aType appears in the type list.
       
   199         * @param aType Type to find.
       
   200         * @return ETrue if aType appears in the type list.
       
   201         */
       
   202         TBool HasType( const TDesC8& aType ) const;
       
   203 				
       
   204         /**
       
   205         * Get number of elements in the type list.
       
   206         * @return Number of elements.
       
   207         */
       
   208         TInt TypesCount() const;
       
   209 
       
   210        /**
       
   211         * Get updated DD URI attribute. 
       
   212         * @return Size.
       
   213         */
       
   214         IMPORT_C TPtrC8 UpdatedDDUriL() const;
       
   215         
       
   216         /**
       
   217         * Get Full Name (with path) of media object. 
       
   218         * @return iFullName.
       
   219         */
       
   220         TPtrC FullName() const;
       
   221         
       
   222         /**
       
   223         * Get Pausable attribute. 
       
   224         * @return iPausable.
       
   225         */
       
   226         TBool Pausable() const;
       
   227         
       
   228         /**
       
   229         * Check if unique filename is set or not.
       
   230         * @return IsUniqueFilenameSet.
       
   231         */
       
   232         TBool IsUniqueFilenameSet() const;
       
   233 
       
   234     public:		
       
   235     
       
   236         /**
       
   237         * Append information to stored in info file.
       
   238         * @return void
       
   239         * @Added in OMA pause-resume feature
       
   240         */
       
   241 	    void StoreMediaInfoL( TPtr8& aBuf, const CArrayPtrFlat<CHeaderField>* aHeaders ) const;
       
   242 		
       
   243 		/**
       
   244         * Load the information from info file
       
   245         * @return void
       
   246         * @Added in OMA pause-resume feature
       
   247         */
       
   248 	    void LoadMediaInfoL( RFile& aInFile, RFs &aFs, CArrayPtrFlat<CHeaderField>*& aHeaders );
       
   249 	    
       
   250 	    /**
       
   251         * Re-arrange the types so that TYPE at index 0 should match the content-type mentioned in the header of content download
       
   252         * @return void
       
   253         */
       
   254         void ReArrangeTypesL( TInt aIndex );
       
   255                 
       
   256 
       
   257     protected:  // Constructors and destructor
       
   258 
       
   259         /**
       
   260         * Constructor.
       
   261         */      
       
   262         CMediaObjectData();
       
   263         
       
   264         /**
       
   265         * Second phase constructor. Leaves on failure.
       
   266         */      
       
   267         void ConstructL();
       
   268 
       
   269     protected:  // Setters
       
   270     
       
   271         /**
       
   272         * Set Name attribute.
       
   273         * @param Name.
       
   274         * @return ETrue if set, EFalse for invalid data.
       
   275         */
       
   276         TBool SetNameL( const TDesC& aName );
       
   277 
       
   278         /**
       
   279         * Set Description attribute.
       
   280         * @param Description.
       
   281         * @return ETrue if set, EFalse for invalid data.
       
   282         */
       
   283         TBool SetDescriptionL( const TDesC& aDescription );
       
   284 
       
   285         /**
       
   286         * Set Url attribute.
       
   287         * @param Url.
       
   288         * @return ETrue if set, EFalse for invalid data.
       
   289         */
       
   290         TBool SetUrlL( const TDesC& aUrl );
       
   291 
       
   292         /**
       
   293         * Set Size attribute.
       
   294         * @param Size.
       
   295         * @return ETrue if set, EFalse for invalid data.
       
   296         */
       
   297         TBool SetSize( TInt aSize );
       
   298 
       
   299         /**
       
   300         * Set Downloaded size attribute.
       
   301         * @param Size.
       
   302         * @return ETrue if set, EFalse for invalid data.
       
   303         */
       
   304         TBool SetDownloadedSize( TInt aSize );
       
   305 
       
   306         /**
       
   307         * Set state attribute.
       
   308         * @param TMediaObjectState.
       
   309         * @return void.
       
   310         */
       
   311         void SetState( TMediaObjectState aState );
       
   312 
       
   313         /**
       
   314         * Set Type attribute (replace all).
       
   315         * @param Type.
       
   316         * @return ETrue if set, EFalse for invalid data.
       
   317         */
       
   318         TBool SetTypeL( const TDesC& aType );
       
   319 
       
   320         /**
       
   321         * Set Type attribute.
       
   322         * @param Type.
       
   323         * @return ETrue if set, EFalse for invalid data.
       
   324         */
       
   325         TBool AddTypeL( const TDesC& aType );
       
   326 
       
   327         /**
       
   328         * Set Install-Notify attribute.
       
   329         * @param Install-Notify.
       
   330         * @return ETrue if set, EFalse for invalid data.
       
   331         */
       
   332         TBool SetInstallNotifyL( const TDesC& aInstallNotify );
       
   333 
       
   334         /**
       
   335         * Set Info-URL attribute.
       
   336         * @param Info-URL.
       
   337         * @return ETrue if set, EFalse for invalid data.
       
   338         */
       
   339         TBool SetInfoUrlL( const TDesC& aInfoUrl );
       
   340 
       
   341         /**
       
   342         * Set Price attribute.
       
   343         * @param Price.
       
   344         * @return ETrue if set, EFalse for invalid data.
       
   345         */
       
   346         TBool SetPriceL( const TDesC& aPrice );
       
   347 
       
   348         /**
       
   349         * Set Icon attribute.
       
   350         * @param Icon.
       
   351         */
       
   352         TBool SetIconL( const TDesC& aIcon );
       
   353 
       
   354         /**
       
   355         * Set Version attribute.
       
   356         * @param Version.
       
   357         */
       
   358         TBool SetVersionL( const TDesC& aVersion );
       
   359 
       
   360         /**
       
   361         * Set source URI.
       
   362         * @param aSourceUri Source URI.
       
   363         */
       
   364         void SetSourceUriL( const TDesC8& aSourceUri );
       
   365 
       
   366         /**
       
   367         * Set Progressive download attribute.
       
   368         * @param aProgressiveDl Progressive Download setting.
       
   369         */
       
   370         void SetProgressiveDownload( TBool aProgressiveDl );
       
   371 
       
   372         /**
       
   373         * Set Order attribute.
       
   374         * @param aIsPostOrder.
       
   375         */
       
   376         void SetOrderIsPost( TBool aIsPostOrder );
       
   377 
       
   378         /**
       
   379         * Set updated DD URI attribute. 
       
   380         */
       
   381         TBool SetUpdatedDDURI( const TDesC& aUrl );
       
   382         
       
   383         /**
       
   384         * Set Unique-Filename-Set attribute.
       
   385         * @param aUniqueFilenameSet (ETrue / EFalse).
       
   386         */
       
   387         void UniqueFilenameSet( TBool aUniqueFilenameSet );
       
   388         
       
   389     private:    // implementation details
       
   390 
       
   391         /**
       
   392         * Common setter for string attributes, with overflow check.
       
   393         * @param aBuf Buffer to set.
       
   394         * @param aString String to set.
       
   395         * @param aMaxLength Max length to check.
       
   396         * @return ETrue if set, EFalse for invalid data.
       
   397         */
       
   398         TBool SetStringAttrL
       
   399             ( HBufC*& aBuf, const TDesC& aString, TInt aMaxLength );
       
   400 
       
   401         /**
       
   402         * Common setter for string attributes, with overflow check.
       
   403         * @param aBuf Buffer to set.
       
   404         * @param aString String to set.
       
   405         * @param aMaxLength Max length to check.
       
   406         * @return ETrue if set, EFalse for invalid data.
       
   407         */
       
   408         TBool SetStringAttrL
       
   409             ( HBufC8*& aBuf, const TDesC& aString, TInt aMaxLength );
       
   410 
       
   411 
       
   412 		/**
       
   413         * Sets the currently downloaded media content size
       
   414         * @return void
       
   415         */		
       
   416         void SetDownloadedFileSizeL( RFs &aFs );
       
   417 		
       
   418 		/**
       
   419         * Creates a buffer holding content types
       
   420         * @return void
       
   421         * @Added in OMA pause-resume feature
       
   422         */
       
   423 	    void AppendContentTypesL(TPtr8& abuf,CDesC8ArrayFlat* aTypes)const;
       
   424 
       
   425 		/**
       
   426         * Creates an array of content types.
       
   427         * @return void
       
   428         * @Added in OMA pause-resume feature
       
   429         */
       
   430 	    void LoadContentTypesL(RFile& aInFile,CDesC8ArrayFlat* aTypes);	
       
   431 
       
   432         /**
       
   433         * Append the HTTP Response of this media object.
       
   434         * @param aBuf Buffer to be appended with header info.
       
   435         * @return void.
       
   436         */
       
   437         void AppendHeadersL( TPtr8& aBuf, const CArrayPtrFlat<CHeaderField>* aHeaders ) const;
       
   438 
       
   439         /**
       
   440         * Load the header fields from the info file.
       
   441         * @param aFile Info file.
       
   442         * @param aHeaders Headers fields to be filled into.
       
   443         * @return void.
       
   444         */
       
   445         void LoadHeadersL( RFile& aFile, CArrayPtrFlat<CHeaderField>*& aHeaders );
       
   446 
       
   447     private:    // friends
       
   448 
       
   449         /// Parsers can set the data.
       
   450         friend class TCodParser;
       
   451 
       
   452         /// Parser can set the data.
       
   453         friend class TDdParser;
       
   454         
       
   455         /// Engine can set source URI.
       
   456         friend class CCodEngBase;
       
   457         
       
   458         /// Saver needs to access the paths.
       
   459         friend class CFileSaver;        
       
   460 
       
   461     private:    // data
       
   462 
       
   463         HBufC* iName;               ///< COD-Name. Owned.
       
   464         HBufC* iDescription;        ///< COD-Description. Owned.
       
   465         HBufC8* iUrl;               ///< COD-URL. Owned.
       
   466         TUint iSize;                 ///< COD-Size.
       
   467         CDesC8ArrayFlat* iTypes;    ///< COD-Types. Owned.
       
   468         HBufC8* iInstallNotify;     ///< COD-Install-Notify. Owned.
       
   469         HBufC8* iInfoUrl;           ///< COD-Info-URL. Owned.
       
   470         HBufC* iPrice;              ///< COD-Price. Owned.
       
   471         HBufC8* iIcon;              ///< COD-Icon. Owned.
       
   472         HBufC8* iSourceUri;         ///< Source URI. Owned.
       
   473         TBool iProgressiveDl;       ///< Progressive download. //for OMA 2
       
   474         TBool iIsPostOrder;			///< Order (True if Post or False if Any) // for OMA 2
       
   475         
       
   476         //Media specific data required for CodEngBase
       
   477         
       
   478         TInt iDownloadedSize;       ///< Currently downloaded size of the media.
       
   479         TMediaObjectState iState;   ///< Media object state
       
   480       	TInt iStatusCode;	        ///< HTTP code sent in install-notify.
       
   481         TInt iResult;               ///< Resulting error code (overall result).
       
   482         TFileName iFileName;        ///< File name of saved content.
       
   483         HBufC* iFullName;           ///< File name based on the Temp file path and url file name
       
   484         TFileName iTempPath;        ///< Temp file path (downloading).
       
   485         TFileName iRootPath;        ///< Root path (saving content).
       
   486         TBool iPausable;            ///< Pausable
       
   487         TBool iUniqueFilenameSet;   ///< ETrue if unique name for this track is already set.
       
   488                                     ///< Required to prevent over-writing of existing media file.
       
   489         
       
   490     };
       
   491 
       
   492 #endif /* def MEDIA_OBJECT_H */