mpengine/src/mpmpxharvesterframeworkwrapper_p.cpp
changeset 22 ecf06a08d4d9
child 29 8192e5b5c935
equal deleted inserted replaced
20:82baf59ce8dd 22:ecf06a08d4d9
       
     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: Wrapper for mpx harvester framework utilities - private implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QStringList>
       
    19 
       
    20 #include <s32strm.h>
       
    21 #include <s32mem.h>
       
    22 #include <apgcli.h>
       
    23 #include <apacmdln.h>
       
    24 
       
    25 #include <mpxcollectionutility.h>
       
    26 #include <mpxharvesterutility.h>
       
    27 #include <mpxcollectionmessage.h>
       
    28 #include <mpxmessagecontainerdefs.h>
       
    29 #include <mpxmessagegeneraldefs.h>
       
    30 #include <mpxcollectionmessagedefs.h>
       
    31 #include <mpxlog.h>
       
    32 
       
    33 #include "mpmpxharvesterframeworkwrapper.h"
       
    34 #include "mpmpxharvesterframeworkwrapper_p.h"
       
    35 #include "mptrace.h"
       
    36 
       
    37 /*!
       
    38     \class MpMpxHarvesterFrameworkWrapperPrivate
       
    39     \brief Wrapper for mpx harvester framework utilities - private implementation.
       
    40 
       
    41     This is a private implementation of the mpx harvester framework wrapper utilties interface.
       
    42 */
       
    43 
       
    44 const int NoPreviousBroadCastMsg = -1;
       
    45 
       
    46 /*!
       
    47  \internal
       
    48  */
       
    49 MpMpxHarvesterFrameworkWrapperPrivate::MpMpxHarvesterFrameworkWrapperPrivate( MpMpxHarvesterFrameworkWrapper *wrapper )
       
    50     : q_ptr(wrapper),
       
    51       iCollectionUtility(0),
       
    52       iHarvesterUtility(0),
       
    53       iNumItemsAdded(0),
       
    54       iScanning( EFalse ),
       
    55       iPreviousBroadCastMsg( NoPreviousBroadCastMsg )
       
    56 {
       
    57     TX_LOG
       
    58 }
       
    59 
       
    60 /*!
       
    61  \internal
       
    62  */
       
    63 MpMpxHarvesterFrameworkWrapperPrivate::~MpMpxHarvesterFrameworkWrapperPrivate()
       
    64 {
       
    65     TX_ENTRY
       
    66     if ( iCollectionUtility ) {
       
    67         iCollectionUtility->Collection().CancelRequest();
       
    68         iCollectionUtility->Close();
       
    69     }
       
    70 
       
    71     if ( iHarvesterUtility ) {
       
    72         iHarvesterUtility->Close();
       
    73     }
       
    74     TX_EXIT
       
    75 }
       
    76 
       
    77 /*!
       
    78  \internal
       
    79  */
       
    80 void MpMpxHarvesterFrameworkWrapperPrivate::init( MpCommon::MpViewMode viewMode, TUid hostUid )
       
    81 {
       
    82     iViewMode = viewMode;
       
    83     mHostUid = hostUid;
       
    84     TRAPD( err, DoInitL() );
       
    85     if ( err != KErrNone ) {
       
    86         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
    87     }
       
    88 }
       
    89 
       
    90 /*!
       
    91  \internal
       
    92  */
       
    93 void MpMpxHarvesterFrameworkWrapperPrivate::scan()
       
    94 {
       
    95     TRAPD( err, DoScanL() );
       
    96     if ( err != KErrNone ) {
       
    97         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
    98     }
       
    99 }
       
   100 
       
   101 /*!
       
   102  \internal
       
   103  */
       
   104 void MpMpxHarvesterFrameworkWrapperPrivate::cancelScan()
       
   105 {
       
   106     TRAPD( err, DoCancelScanL() );
       
   107     if ( err != KErrNone ) {
       
   108         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   109     }
       
   110 }
       
   111 
       
   112 /*!
       
   113  \internal
       
   114  */
       
   115 void MpMpxHarvesterFrameworkWrapperPrivate::checkForSystemEvents()
       
   116 {
       
   117     TRAPD( err, DoCheckForSystemEventsL() );
       
   118     if ( err != KErrNone ) {
       
   119         TX_LOG_ARGS( "Error: " << err << "; should never get here." );
       
   120     }
       
   121 }
       
   122 
       
   123 /*!
       
   124  \internal
       
   125  */
       
   126 void MpMpxHarvesterFrameworkWrapperPrivate::HandleOpenL(
       
   127     const CMPXMedia& aEntries,
       
   128     TInt aIndex,
       
   129     TBool aComplete,
       
   130     TInt aError )
       
   131 {
       
   132     Q_UNUSED( aIndex );
       
   133     Q_UNUSED( aComplete );
       
   134     Q_UNUSED( aError );
       
   135     Q_UNUSED( aEntries );
       
   136 }
       
   137 
       
   138 /*!
       
   139  \internal
       
   140  */
       
   141 void MpMpxHarvesterFrameworkWrapperPrivate::HandleOpenL(
       
   142     const CMPXCollectionPlaylist& aPlaylist,
       
   143     TInt aError )
       
   144 {
       
   145     Q_UNUSED( aPlaylist );
       
   146     Q_UNUSED( aError );
       
   147 }
       
   148 
       
   149 /*!
       
   150  \internal
       
   151  */
       
   152 void MpMpxHarvesterFrameworkWrapperPrivate::HandleCollectionMediaL(
       
   153     const CMPXMedia& aMedia,
       
   154     TInt aError )
       
   155 {
       
   156     Q_UNUSED( aMedia );
       
   157     Q_UNUSED( aError );
       
   158 }
       
   159 
       
   160 /*!
       
   161  \internal
       
   162  */
       
   163 void MpMpxHarvesterFrameworkWrapperPrivate::HandleCollectionMessage(
       
   164     CMPXMessage* aMsg,
       
   165     TInt aErr )
       
   166 {
       
   167     TX_ENTRY_ARGS( "aErr=" << aErr );
       
   168     if ( aErr == KErrNone && aMsg ) {
       
   169         TRAP_IGNORE( DoHandleCollectionMessageL(*aMsg) );
       
   170     }
       
   171     TX_EXIT
       
   172 }
       
   173 
       
   174 /*!
       
   175  \internal
       
   176  */
       
   177 void MpMpxHarvesterFrameworkWrapperPrivate::DoInitL()
       
   178 {
       
   179     TX_ENTRY
       
   180     if ( iViewMode == MpCommon::FetchView ) {
       
   181         iCollectionUtility = MMPXCollectionUtility::NewL( this, mHostUid );
       
   182     }
       
   183     else {
       
   184         iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
   185     }
       
   186     iHarvesterUtility = CMPXHarvesterFactory::NewL();
       
   187     iHarvesterUtility->CheckForSystemEventsL();
       
   188     TX_EXIT
       
   189 }
       
   190 
       
   191 /*!
       
   192  \internal
       
   193  */
       
   194 void MpMpxHarvesterFrameworkWrapperPrivate::DoScanL()
       
   195 {
       
   196     TX_ENTRY
       
   197     iNumItemsAdded = 0;
       
   198     iHarvesterUtility->ScanL();
       
   199     TX_EXIT
       
   200 }
       
   201 
       
   202 /*!
       
   203  \internal
       
   204  */
       
   205 void MpMpxHarvesterFrameworkWrapperPrivate::DoCancelScanL()
       
   206 {
       
   207     TX_ENTRY
       
   208     // If harvester crashes, restart it.
       
   209     TRAPD( err, iHarvesterUtility->CancelScanL() );
       
   210     if ( err != KErrNone ) {
       
   211         iHarvesterUtility->Close();
       
   212         iHarvesterUtility = NULL;
       
   213         iHarvesterUtility = CMPXHarvesterFactory::NewL();
       
   214         iHarvesterUtility->CheckForSystemEventsL();
       
   215     }
       
   216     TX_EXIT
       
   217 }
       
   218 
       
   219 /*!
       
   220  \internal
       
   221  */
       
   222 void MpMpxHarvesterFrameworkWrapperPrivate::DoHandleCollectionMessageL(
       
   223     const CMPXMessage& aMsg )
       
   224 {
       
   225     TX_ENTRY
       
   226     TMPXMessageId id( aMsg.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   227     if ( KMPXMessageGeneral == id ) {
       
   228         TInt event( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
   229         TInt type( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
   230         TInt data( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
   231         TX_LOG_ARGS( "event=" << event << ", type=" << type << ", data=" << data );
       
   232 
       
   233         if ( event == TMPXCollectionMessage::EBroadcastEvent &&
       
   234             BroadcastEventFilter( type ) ) {
       
   235             switch ( type ) {
       
   236                 case EMcMsgFormatStart:
       
   237                     emit q_ptr->diskEvent(DiskFormatStarted);
       
   238                     break;
       
   239                 case EMcMsgFormatEnd:
       
   240                     emit q_ptr->diskEvent(DiskFormatEnded);
       
   241                     break;
       
   242                 case EMcMsgDiskRemoved:
       
   243                     emit q_ptr->diskEvent(DiskRemoved);
       
   244                     break;
       
   245                 case EMcMsgDiskInserted:
       
   246                     emit q_ptr->diskEvent(DiskInserted);
       
   247                     break;
       
   248                 case EMcMsgUSBMassStorageStart:
       
   249                     emit q_ptr->usbEvent(UsbMassStorageStarted);
       
   250                     break;
       
   251                 case EMcMsgUSBMassStorageEnd:
       
   252                     emit q_ptr->usbEvent(UsbMassStorageEnded);
       
   253                     break;
       
   254                 case EMcMsgUSBMTPStart:
       
   255                     emit q_ptr->usbEvent(UsbMtpStarted);
       
   256                     break;
       
   257                 case EMcMsgUSBMTPEnd:
       
   258                     emit q_ptr->usbEvent(UsbMtpEnded);
       
   259                     break;
       
   260                 case EMcMsgUSBMTPNotActive:
       
   261                     emit q_ptr->usbEvent(UsbMtpNotActive);
       
   262                     break;
       
   263                 case EMcMsgRefreshStart:
       
   264                     iScanning = ETrue;
       
   265                     emit q_ptr->scanStarted();
       
   266                     break;
       
   267                 case EMcMsgRefreshEnd:
       
   268                     iScanning = EFalse;
       
   269                     emit q_ptr->scanEnded( iNumItemsAdded, data );
       
   270                     break;
       
   271                 default:
       
   272                     break;
       
   273             }
       
   274         }
       
   275     }
       
   276     else if( KMPXMessageIdItemChanged == id && iScanning ) {
       
   277         if ( aMsg.IsSupported( KMPXMessageArrayContents ) ) {
       
   278             // Loop through messages for arrays
       
   279             const CMPXMessageArray* messageArray =
       
   280                         aMsg.Value<CMPXMessageArray>( KMPXMessageArrayContents );
       
   281             User::LeaveIfNull( const_cast<CMPXMessageArray*>( messageArray ) );
       
   282 
       
   283             for ( TInt i=0; i<messageArray->Count(); ++i ) {
       
   284                   HandleCollectionMessage( messageArray->AtL( i ), KErrNone );
       
   285             }
       
   286             emit q_ptr->scanCountChanged( iNumItemsAdded );
       
   287         }
       
   288         else {
       
   289             // Single item
       
   290             TMPXChangeEventType changeType( aMsg.ValueTObjectL<TMPXChangeEventType>( KMPXMessageChangeEventType ) );
       
   291             TMPXGeneralCategory cat( aMsg.ValueTObjectL<TMPXGeneralCategory>( KMPXMessageMediaGeneralCategory ) );
       
   292             if( changeType == EMPXItemInserted &&
       
   293                 ( cat == EMPXSong || cat == EMPXPlaylist || cat == EMPXPodcast ) ) {
       
   294                 iNumItemsAdded++;
       
   295             }
       
   296         }
       
   297     }
       
   298     TX_EXIT
       
   299 }
       
   300 
       
   301 /*!
       
   302  \internal
       
   303  Returns false if same event has been received more than once
       
   304  */
       
   305 TBool MpMpxHarvesterFrameworkWrapperPrivate::BroadcastEventFilter( TInt aMsg )
       
   306 {
       
   307     TX_ENTRY_ARGS( "New msg=" << aMsg << ", Prev. msg=" << iPreviousBroadCastMsg );
       
   308     if ( aMsg != iPreviousBroadCastMsg ) {
       
   309         iPreviousBroadCastMsg = aMsg;
       
   310         return true;
       
   311     }
       
   312 
       
   313     return false;    
       
   314 }
       
   315 
       
   316 /*!
       
   317  \internal
       
   318  Request Harvester to check if there are any system events active.
       
   319  */
       
   320 void MpMpxHarvesterFrameworkWrapperPrivate::DoCheckForSystemEventsL()
       
   321 {
       
   322     TX_ENTRY
       
   323     iPreviousBroadCastMsg = NoPreviousBroadCastMsg;    
       
   324     iHarvesterUtility->CheckForSystemEventsL();
       
   325     TX_EXIT
       
   326 }
       
   327