mmappcomponents/harvester/server/src/mpxharvesterengine.cpp
changeset 27 cbb1bfb7ebfb
parent 0 a2952bb97e68
child 32 edd273b3192a
equal deleted inserted replaced
25:d881023c13eb 27:cbb1bfb7ebfb
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <e32std.h>
    19 #include <e32std.h>
    20 #ifdef RD_MULTIPLE_DRIVE
       
    21 #include <driveinfo.h>
    20 #include <driveinfo.h>
    22 #endif //RD_MULTIPLE_DRIVE
       
    23 #include <mpxlog.h>
    21 #include <mpxlog.h>
    24 #include <mpxmedia.h>
    22 #include <mpxmedia.h>
    25 #include <mpxcollectionutility.h>
    23 #include <mpxcollectionutility.h>
    26 #include <mpxcollectionmessage.h>
    24 #include <mpxcollectionmessage.h>
    27 #include <mpxtaskqueue.h>
    25 #include <mpxtaskqueue.h>
    36 #include "mpxharvestercommon.h"
    34 #include "mpxharvestercommon.h"
    37 #include "mpxharvesterengine.h"
    35 #include "mpxharvesterengine.h"
    38 #include "mpxfsformatmonitor.h"
    36 #include "mpxfsformatmonitor.h"
    39 #include "mpxmediaremovalmonitor.h"
    37 #include "mpxmediaremovalmonitor.h"
    40 #include "mpxusbeventhandler.h"
    38 #include "mpxusbeventhandler.h"
    41 #include "mpxmmcejectmonitor.h"
       
    42 #include "mpxharvesterfilehandler.h"
    39 #include "mpxharvesterfilehandler.h"
    43 #include "mpxharvesterengineobserver.h"
    40 #include "mpxharvesterengineobserver.h"
    44 #include "mpxhvsmsg.h"
    41 #include "mpxhvsmsg.h"
    45 
    42 
    46 // ======== MEMBER FUNCTIONS ========
    43 // ======== MEMBER FUNCTIONS ========
    62     MPX_DEBUG1("CMPXHarvesterEngine::~CMPXHarvesterEngine <---");
    59     MPX_DEBUG1("CMPXHarvesterEngine::~CMPXHarvesterEngine <---");
    63 
    60 
    64     delete iFormatMonitor;
    61     delete iFormatMonitor;
    65     delete iMediaRemovalMonitor;
    62     delete iMediaRemovalMonitor;
    66     delete iUSBMonitor;
    63     delete iUSBMonitor;
    67     delete iMMCMonitor;
       
    68 
    64 
    69     delete iFileHandler;
    65     delete iFileHandler;
    70     iFsSession.Close();
    66     iFsSession.Close();
    71 
    67 
    72     if( iTaskQueue )
    68     if( iTaskQueue )
    97     // Format handler for Removable Drive
    93     // Format handler for Removable Drive
    98     iFormatMonitor = CMPXFsFormatMonitor::NewL( *this );
    94     iFormatMonitor = CMPXFsFormatMonitor::NewL( *this );
    99 
    95 
   100     // MMC Removal monitor for Removable Drive
    96     // MMC Removal monitor for Removable Drive
   101     TInt removableDrive( EDriveE );
    97     TInt removableDrive( EDriveE );
   102 #ifdef RD_MULTIPLE_DRIVE
       
   103     User::LeaveIfError( DriveInfo::GetDefaultDrive(
    98     User::LeaveIfError( DriveInfo::GetDefaultDrive(
   104         DriveInfo::EDefaultRemovableMassStorage,
    99         DriveInfo::EDefaultRemovableMassStorage,
   105         removableDrive ) );
   100         removableDrive ) );
   106 #endif // RD_MULTIPLE_DRIVE
       
   107     iMediaRemovalMonitor = CMPXMediaRemovalMonitor::NewL(
   101     iMediaRemovalMonitor = CMPXMediaRemovalMonitor::NewL(
   108         removableDrive, iFsSession, *this );
   102         removableDrive, iFsSession, *this );
   109 
   103 
   110     // USB Event monitor
   104     // USB Event monitor
   111     iUSBMonitor = CMPXUsbEventHandler::NewL( *this );
   105     iUSBMonitor = CMPXUsbEventHandler::NewL( *this );
   112 
   106 
   113     // MMC Event handling
       
   114     iMMCMonitor = CMPXMMCEjectMonitor::NewL( *this );
       
   115 
   107 
   116     // File handler to handle file related events
   108     // File handler to handle file related events
   117     iFileHandler = CMPXHarvesterFileHandler::NewL( iFsSession );
   109     iFileHandler = CMPXHarvesterFileHandler::NewL( iFsSession );
   118 
   110 
   119     // Active task queue for async requests
   111     // Active task queue for async requests
   443 //
   435 //
   444 void CMPXHarvesterEngine::HandleSystemEventL( TSystemEvent aEvent,
   436 void CMPXHarvesterEngine::HandleSystemEventL( TSystemEvent aEvent,
   445                                               TInt aData )
   437                                               TInt aData )
   446     {
   438     {
   447     MPX_DEBUG2("CMPXHarvesterEngine::HandleSystemEventL %i <---", aEvent);
   439     MPX_DEBUG2("CMPXHarvesterEngine::HandleSystemEventL %i <---", aEvent);
       
   440     
       
   441     if( !iTempCollectionUtil )
       
   442         {
       
   443         iTempCollectionUtil = MMPXCollectionUtility::NewL( NULL, KMcModeDefault );
       
   444         }
       
   445         
       
   446     // Must close collections ASAP in case drives may dismount soon       
       
   447     TRAP_IGNORE( 
       
   448         if (aEvent == EUSBMassStorageStartEvent)
       
   449             {
       
   450             DoStopPlaybackL();
       
   451             iTempCollectionUtil->Collection().CommandL ( EMcCloseCollection, -1 ); 
       
   452             iFileHandler->HandleSystemEventL ( EDiskDismountEvent, -1 );
       
   453             }
       
   454         else if ( aEvent == EDiskDismountEvent )
       
   455             {
       
   456             DoStopPlaybackL();
       
   457             iTempCollectionUtil->Collection().CommandL ( EMcCloseCollection, aData );
       
   458             }
       
   459         );
   448 
   460 
   449     // The engine is a delegator, it sends the events to
   461     // The engine is a delegator, it sends the events to
   450     // different classes to do the actual work
   462     // different classes to do the actual work
   451     TRAPD( openErr, iFileHandler->HandleSystemEventL( aEvent, aData ) );
   463     TRAPD( openErr, iFileHandler->HandleSystemEventL( aEvent, aData ) );
   452 
   464 
   453     // Avoid Message queue already exist problem
   465     // Avoid Message queue already exist problem
   454     //
   466     //
   455     TBool notify(ETrue);
   467     TBool notify(ETrue);
   456     switch( aEvent )
   468     switch( aEvent )
   457         {
   469         {
   458         case EPowerKeyEjectEvent:
   470         case EDiskDismountEvent:
   459             {
   471             {
   460             notify=EFalse;
   472             notify=EFalse;
   461             TRAP_IGNORE( DoStopPlaybackL() );
       
   462             break;
   473             break;
   463             }
   474             }
       
   475         case EUSBMassStorageStartEvent:
       
   476             {
       
   477             iDiskOpActive = ETrue;
       
   478             }
       
   479             break;
   464         case EFormatStartEvent:
   480         case EFormatStartEvent:
   465         case EUSBMassStorageStartEvent:   // deliberate fall through
       
   466         case EUSBMTPStartEvent:           // deliberate fall through
   481         case EUSBMTPStartEvent:           // deliberate fall through
   467         case EDiskInsertedEvent:          // deliberate fall through
   482         case EDiskInsertedEvent:          // deliberate fall through
   468         case EDiskRemovedEvent:           // deliberate fall through
   483         case EDiskRemovedEvent:           // deliberate fall through
   469             {
   484             {
   470             iDiskOpActive = ETrue;
   485             iDiskOpActive = ETrue;
   471             TRAP_IGNORE( DoStopPlaybackL() );
   486             TRAP_IGNORE( DoStopPlaybackL() );
   472             }
   487             }
   473         default: //lint !e616 !e825
       
   474             if( !iTempCollectionUtil )
       
   475                 {
       
   476                 iTempCollectionUtil = MMPXCollectionUtility::NewL( NULL, KMcModeDefault );
       
   477                 }
       
   478             break;
   488             break;
   479         }
   489         }
   480 
   490 
   481     // Send a message to the collection server about the event
   491     // Send a message to the collection server about the event
   482     //
   492     //
   512                 {
   522                 {
   513                 iTempCollectionUtil->Close();
   523                 iTempCollectionUtil->Close();
   514                 iTempCollectionUtil = NULL;
   524                 iTempCollectionUtil = NULL;
   515                 }
   525                 }
   516         }
   526         }
       
   527         
       
   528     if ( aEvent == EUSBMassStorageEndEvent )
       
   529         {
       
   530         // In some cases visit to USB Mass Storage mode can be so brief
       
   531         // that drives are actually not dismounted at all even though we
       
   532         // get a NotifyDismount event. In such cases we need to re-issue
       
   533         // the NotifyDismount requests.
       
   534         iMediaRemovalMonitor->CheckDriveStatus();
       
   535         }
   517     }
   536     }
   518 
   537 
   519 // ---------------------------------------------------------------------------
   538 // ---------------------------------------------------------------------------
   520 // Execute task queue events
   539 // Execute task queue events
   521 // ---------------------------------------------------------------------------
   540 // ---------------------------------------------------------------------------