upnpsharing/upnpcontentserver/inc/upnpcontainercheckerao.h
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-2007 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:      This module handlers the cleaning and creating of the 
       
    15 *                filesystem to mediaserver
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef __UPNPCONTAINERCHECKERAO_H__
       
    24 #define __UPNPCONTAINERCHECKERAO_H__
       
    25 
       
    26 // INCLUDES
       
    27 #include <e32base.h>
       
    28 
       
    29 #include <upnpbrowsecriteria.h>
       
    30 #include <upnpcontainerlist.h>
       
    31 #include <upnpcontainer.h>
       
    32 #include <upnpitem.h>
       
    33 #include <upnpitemlist.h>
       
    34 #include <upnpfilesharing.h>
       
    35 #include <upnpmediaserverclient.h>
       
    36 #include "upnpcontentserverdefs.h"
       
    37 #include "upnpsharingcallback.h"
       
    38 
       
    39 /**
       
    40  *  A class to check, create  and clean the default filesystem in Media server
       
    41  *
       
    42  *  @since S60 3.1
       
    43  */
       
    44 class CUpnpContainerCheckerAo : public CActive
       
    45     {
       
    46     /**
       
    47      * Indicates the ongoing operation of the CUpnpContainerCheckerAo
       
    48      */
       
    49     enum THandlerOperations
       
    50         {
       
    51         EInitialize,
       
    52         EQueryDefaultContainers,
       
    53         EUnshareItemList,
       
    54         EQueryDefaultContainersResult,
       
    55         EQueryItemFromMediaServer,
       
    56         EQueryItemFromMediaServerResult,
       
    57         
       
    58         EUnshareContainer,
       
    59         EUnshareContainerResult,
       
    60 
       
    61         EShareContainer,
       
    62         EShareContainerResult,
       
    63         ENotActive
       
    64         };
       
    65 
       
    66     /**
       
    67      * Indicates the current state of the handler
       
    68      */
       
    69     enum THandlerState
       
    70         {
       
    71         EResolveDefaultContainerIds,
       
    72         ECleanFileStructure,
       
    73         EShareDefaultContainers,
       
    74         EEmptyUploadedContainer,
       
    75         EEmptyUploadedContainerItems,
       
    76         EEmptyRootContainerItems,
       
    77         EUnshareExtraContainers,
       
    78         EUnshareExtraItems,
       
    79         EIdle
       
    80         };
       
    81 
       
    82     /**
       
    83      * Indicates the current state of the handler
       
    84      */
       
    85     enum TErrorState
       
    86         {
       
    87         ENoError,
       
    88         EDropAllContent,
       
    89         EDropAllContentResult
       
    90         };
       
    91 
       
    92     /**
       
    93      * The operating modes
       
    94      */
       
    95     enum TOperationMode
       
    96         {
       
    97         EValidateContainers,
       
    98         ECheckDefaultContainers
       
    99         };
       
   100 
       
   101 public:
       
   102    /**
       
   103     * The folder checking operations
       
   104     */
       
   105     enum TContainerPosition
       
   106         {
       
   107         EImageAndVideo = 0,
       
   108         EMusic,
       
   109         EUploaded
       
   110         };
       
   111 
       
   112     /**
       
   113     * C++ constructor.
       
   114     * @since S60 3.1
       
   115     * @param aWait, the client side wait
       
   116     */
       
   117     CUpnpContainerCheckerAo( MUpnpSharingCallback* aCallback );
       
   118 
       
   119     /**
       
   120     * C++ destructor.
       
   121     */
       
   122     virtual ~CUpnpContainerCheckerAo();
       
   123 
       
   124     /**
       
   125      * Creates the default containers if they do not exist,
       
   126      * empties root container and cleans uploaded container
       
   127      * @since S60 3.1
       
   128      * @return Errorcode of the operation start
       
   129      */
       
   130     TInt ValidateContainerStructureL( RArray<TInt>* aIds );
       
   131 
       
   132     /**
       
   133      * Creates the default containers if they do not exist
       
   134      * Add ids of the default containers to array
       
   135      * @since S60 3.1
       
   136      * @param aIds The container Ids, indexed using TContainerPosition type
       
   137      * @return Errorcode of the operation start
       
   138      */
       
   139     TInt CheckDefaultContainersL( RArray<TInt>* aIds );
       
   140 
       
   141     /**
       
   142      * Request this active ocject to stop as soon as is possible
       
   143      * Stop is indicated to client via callback
       
   144      * @since S60 3.1
       
   145      * @param aStopType Type of stop operation
       
   146      */
       
   147     void RequestStop( MUpnpSharingCallback::TSharingStopType aStopType );
       
   148 
       
   149 
       
   150 private:
       
   151 
       
   152     /**
       
   153     * 2nd phase constructor.
       
   154     */
       
   155     void ConstructL();
       
   156 
       
   157     /**
       
   158      * The active object main loop
       
   159      * @since S60 3.1
       
   160      */
       
   161     void RunL();
       
   162 
       
   163     /**
       
   164      * The active object cancel function
       
   165      * @since S60 3.1
       
   166      */
       
   167     void DoCancel();
       
   168 
       
   169     /**
       
   170      * Perform cleanup in case RunL leaves
       
   171      * @since S60 3.1
       
   172      * @return error code
       
   173      */
       
   174     TInt RunError( TInt aError );
       
   175 
       
   176     /**
       
   177      * Perform allocating of resources needed for processing upload events
       
   178      * @since S60 3.1
       
   179      * @return error code
       
   180      */
       
   181     TInt InitializeL();
       
   182 
       
   183     /**
       
   184      * Query default container structure ids from media server
       
   185      * @since S60 3.1
       
   186      */
       
   187     void QueryDefaultContainerIdsL();
       
   188 
       
   189     /**
       
   190      * Handle the query result
       
   191      * @since S60 3.1
       
   192      */
       
   193     void QueryDefaultContainerIdsResultL();
       
   194 
       
   195     /**
       
   196      * Handle the item query result
       
   197      * @since S60 3.1
       
   198      */
       
   199     void QueryItemFromCdsResultL();
       
   200 
       
   201     /**
       
   202      * Unshare the items in iItemList
       
   203      * @since S60 3.1
       
   204      */
       
   205     void UnshareItemListL();
       
   206 
       
   207     /**
       
   208      * Share container on basis of ID
       
   209      * @since S60 3.1
       
   210      */
       
   211     void ShareContainerL( TInt aPos );
       
   212 
       
   213     /**
       
   214      * Handle the sharing operation result
       
   215      * @since S60 3.1
       
   216      */
       
   217     void ShareContainerResult( );
       
   218 
       
   219     /**
       
   220      * Unshares container under processing
       
   221      * @since S60 3.1
       
   222      */
       
   223     void UnshareContainerL();
       
   224 
       
   225     /**
       
   226      * Handle result of the unshare container operation
       
   227      * @since S60 3.1
       
   228      */
       
   229     void UnshareContainerResultL();
       
   230 
       
   231     /**
       
   232      * Query containers in root level
       
   233      * @since S60 3.1
       
   234      */
       
   235     void QueryContainerItemsL();
       
   236 
       
   237     /**
       
   238      * Create browse criteria for media server query
       
   239      * @since S60 3.1
       
   240      * @return pointer to CUpnpBrowseCriteria instance
       
   241      */
       
   242     CUpnpBrowseCriteria* CreateBrowseCriteriaLC() const;
       
   243 
       
   244     /**
       
   245      * Clean allocated resources for possible next run
       
   246      * @since S60 3.1
       
   247      */
       
   248     void Cleanup();
       
   249 
       
   250     /**
       
   251      * Complete own request
       
   252      * @since S60 3.1
       
   253      * @param aError Errorcode to use in completion
       
   254      */
       
   255     void SelfComplete( TInt aError );
       
   256 
       
   257 
       
   258 
       
   259 private:
       
   260 
       
   261     /**
       
   262      * Media server API to share files
       
   263      * owned
       
   264      */
       
   265     CUpnpFileSharing* iFileSharing;
       
   266 
       
   267     /**
       
   268      * Media server session handle
       
   269      */
       
   270     RUpnpMediaServerClient iMediaServer;
       
   271 
       
   272     /**
       
   273      * Used to hold the upper ao
       
   274      * Stopped when this class has nothing to do. Not owned.
       
   275      */
       
   276     MUpnpSharingCallback* iCallback;
       
   277 
       
   278     /**
       
   279      * Hanlders current state
       
   280      */
       
   281     TInt iState;
       
   282 
       
   283     /**
       
   284      * Handlers current operation
       
   285      */
       
   286     TInt iCurrentOperation;
       
   287 
       
   288     /**
       
   289      * Id of the Images& Videos container
       
   290      */
       
   291     TInt iImageVideoContainerId;
       
   292 
       
   293     /**
       
   294      * Id of the Music container
       
   295      */
       
   296     TInt iMusicContainerId;
       
   297 
       
   298     /**
       
   299      * Id of the Upload container
       
   300      */
       
   301     TInt iUploadContainerId;
       
   302 
       
   303     /**
       
   304      * Array of shared container IDs
       
   305      */
       
   306     RArray<TInt> iSharedContainerIds;
       
   307 
       
   308     /**
       
   309      * The currently processed container
       
   310      * owned
       
   311      */
       
   312     CUpnpContainer* iTmpContainer;
       
   313 
       
   314     /**
       
   315      * Structure used to hold the containers queries from media server
       
   316      * In practice it is used to hold "Images& VIdeos" & "Music" & "Uploaded"
       
   317      * containers.
       
   318      * owned
       
   319      */
       
   320     CUpnpContainerList*  iContainerList;
       
   321     
       
   322     /**
       
   323     * Structure used to hold possbile unwanted items when cleaning 
       
   324     * some folder
       
   325     * owned
       
   326     */
       
   327     CUpnpItemList* iItemList;
       
   328     
       
   329     /**
       
   330      * Holds the position of the container under processing
       
   331      */
       
   332     TInt iContainerPosition;
       
   333 
       
   334     /**
       
   335      * The number of items in item query
       
   336      */
       
   337     TInt iTotalMatches;
       
   338 
       
   339     /**
       
   340      * The position when unsharing list of items
       
   341      */
       
   342     TInt iExecStatus;
       
   343 
       
   344     /**
       
   345      * Operation mode as defined by TOperationMode
       
   346      */
       
   347     TInt iOperationMode;
       
   348 
       
   349     /**
       
   350      * Pointer to client structure to contain the container ids
       
   351      * Not owned
       
   352      */
       
   353     RArray<TInt>* iClientIds;
       
   354 
       
   355     /**
       
   356      * Indicates if the client has requested stop
       
   357      * Value is the stop type
       
   358      */
       
   359     TInt iStopRequested;
       
   360 
       
   361     /**
       
   362      * State variable which informs if there is need to do
       
   363      * error handling
       
   364      */
       
   365     TInt iRecoverError;
       
   366     
       
   367     /**
       
   368      * The number of matches returned by media server
       
   369      * Not used but required by CUpnpFileSharing API
       
   370      */
       
   371      TInt iMatchCount;
       
   372 
       
   373     /**
       
   374      * temporary storage for object count when querying items from media
       
   375      * server
       
   376      */
       
   377     TInt iObjectCount;
       
   378     };
       
   379 
       
   380 
       
   381 #endif // __UPNPCONTAINERCHECKERAO_H__