mmappcomponents/harvester/server/inc/mpxharvesterengine.h
changeset 0 a2952bb97e68
child 19 51035f0751c2
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Harvester Engine to handle file and system related events
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CHARVESTERENGINE_H
       
    20 #define CHARVESTERENGINE_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <bamdesca.h>
       
    25 #include <mpxcollectionobserver.h>
       
    26 #include <mpxtaskqueueobserver.h>
       
    27 #include <mpxplaylistengineobserver.h>
       
    28 #include "mpxsystemeventobserver.h"
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CMPXHarvesterFileHandler;
       
    32 class CMPXFsFormatMonitor;
       
    33 class CMPXMediaRemovalMonitor;
       
    34 class CMPXUsbEventHandler;
       
    35 class CMPXMMCEjectMonitor;
       
    36 class CMPXMedia;
       
    37 class CMPXActiveTaskQueue;
       
    38 class CMPXPlaylistEngine;
       
    39 class MMPXHarvesterEngineObserver;
       
    40 class MMPXCollectionUtility;
       
    41 class RHvsMsg;
       
    42 
       
    43 /**
       
    44  *  Harvester engine to monitor for file system events
       
    45  *
       
    46  *  @lib mpxharvesterserver.exe
       
    47  *  @since S60 S60_version 3.0
       
    48  */
       
    49 NONSHARABLE_CLASS( CMPXHarvesterEngine ) : public CBase,
       
    50                                            public MMPXSystemEventObserver,
       
    51                                            public MMPXTaskQueueObserver,
       
    52                                            public MMPXPlaylistEngineObserver
       
    53     {
       
    54 public:
       
    55 
       
    56     /**
       
    57     * Two-phase constructor
       
    58     */
       
    59     static CMPXHarvesterEngine* NewL();
       
    60 
       
    61     /**
       
    62     * Virtual destructor
       
    63     */
       
    64     virtual ~CMPXHarvesterEngine();
       
    65 
       
    66 public:  // New Functions
       
    67 
       
    68     /**
       
    69     * Initiates a scan of the file system
       
    70     */
       
    71     void ScanL();
       
    72 
       
    73     /**
       
    74     * Cancels a scan of the file system
       
    75     */
       
    76     void CancelScan();
       
    77 
       
    78     /**
       
    79     * Add a song to the harvester db, asyncrhonous
       
    80     * @param aMsg Message struct for the add file
       
    81     * @param aFile path to the file
       
    82     * @param aObs observer to the add event,
       
    83     *        callback with CompleteTask() on completion
       
    84     */
       
    85     void AddFileL( RHvsMsg* aMsg, const TDesC& aFile, MMPXHarvesterEngineObserver* aObs );
       
    86 
       
    87     /**
       
    88     * Add a song to the harvester db
       
    89     * @param aMedia, media to add
       
    90     * @return collection ID
       
    91     */
       
    92     TInt AddFileL( CMPXMedia*& aMedia );
       
    93 
       
    94     /**
       
    95     * Get media for song, asyncrhonous
       
    96     * @param aMsg Message struct for the add file
       
    97     * @param aFile path to the file
       
    98     * @param aObs observer to the add event,
       
    99     *        callback with CompleteTask() on completion
       
   100     */
       
   101     void GetMediaL( RHvsMsg* aMsg, const TDesC& aFile, MMPXHarvesterEngineObserver* aObs );
       
   102 
       
   103     /**
       
   104     * Get Collection id for the song
       
   105     * @param aFile path to the file
       
   106     * @return collection ID
       
   107     */
       
   108     TInt GetColUidL( const TDesC& aFile );
       
   109 
       
   110     /**
       
   111     * Remove a song from the harvester db
       
   112     * @param aFile path to the file
       
   113     * @param aDelete, do we want to delete the file from FS
       
   114     * @return the Collection ID of the removed file
       
   115     */
       
   116     TInt RemoveFileL( const TDesC& aFile, TBool aDelete, TBool aEndTransaction=ETrue);
       
   117 
       
   118     /**
       
   119     * Removes multiple songs from the harvester db
       
   120     * @param aArray list of files to delete
       
   121     * @param aDelete, do we want to delete the file from FS
       
   122     */
       
   123     void RemoveMultipleFilesL( const MDesCArray& aArray, TBool aDelete, TBool aEndTransaction );
       
   124 
       
   125     /**
       
   126     * Remove all songs from the harvester db
       
   127     */
       
   128     void RemoveAllFilesL();
       
   129 
       
   130     /**
       
   131     * Update a file
       
   132     * @param aFile, File name
       
   133     * @param aCollection, Collection ID
       
   134     */
       
   135     void UpdateFileL( const TDesC& aFile, TInt aCollection );
       
   136 
       
   137     /**
       
   138     * Rename a file
       
   139     * @param aOldPath original file path
       
   140     * @param aNewPath new file path
       
   141     * @param aCollection Collection ID
       
   142     */
       
   143     void RenameFileL( const TDesC& aOldPath, const TDesC& aNewPath, TInt aCollection );
       
   144 
       
   145     /**
       
   146     * Finds the collection ID based on a File name
       
   147     * @param aFile, file name to lookup
       
   148     * @return the collection ID
       
   149     */
       
   150     TInt FindCollectionIdL( const TDesC& aFile );
       
   151 
       
   152     /**
       
   153     * Exports a playlist based on the message
       
   154     * @param aMessage containing the task
       
   155     * @param aObs observer to the export event
       
   156     *        callback to HandleImportCompleteL() on completion
       
   157     */
       
   158     void ExportPlaylistL( RHvsMsg* aMessage,
       
   159                           MMPXHarvesterEngineObserver* aObs );
       
   160 
       
   161     /**
       
   162     * Import a playlist based on the message
       
   163     * @param aMessage containing the task
       
   164     * @param aObs observer callback
       
   165     *             callback to HandleExportCompleteL() on completion
       
   166     */
       
   167     void ImportPlaylistL( RHvsMsg* aMessage,
       
   168                           MMPXHarvesterEngineObserver* aObs );
       
   169 
       
   170     /**
       
   171     * Async method to import a file (playlist or media )
       
   172     * @param aMessage containing the task
       
   173     * @param aObs, observer callback
       
   174     */
       
   175     void ImportFileL( RHvsMsg* aMessage,
       
   176                       MMPXHarvesterEngineObserver* aObs );
       
   177 
       
   178     /**
       
   179     * Query the required attributes for tracks for the specified playlist type
       
   180     * @param aPlaylistType typ of playlist to check for required attriubtes
       
   181     * @return list of required attributes for a playlist
       
   182     */
       
   183     const TArray<TMPXAttribute> RequiredAttributesL(TInt aPlaylistType) const;
       
   184 
       
   185     /**
       
   186     * Query the optional attributes for tracks for the specified playlist type
       
   187     * @param aPlaylistType typ of playlist to check for optional attriubtes
       
   188     * @return list of required attributes for a playlist
       
   189     */
       
   190     const TArray<TMPXAttribute> OptionalAttributesL(TInt aPlaylistType) const;
       
   191 
       
   192     /**
       
   193     * Query about the file extension the playlist plugin for the given type
       
   194     * supports
       
   195     * @return file extension which includes the period
       
   196     */
       
   197     const TDesC& PlaylistFileExtensionL(TInt aPlaylistType) const;
       
   198 
       
   199     /**
       
   200     * Determines if the given file is a playlist
       
   201     * @param aFile file path of the file to be tested
       
   202     * @return ETrue if it's a playlist otherwise EFalse
       
   203     */
       
   204     TBool IsPlaylistL( const TDesC& aFile );
       
   205 
       
   206     /**
       
   207     * Recreate the harvester database if corruption is detected
       
   208     * note: all dbs are re-created for accuracy and simplicity
       
   209     */
       
   210     void RecreateDatabases();
       
   211 
       
   212     /**
       
   213     * Polls for system events
       
   214     * If an event occurs, it will br broadcasted to the rest of the MPX framework
       
   215     */
       
   216     void CheckForSystemEvents();
       
   217 
       
   218     /**
       
   219     * Close the database transaction
       
   220     */
       
   221     void CloseTransactionL();
       
   222 
       
   223 protected:  // From Base Class
       
   224 
       
   225     /*
       
   226     * From MMPXSystemEventObserver
       
   227     */
       
   228     void HandleSystemEventL( TSystemEvent aEvent, TInt aData );
       
   229 
       
   230     /*
       
   231     * From MMPXTaskQueueObserver
       
   232     */
       
   233     void ExecuteTask(TInt aTask,
       
   234                      TInt aParamData,
       
   235                      TAny* aPtrData,
       
   236                      const CBufBase& aBuf,
       
   237                      TAny* aCallback,
       
   238                      CBase* aCObject1,
       
   239                      CBase* aCObject2);
       
   240 
       
   241     /*
       
   242     * From MMPXTaskQueueObserver
       
   243     */
       
   244     void HandleTaskError(
       
   245         TInt aTask,
       
   246         TAny* aPtrData,
       
   247         TAny* aCallback,
       
   248         TInt aError);
       
   249 
       
   250      /*
       
   251      * From MMPXPlaylistEngineObserver
       
   252      */
       
   253      void HandlePlaylistL(CMPXMedia* aPlaylist,
       
   254                           const TInt aError,
       
   255                           const TBool aCompleted );
       
   256 
       
   257      /*
       
   258      * From MMPXPlaylistEngineObserver
       
   259      */
       
   260      void HandlePlaylistL(const TDesC& aPlaylistUri,
       
   261                           const TInt aError);
       
   262 
       
   263 private:  // New functions
       
   264 
       
   265     /**
       
   266     * Handles exporting a playlist
       
   267     * @param aMsg, RMessage to handle
       
   268     */
       
   269     void DoExportPlaylistL( RHvsMsg* aMsg );
       
   270 
       
   271     /**
       
   272     * Handles importing a playlist
       
   273     * @param aMsg, RMessage to handle
       
   274     */
       
   275     void DoImportPlaylistL( RHvsMsg* aMsg );
       
   276 
       
   277     /**
       
   278     * Handles importing a file
       
   279     * @param aMsg, RMessage to handle
       
   280     */
       
   281     void DoImportFileL( RHvsMsg* aMsg );
       
   282 
       
   283     /**
       
   284     * Stop playback synchronously
       
   285     */
       
   286     void DoStopPlaybackL();
       
   287 
       
   288 private:
       
   289 
       
   290     /**
       
   291     *  C++ constructor
       
   292     */
       
   293     CMPXHarvesterEngine();
       
   294 
       
   295     /**
       
   296     * 2nd-phase constructor
       
   297     */
       
   298     void ConstructL();
       
   299 
       
   300 private: // data
       
   301     RFs   iFsSession;    // Session to File System
       
   302 
       
   303     CMPXHarvesterFileHandler* iFileHandler;
       
   304 
       
   305     // Move to RPointerArrays of monitors in the future
       
   306     CMPXFsFormatMonitor*      iFormatMonitor;
       
   307     CMPXMediaRemovalMonitor*  iMediaRemovalMonitor;
       
   308     CMPXUsbEventHandler*      iUSBMonitor;
       
   309     CMPXMMCEjectMonitor*      iMMCMonitor;
       
   310 
       
   311     // Internal task queue for async operations
       
   312     CMPXActiveTaskQueue*      iTaskQueue;
       
   313 
       
   314     // Playlist engine
       
   315     CMPXPlaylistEngine*       iPlaylistEngine;
       
   316 
       
   317     // Async op details
       
   318     TMPXHarvesterServerOp     iCurAsyncOp;
       
   319 
       
   320     // Temporary variable, avoid msg queue already exist problems
       
   321     MMPXCollectionUtility*    iTempCollectionUtil;
       
   322     TBool                     iDiskOpActive;
       
   323     };
       
   324 
       
   325 #endif // CHARVESTERENGINE_H