harvester/harvesterserver/src/cpixstateobserver.cpp
changeset 24 65456528cac2
equal deleted inserted replaced
23:d4d56f5e7c55 24:65456528cac2
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cpixstateobserver.h"
       
    19 #include <mpxcollectionutility.h>
       
    20 #include <mpxmessagegeneraldefs.h>
       
    21 #include <mpxcollectionmessage.h>
       
    22 #include "OstTraceDefinitions.h"
       
    23 #ifdef OST_TRACE_COMPILER_IN_USE
       
    24 #include "cpixstateobserverTraces.h"
       
    25 #endif
       
    26 
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CPiXStateObserver::NewL()
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CPiXStateObserver* CPiXStateObserver::NewL( MCPiXStateObserver* aObserver, RFs* aFsSession )
       
    33     {        
       
    34     CPiXStateObserver* self = new ( ELeave ) CPiXStateObserver(aObserver);
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL( aFsSession );
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39     }
       
    40 
       
    41 
       
    42 CPiXStateObserver::CPiXStateObserver(MCPiXStateObserver* aObserver)
       
    43             : iObserver(aObserver)                                
       
    44                     
       
    45     {
       
    46     iPreviousState = KErrNotFound;
       
    47     iMMCHarvesting = KErrNotFound;
       
    48     iMPXHarvesting = KErrNotFound;    
       
    49     }
       
    50 // -----------------------------------------------------------------------------
       
    51 // CPiXStateObserver::~CPiXStateObserver()
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CPiXStateObserver::~CPiXStateObserver()
       
    55    {
       
    56    iHarvesterClient.RemoveHarvesterEventObserver(*this);
       
    57    iHarvesterClient.Close();
       
    58    }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CPiXStateObserver::ConstructL()
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CPiXStateObserver::ConstructL( RFs* aFsSession )
       
    65     {    
       
    66     iFsSession = aFsSession;
       
    67     }
       
    68 
       
    69 void CPiXStateObserver::StartMonitoringL()
       
    70     {
       
    71     TInt err(KErrNone);
       
    72     err = iHarvesterClient.Connect();    
       
    73     
       
    74     if(err == KErrNone)
       
    75         {
       
    76         err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeMMC, 1000 );        
       
    77         }
       
    78     iCollectionUtility = MMPXCollectionUtility::NewL( this );
       
    79 
       
    80     }
       
    81 // -----------------------------------------------------------------------------
       
    82 // CPiXStateObserver::HarvestingUpdated()
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CPiXStateObserver::HarvestingUpdated( HarvesterEventObserverType aHEObserverType, 
       
    86              HarvesterEventState aHarvesterEventState, TInt aItemsLeft  )
       
    87     {    
       
    88     if(aHEObserverType == EHEObserverTypeMMC)
       
    89         {
       
    90         switch(aHarvesterEventState)
       
    91             {
       
    92             case EHEStateStarted:
       
    93             case EHEStateHarvesting:            
       
    94                 {
       
    95                 iMMCHarvesting = ETrue;                
       
    96                 break;
       
    97                 }
       
    98             case EHEStateFinished:
       
    99             case EHEStateUninitialized:
       
   100                 {
       
   101                 iMMCHarvesting = EFalse;                
       
   102                 break;
       
   103                 }
       
   104             default:
       
   105                 break;
       
   106             }
       
   107         OstTrace0( TRACE_FLOW, CPIXSTATEOBSERVER_HARVESTINGUPDATED, "CPiXStateObserver::HarvestingUpdated MMC Event" );        
       
   108         NotifyObserverL();
       
   109         }    
       
   110     }
       
   111 
       
   112 void CPiXStateObserver::HandleCollectionMessage( CMPXMessage* aMessage, TInt aError )
       
   113     {
       
   114     if ( aError != KErrNone )
       
   115         {
       
   116         return;
       
   117         }
       
   118     
       
   119     TMPXMessageId generalId( *aMessage->Value<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   120     
       
   121     //we are interestead of only general system events
       
   122     if ( generalId == KMPXMessageGeneral )
       
   123         {
       
   124         TInt event( *aMessage->Value<TInt>( KMPXMessageGeneralEvent ) );
       
   125         TInt op( *aMessage->Value<TInt>( KMPXMessageGeneralType ) );
       
   126         
       
   127         if ( event == TMPXCollectionMessage::EBroadcastEvent )
       
   128             {
       
   129             switch( op )
       
   130                 {
       
   131                 //when MTP sync or music collection is started then pause processing
       
   132                 case EMcMsgRefreshStart:
       
   133                 case EMcMsgUSBMTPStart:
       
   134                     {
       
   135                     iMPXHarvesting = ETrue;
       
   136                     break;
       
   137                     }
       
   138                 //when MTP sync or music collection refresh is complete then resume processing
       
   139                 case EMcMsgRefreshEnd:
       
   140                 case EMcMsgUSBMTPEnd:
       
   141                 case EMcMsgUSBMTPNotActive:
       
   142                     {
       
   143                     iMPXHarvesting = EFalse;
       
   144                     break;
       
   145                     }
       
   146                 default:
       
   147                     break;
       
   148                 }
       
   149             OstTrace0( TRACE_FLOW, CPIXSTATEOBSERVER_HANDLECOLLECTIONMESSAGE, "CPiXStateObserver::HandleCollectionMessage MPX Event" );            
       
   150             NotifyObserverL();
       
   151             }        
       
   152         }
       
   153     }
       
   154 
       
   155 void CPiXStateObserver::HandleOpenL( const CMPXMedia& /*aEntries*/, TInt /*aIndex*/,
       
   156                                                TBool /*aComplete*/, TInt /*aError*/ )
       
   157      {
       
   158      // not needed here
       
   159      }
       
   160 
       
   161 void CPiXStateObserver::HandleOpenL( const CMPXCollectionPlaylist& /*aPlaylist*/, TInt /*aError*/ )
       
   162    {
       
   163    // not needed here
       
   164    }
       
   165 
       
   166 void CPiXStateObserver::HandleCollectionMediaL( const CMPXMedia& /*aMedia*/,
       
   167                                                        TInt /*aError*/ )
       
   168     {
       
   169     // not needed here
       
   170     }
       
   171 
       
   172 TBool CPiXStateObserver::GetStatus()
       
   173     {
       
   174     TBool ret = EFalse;
       
   175     if( iMMCHarvesting || iMPXHarvesting )
       
   176         ret = ETrue;
       
   177     return ret;        
       
   178     }
       
   179 
       
   180 void CPiXStateObserver::NotifyObserverL()
       
   181     {
       
   182     TBool status = GetStatus();
       
   183     if( iPreviousState != status )
       
   184             {
       
   185             iPreviousState = status; 
       
   186             if (iObserver)
       
   187                 {
       
   188                 iObserver->HandleStateObserverChangeL(status);
       
   189                 OstTrace1( TRACE_FLOW, CPIXSTATEOBSERVER_NOTIFYOBSERVERL, "CPiXStateObserver::NotifyObserverL status=%d", status );
       
   190                 
       
   191                 }
       
   192             }    
       
   193     }