upnpsharing/upnpsharingalgorithm/inc/upnpcontainerresolver.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:  Header file for the CUpnpContainerResolver class.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_UPNP_CONTAINER_RESOLVER_H
       
    19 #define C_UPNP_CONTAINER_RESOLVER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <barsc.h> // for RResourceFile
       
    23 #include <upnpcontainer.h>
       
    24 #include "upnpcdsliteobjectarray.h"
       
    25 
       
    26 // FORWARD DECLARTIONS
       
    27 class CUpnpItem;
       
    28 
       
    29 // CLASS DECLARATION
       
    30 
       
    31 /**
       
    32 *  CUpnpContainerResolver class definition
       
    33 *
       
    34 *  @lib upnpsharingalgorithm.lib
       
    35 *  @since S60 5.2
       
    36 */
       
    37 class CUpnpContainerResolver : public CBase
       
    38     {
       
    39 
       
    40     public: // Constructors and destructor
       
    41 
       
    42         /**
       
    43          * Two-phased constructor.
       
    44          *
       
    45          * @since S60 5.2
       
    46          * @param aCdsLiteObjectArray, array of cds objects
       
    47          * @return container resolver object
       
    48          */
       
    49         static CUpnpContainerResolver* NewL(
       
    50             CUpnpCdsLiteObjectArray& aCdsLiteObjectArray );
       
    51 
       
    52         /**
       
    53          * Destructor.
       
    54          *
       
    55          * @since S60 5.2
       
    56          */
       
    57         virtual ~CUpnpContainerResolver();
       
    58 
       
    59         /**
       
    60          * Resolves containers that need to be created.
       
    61          * Container list is returned to the caller.
       
    62          *
       
    63          * @since S60 5.2
       
    64          * @param aItem, upnp item to be shared
       
    65          * @return RPointerArray, array containing created containers
       
    66          */
       
    67         RPointerArray<CUpnpContainer>
       
    68             ResolveContainerStructureL( CUpnpItem& aItem );
       
    69 
       
    70         /**
       
    71          * Resolves containers that need to be created for a reference item.
       
    72          * Container list is returned to the caller.
       
    73          *
       
    74          * @since S60 5.2
       
    75          * @param aType, reference media type
       
    76          * @param aItem, upnp item to be shared
       
    77          * @return RPointerArray, array containing created containers
       
    78          */
       
    79         RPointerArray<CUpnpContainer>
       
    80             ResolveReferenceContainersL( TInt aType, CUpnpItem& aItem );
       
    81 
       
    82         /**
       
    83          * Resolves containers that need to be removed (containers
       
    84          * that does not contain items anymore) after an item
       
    85          * has been unshared
       
    86          *
       
    87          * @since S60 5.2
       
    88          * @param aContainerId, Container id where item belongs.
       
    89          * @return RPointerArray, containers to be removed
       
    90          */
       
    91         RPointerArray<CUpnpCdsLiteObject>
       
    92             ResolveEmptyContainersL( TDesC8& aContainerId );
       
    93 
       
    94     private: // Second-phase contstruction
       
    95 
       
    96         /**
       
    97          * Default c++ constructor
       
    98          *
       
    99          * @since S60 5.2
       
   100          * @param aCdsLiteObjectArray, array of cds objects
       
   101          */
       
   102         CUpnpContainerResolver(
       
   103             CUpnpCdsLiteObjectArray& aCdsLiteObjectArray ):
       
   104                 iCdsLiteObjectArray( aCdsLiteObjectArray ) {}
       
   105 
       
   106         /**
       
   107          * Second-phase constructor.
       
   108          *
       
   109          * @since S60 5.2
       
   110          */
       
   111         void ConstructL();
       
   112 
       
   113         /**
       
   114          * Creates a new UpnpContainer according to the given parameters
       
   115          *
       
   116          * @since S60 5.2
       
   117          * @param aTitle, title of created container
       
   118          * @param aClass, class of created container
       
   119          * @return CUpnpContainer, created container
       
   120          */
       
   121         CUpnpContainer* CreateContainerL( const TDesC8& aTitle,
       
   122                                           const TDesC8& aClass );
       
   123 
       
   124         /**
       
   125          * Finds non-existing containers from CDS and creates them.
       
   126          * If new containers are not created, returned parent id
       
   127          * is for item, otherwise for last found container
       
   128          *
       
   129          * @since S60 5.2
       
   130          * @param aContainerNames, container names to be resolved
       
   131          * @param aContainers, containers that need to be shared
       
   132          * @param aMediaClass, media class type
       
   133          * @return HBufC8, parent id of a container / item
       
   134          */
       
   135         HBufC8* CreateContainersL(
       
   136             RPointerArray<HBufC8>& aContainerNames,
       
   137             RPointerArray<CUpnpContainer>& aContainers,
       
   138             const TDesC8& aMediaClass );
       
   139 
       
   140 
       
   141         /**
       
   142          * Reads resource text from component resource file.
       
   143          *
       
   144          * @since S60 5.2
       
   145          * @param aResourceId, resource id
       
   146          * @return HBufC8, resource text
       
   147          */
       
   148         HBufC8* ReadResourceTextL( TInt aResourceId );
       
   149 
       
   150         /**
       
   151          * Finds element value of a certain element
       
   152          *
       
   153          * @since S60 5.2
       
   154          * @param elements, element array
       
   155          * @return HBufC8, element value
       
   156          */
       
   157         HBufC8* GetElementL( const RUPnPElementsArray& elements,
       
   158                                    const TDesC8& aElement );
       
   159 
       
   160         /**
       
   161          * Modifies aDate parameter so that month and day
       
   162          * values are decreased by one. This is because
       
   163          * month and day count need to be started from
       
   164          * zero, not from 1.
       
   165          *
       
   166          * @since S60 5.2
       
   167          * @param aDate, date to be adjusted
       
   168          * @return HBufC8, adjusted date
       
   169          */
       
   170         HBufC8* AdjustDateL( const TDesC8& aDate );
       
   171 
       
   172         /**
       
   173          * Adds date containers to the aContainerNames
       
   174          * list. Year, Month and Day are added separately.
       
   175          * Returns KErrNotFound, if date metadata is missing.
       
   176          *
       
   177          * @since S60 5.2
       
   178          * @param aContainerNames, list of containers
       
   179          * @param aElements, list of item elements
       
   180          * @return TInt, error code
       
   181          */
       
   182         TInt AddByDateContainersL(
       
   183             RPointerArray<HBufC8>& aContainerNames,
       
   184             const RUPnPElementsArray& aElements );
       
   185 
       
   186         /**
       
   187          * Finds an element and modifies element value so
       
   188          * that only the first letter of the element is
       
   189          * capitalized. Modified element value is appended
       
   190          * to the aContainerNames array. Returns KErrNotFound,
       
   191          * if date metadata is missing.
       
   192          *
       
   193          * @since S60 5.2
       
   194          * @param aContainerNames, list of containers
       
   195          * @param aElements, list of item elements
       
   196          * @param aElementType, element type
       
   197          */
       
   198         void ModifyAndAppendElementL(
       
   199                 RPointerArray<HBufC8>& aContainerNames,
       
   200                 const RUPnPElementsArray& aElements,
       
   201                 const TDesC8& aElementType );
       
   202 
       
   203         /**
       
   204          * Appends container name to array.
       
   205          * Container name is read from resource.
       
   206          * @since S60 5.2
       
   207          * @param aArray, array of container names
       
   208          * @param TInt, resource text id
       
   209          */
       
   210         void AppendContainerNameToArrayL( RPointerArray<HBufC8>& aArray,
       
   211                                           TInt aResourceTextId );
       
   212     private: // Data members
       
   213 
       
   214         /**
       
   215          * Reference to the object array
       
   216          */
       
   217         CUpnpCdsLiteObjectArray& iCdsLiteObjectArray;
       
   218 
       
   219         /**
       
   220          * Resource file. Owned
       
   221          */
       
   222         RResourceFile            iResourceFile;
       
   223 
       
   224         /**
       
   225          * File server session. Owned
       
   226          */
       
   227         RFs                      iFs;
       
   228     };
       
   229 
       
   230 #endif // C_UPNP_CONTAINER_RESOLVER_H
       
   231 
       
   232 // End of file