internetradio2.0/uisrc/irsystemeventcollector.cpp
changeset 3 ee64f059b8e1
parent 2 2e1adbfc62af
child 4 3f2d53f144fe
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
     1 /*
       
     2 * Copyright (c) 2006-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:  Implementation of CIRSystemEventCollector
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32cmn.h>
       
    20 #include <UiklafInternalCRKeys.h>
       
    21 #include <centralrepository.h>
       
    22 
       
    23 #include "iraccessoryobserver.h"
       
    24 #include "irdiskspacewatcher.h"
       
    25 //#include "irrepositorymanager.h"
       
    26 #include "irsystemeventcollector.h"
       
    27 #include "irsystemeventdetector.h"
       
    28 #include "irdebug.h"
       
    29 
       
    30 // Constants
       
    31 const TInt KIRObserverArrayGranularity( 2 );
       
    32 const TInt KIR_DEFAULT_CRITICAL_LEVEL = 3145728;	// 3MB
       
    33 const TInt KThree =3;  
       
    34 // ---------------------------------------------------------------------------
       
    35 // Constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CIRSystemEventCollector::CIRSystemEventCollector() : 
       
    39     iSystemEventObservers( KIRObserverArrayGranularity )
       
    40     {
       
    41     IRLOG_DEBUG( "CIRSystemEventCollector::CIRSystemEventCollector" );
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Second-phase constructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CIRSystemEventCollector::ConstructL()
       
    49     {
       
    50     IRLOG_DEBUG( "CIRSystemEventCollector::ConstructL - Entering" );
       
    51     iSystemEventDetector = CIRSystemEventDetector::NewL( *this );
       
    52 
       
    53     iHeadsetObserver = CIRAccessoryObserver::NewL();
       
    54     iHeadsetObserver->SetObserver( this );
       
    55 
       
    56     TInt criticalLevel = 0;
       
    57 
       
    58 	CRepository* cenrep = CRepository::NewLC(KCRUidUiklaf );
       
    59 	TInt err = cenrep->Get(KUikOODDiskCriticalThreshold, criticalLevel);
       
    60 	CleanupStack::PopAndDestroy(cenrep);
       
    61 	if(err != KErrNone)
       
    62 		{
       
    63 		criticalLevel = KIR_DEFAULT_CRITICAL_LEVEL;
       
    64 		IRLOG_WARNING( "CIRSystemEventCollector::ConstructL - Failed to read criticalLevel. Using default 3MB" );
       
    65 		}
       
    66     criticalLevel = criticalLevel * KThree;
       
    67     iDiskSpaceWatcher = CIRDiskSpaceWatcher::NewL( static_cast<TInt64>( criticalLevel ), *this );
       
    68     iDiskSpaceWatcher->StartObservingDriveL( KVRDefaultDrive );
       
    69 
       
    70 	IRRDEBUG3("CIRSystemEventCollector::ConstructL - DiskSpaceWather started. driveNum=%d, criticalLevel=%d ", KVRDefaultDrive, criticalLevel );
       
    71 
       
    72     IRLOG_DEBUG( "CIRSystemEventCollector::ConstructL - Exiting" );
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Two-phased constructor
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CIRSystemEventCollector* CIRSystemEventCollector::NewL()
       
    80     {
       
    81     IRLOG_DEBUG( "CIRSystemEventCollector::NewL - Entering" );
       
    82     CIRSystemEventCollector* self = new( ELeave ) CIRSystemEventCollector;
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     CleanupStack::Pop(self);
       
    86     IRLOG_DEBUG( "CIRSystemEventCollector::NewL - Exiting" );
       
    87     return self;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // Destructor
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CIRSystemEventCollector::~CIRSystemEventCollector()
       
    95     {
       
    96     IRLOG_DEBUG( "CIRSystemEventCollector::~CIRSystemEventCollector - Entering" );
       
    97     delete iSystemEventDetector;
       
    98     delete iHeadsetObserver;
       
    99     
       
   100     if( iDiskSpaceWatcher )
       
   101 	    {
       
   102 	    delete iDiskSpaceWatcher;
       
   103 	    iDiskSpaceWatcher = NULL;
       
   104 	    }
       
   105 
       
   106     iSystemEventObservers.Close();
       
   107     IRLOG_DEBUG( "CIRSystemEventCollector::~CIRSystemEventCollector - Exiting" );
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Adds a system event observer
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C void CIRSystemEventCollector::AddObserverL( MIRSystemEventObserver* aHeadsetObserver )
       
   115     {
       
   116     IRLOG_DEBUG( "CIRSystemEventCollector::AddObserverL - Entering" );
       
   117     iSystemEventObservers.AppendL( aHeadsetObserver );
       
   118     IRLOG_DEBUG( "CIRSystemEventCollector::AddObserverL - Exiting" );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Removes a system event observer
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125  EXPORT_C void CIRSystemEventCollector::RemoveObserver( MIRSystemEventObserver* aSystemObserver )
       
   126     {
       
   127     IRLOG_DEBUG( "CIRSystemEventCollector::RemoveObserver - Entering" );
       
   128     TInt objectIndex = iSystemEventObservers.Find( aSystemObserver );
       
   129     
       
   130     if ( objectIndex != KErrNotFound )
       
   131         {
       
   132         iSystemEventObservers.Remove( objectIndex );
       
   133         }
       
   134     IRLOG_DEBUG( "CIRSystemEventCollector::RemoveObserver - Exiting" );
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Getter for mobile network state
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C TBool CIRSystemEventCollector::IsMobileNetworkCoverage() const
       
   142     {
       
   143     IRLOG_DEBUG( "CIRSystemEventCollector::IsMobileNetworkCoverage" );
       
   144     return iSystemEventDetector->IsMobileNetworkCoverage();
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Getter for network state
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C TBool CIRSystemEventCollector::IsNetworkCoverage() const
       
   152     {
       
   153     IRLOG_DEBUG( "CIRSystemEventCollector::IsNetworkCoverage" );
       
   154     return iSystemEventDetector->IsNetworkCoverage();
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Getter for call state
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C TBool CIRSystemEventCollector::IsCallActive() const
       
   162     {
       
   163     IRLOG_DEBUG( "CIRSystemEventCollector::IsCallActive" );
       
   164     return iSystemEventDetector->IsCallActive();
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // Getter for audio resource state
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C TBool CIRSystemEventCollector::IsAudioResourcesAvailable() const
       
   172     {
       
   173     IRLOG_DEBUG( "CIRSystemEventCollector::IsAudioResourcesAvailable" );
       
   174     return iSystemEventDetector->IsAudioResourcesAvailable();
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Getter for headset connection status
       
   179 // ---------------------------------------------------------------------------
       
   180 EXPORT_C TBool CIRSystemEventCollector::IsHeadsetConnected() const
       
   181     {
       
   182     IRLOG_DEBUG( "CIRSystemEventCollector::IsHeadsetConnected" );
       
   183     return iHeadsetObserver->IsHeadsetConnected();
       
   184     }
       
   185     
       
   186 // ---------------------------------------------------------------------------
       
   187 // Getter disk space state
       
   188 // ---------------------------------------------------------------------------
       
   189 EXPORT_C TBool CIRSystemEventCollector::IsDiskSpaceBelowCriticalLevel() const
       
   190     {
       
   191     return iDiskSpaceWatcher->IsBelowCriticalLevel( KVRDefaultDrive );
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // Getter Vocie UI state
       
   196 // ---------------------------------------------------------------------------
       
   197 EXPORT_C TBool CIRSystemEventCollector::IsVoiceUiActive() const
       
   198     {
       
   199     IRLOG_DEBUG( "CIRSystemEventCollector::IsVoiceUiActive" );
       
   200     return iSystemEventDetector->IsVoiceUiActive();
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // Notifies the observers of system event
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CIRSystemEventCollector::NotifyObserversL(TIRSystemEventType aEvent)
       
   208     {
       
   209     IRLOG_DEBUG( "CIRSystemEventCollector::NotifyObserversL - Entering" );
       
   210     for (TInt i = 0 ; i < iSystemEventObservers.Count() ; i++ )
       
   211         {
       
   212         iSystemEventObservers[i]->HandleSystemEventL( aEvent );
       
   213         }
       
   214     IRLOG_DEBUG( "CIRSystemEventCollector::NotifyObserversL - Exiting" );
       
   215     }
       
   216     
       
   217 // ---------------------------------------------------------------------------
       
   218 // From class MIRSystemEventDetectorObserver.
       
   219 // ---------------------------------------------------------------------------
       
   220 //        
       
   221 void CIRSystemEventCollector::NetworkUpCallbackL()
       
   222     {
       
   223     IRLOG_DEBUG( "CIRSystemEventCollector::NetworkUpCallbackL - Entering" );
       
   224     NotifyObserversL( EIRNetworkCoverageUp );
       
   225     IRLOG_DEBUG( "CIRSystemEventCollector::NetworkUpCallbackL - Exiting" );
       
   226     }
       
   227 
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // From class MIRSystemEventDetectorObserver.
       
   231 // ---------------------------------------------------------------------------
       
   232 //        
       
   233 void CIRSystemEventCollector::NetworkDownCallbackL()
       
   234     {
       
   235     IRLOG_DEBUG( "CIRSystemEventCollector::NetworkDownCallbackL - Entering" );
       
   236     NotifyObserversL( EIRNetworkCoverageDown );
       
   237     IRLOG_DEBUG( "CIRSystemEventCollector::NetworkDownCallbackL - Exiting" );
       
   238     }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // From class MIRSystemEventDetectorObserver.
       
   243 // ---------------------------------------------------------------------------
       
   244 //        
       
   245 void CIRSystemEventCollector::CallActivatedCallbackL()
       
   246     {
       
   247     IRLOG_DEBUG( "CIRSystemEventCollector::CallActivatedCallbackL - Entering" );
       
   248     NotifyObserversL( EIRCallActivated );
       
   249     IRLOG_DEBUG( "CIRSystemEventCollector::CallActivatedCallbackL - Exiting" );
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // From class MIRSystemEventDetectorObserver.
       
   255 // ---------------------------------------------------------------------------
       
   256 //        
       
   257 void CIRSystemEventCollector::CallDeactivatedCallbackL()
       
   258     {
       
   259     IRLOG_DEBUG( "CIRSystemEventCollector::CallDeactivatedCallbackL - Entering" );
       
   260     NotifyObserversL( EIRCallDeactivated );
       
   261     IRLOG_DEBUG( "CIRSystemEventCollector::CallDeactivatedCallbackL - Exiting" );
       
   262     }
       
   263 
       
   264     
       
   265 // ---------------------------------------------------------------------------
       
   266 // From class MIRSystemEventDetectorObserver.
       
   267 // ---------------------------------------------------------------------------
       
   268 //        
       
   269 void CIRSystemEventCollector::AudioResourcesAvailableL()
       
   270     { 
       
   271     IRLOG_DEBUG( "CIRSystemEventCollector::AudioResourcesAvailableL - Entering" );
       
   272     NotifyObserversL( EIRAudioResourcesAvailable );
       
   273     IRLOG_DEBUG( "CIRSystemEventCollector::AudioResourcesAvailableL - Exiting" );
       
   274     }
       
   275 
       
   276     
       
   277 // ---------------------------------------------------------------------------
       
   278 // From class MIRSystemEventDetectorObserver.
       
   279 // ---------------------------------------------------------------------------
       
   280 //        
       
   281 void CIRSystemEventCollector::AudioAutoResumeForbiddenL()
       
   282     {    
       
   283     IRLOG_DEBUG( "CIRSystemEventCollector::AudioAutoResumeForbiddenL - Entering" );
       
   284     NotifyObserversL( EIRAudioAutoResumeForbidden );
       
   285     IRLOG_DEBUG( "CIRSystemEventCollector::AudioAutoResumeForbiddenL - Exiting" );
       
   286     }
       
   287     
       
   288 // ---------------------------------------------------------------------------
       
   289 // From class MIRSystemEventDetectorObserver.
       
   290 // ---------------------------------------------------------------------------
       
   291 //        
       
   292 void CIRSystemEventCollector::ErrorCallbackL( TInt /* aError VRDEBUGVAR( aError ) d*/)
       
   293     {
       
   294     IRLOG_DEBUG( "CIRSystemEventCollector::ErrorCallbackL" );
       
   295     // P&S get fail not considered as a critical issue.
       
   296 	return;
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // From class MIRHeadsetEventObserver.
       
   301 // ---------------------------------------------------------------------------
       
   302 //        
       
   303 void CIRSystemEventCollector::HeadsetConnectedCallbackL()
       
   304     {
       
   305     IRLOG_DEBUG( "CIRSystemEventCollector::HeadsetConnectedCallbackL - Entering" );
       
   306     NotifyObserversL( EIRHeadsetConnected );
       
   307     IRLOG_DEBUG( "CIRSystemEventCollector::HeadsetConnectedCallbackL - Exiting" );
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // From class MIRHeadsetEventObserver.
       
   313 // ---------------------------------------------------------------------------
       
   314 //        
       
   315 void CIRSystemEventCollector::HeadsetDisconnectedCallbackL()
       
   316     {
       
   317     IRLOG_DEBUG( "CIRSystemEventCollector::HeadsetDisconnectedCallbackL - Entering" );
       
   318     NotifyObserversL( EIRHeadsetDisconnected );
       
   319     IRLOG_DEBUG( "CIRSystemEventCollector::HeadsetDisconnectedCallbackL - Exiting" );
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // From class MIRDiskSpaceWatcherObserver.
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 void CIRSystemEventCollector::NotifyLowDiskSpaceL()
       
   327     {
       
   328     IRLOG_DEBUG( "CIRSystemEventCollector::NotifyLowDiskSpaceL - Entering" );
       
   329     NotifyObserversL( EIRLowDiskSpace );
       
   330     IRLOG_DEBUG( "CIRSystemEventCollector::NotifyLowDiskSpaceL - Exiting" );
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // From class MIRAudioRoutingObserver.
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CIRSystemEventCollector::AudioRoutingChangedL( TVROutputDestination aOutputDestination )
       
   338     {
       
   339     IRLOG_DEBUG( "CIRSystemEventCollector::AudioRoutingChangedL - Entering" );
       
   340     TIRSystemEventType ev = EIRAudioRoutingHeadset; 
       
   341     if(aOutputDestination != EVRHeadset)
       
   342         {
       
   343         ev = EIRAudioRoutingSpeaker;
       
   344         }
       
   345 
       
   346     NotifyObserversL( ev );
       
   347     IRLOG_DEBUG( "CIRSystemEventCollector::AudioRoutingChangedL - Exiting" );
       
   348     }