homesync/contentmanager/cmserver/cmscheduler/src/cmscheduler.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 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:  Content Manager server's scheduler component
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <apgtask.h>
       
    21 
       
    22 #include "cmsettings.h"
       
    23 #include "cmcommonutils.h"
       
    24 #include "cmscheduler.h"
       
    25 #include "mediaservantuid.h"
       
    26 #include "cmcommsdbnotifier.h"
       
    27 #include "cmcenrepnotifier.h"
       
    28 #include "msdebug.h"
       
    29 
       
    30 // WLAN scanning interval [s]
       
    31 const TInt
       
    32     KTimerInterval = 30 * 60 * 1000 * 1000; // 30 minutes in microseconds
       
    33 const TInt KTimerCount = 2; // KTimerCount*KTimerInterval = 1 hour
       
    34 const TUid KMediaServantUid = { KMediaServantUID3 }; // application uid
       
    35 const TInt KOfflineProfile = 5; // offline profile identifier
       
    36 
       
    37 // ========================== MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // Two-phased constructor.
       
    40 EXPORT_C CCmScheduler* CCmScheduler::NewL(
       
    41     MCmServiceObserver& aServer, MCmSettings& aSettings)
       
    42     {
       
    43     LOG(_L("[Cm Scheduler]\t CCmScheduler::NewL"));
       
    44     CCmScheduler* self = new ( ELeave )
       
    45         CCmScheduler( aServer, aSettings );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 // Destructor
       
    51 CCmScheduler::~CCmScheduler()
       
    52     {
       
    53     LOG(_L("[Cm Scheduler]\t CCmScheduler::~CCmScheduler"));
       
    54 
       
    55     Cancel();
       
    56     delete iNotifier;
       
    57     delete iRepositoryNotifier;
       
    58     iConnMon.CancelNotifications();
       
    59     iConnMon.Close();
       
    60     iTimer.Close();
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CCmScheduler::CCmScheduler
       
    65 // C++ default constructor can NOT contain any code, that
       
    66 // might leave.
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69 CCmScheduler::CCmScheduler(
       
    70     MCmServiceObserver& aServer, MCmSettings& aSettings)
       
    71     : CActive( EPriorityStandard ),
       
    72     iServer( aServer ), iSettings( aSettings ),
       
    73     iScheduledServiceRunning( EFalse ), iEnabled( ETrue ),
       
    74     iState( ECmScStateOffline ), iTimerCount( 0 ),
       
    75     iServiceToExecute( ECmServicePreProcessingStore ),
       
    76     iExecuteHarvest( ETrue ), iSchedulerInitiated( EFalse )
       
    77     {
       
    78     LOG(_L("[Cm Scheduler]\t CCmScheduler::CCmScheduler()"));
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CCmScheduler::ConstructL()
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 void CCmScheduler::ConstructL()
       
    86     {
       
    87     LOG(_L("[Cm Scheduler]\t CCmScheduler::ConstructL"));
       
    88 
       
    89     // Ensure that iap is set. Otherwise scheduler cannot be used
       
    90 #ifdef __DEBUG
       
    91     TInt iap( 0 );
       
    92     User::LeaveIfError( iSettings.GetIapL( iap ) );
       
    93     TRACE( Print( _L("[Cm Scheduler]\t IAP to use is  %d"), iap));
       
    94 #endif
       
    95 
       
    96     User::LeaveIfError( iTimer.CreateLocal() );
       
    97     CActiveScheduler::Add( this );
       
    98     iEnabled = EFalse;
       
    99 
       
   100     iRepositoryNotifier = CCmCenrepNotifier::NewL( *this );
       
   101     User::LeaveIfError( iRepositoryNotifier->GetCurrentProfile(
       
   102                         iCurrentProfile ) );
       
   103 
       
   104     // create commsdb notifier
       
   105     TRAPD( error, iNotifier = CCmCommsDbNotifier::NewL( *this ) );
       
   106 
       
   107     if ( !error )
       
   108         {
       
   109         iWlanScanState = iNotifier->WlanScanStateL();
       
   110         }
       
   111     else
       
   112         {
       
   113         TRACE( Print( _L("[Cm Scheduler]\t CCmScheduler::ConstructL \
       
   114         error = %d"), error));
       
   115         }
       
   116 
       
   117     // check that mc is not in offline mode
       
   118     if ( iCurrentProfile != KOfflineProfile )
       
   119         {
       
   120         iState = ECmScStateOnline;
       
   121         if ( error == KErrNone )
       
   122             {
       
   123             // We assume that scan is off.
       
   124             // State is checked and if it is on wlan events can be used.
       
   125             if ( iNotifier->HasScanStateChangedL() )
       
   126                 {
       
   127                 LOG(_L("[Cm Scheduler]\t CCmScheduler::ConstructL() \
       
   128                     Scanning state changed on"));
       
   129                 // scanning is on
       
   130                 SetEnabledL( ETrue );
       
   131                 }
       
   132 
       
   133             else
       
   134                 {
       
   135                 LOG(_L("[Cm Scheduler]\t CCmScheduler::ConstructL() \
       
   136                     Scanning state is off - starting timer"));
       
   137                 // scanning is off - use timer
       
   138                 TryToStartRetryTimer();
       
   139                 }
       
   140             }
       
   141         else
       
   142             {
       
   143             LOG(_L("[Cm Scheduler]\t CCmScheduler::ConstructL() \
       
   144                 Notifier creation failed"));
       
   145             // if notifier cannot be created we start the timer
       
   146             TryToStartRetryTimer();
       
   147             }
       
   148         }
       
   149     else
       
   150         {
       
   151         LOG(_L("[Cm Scheduler]\t CCmScheduler::ConstructL() \
       
   152             profile = offline"));
       
   153         }
       
   154     }
       
   155 
       
   156 // --------------------------------------------------------------------------
       
   157 // CCmScheduler::EventL()
       
   158 // Called when an event arrives to connection monitor
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 void CCmScheduler::EventL( const CConnMonEventBase& aConnMonEvent )
       
   162     {
       
   163     TRACE(Print(_L("[Cm Scheduler]\t CCmScheduler::EventL() \
       
   164         eventtype = %d, connection id = %d"),
       
   165         aConnMonEvent.EventType(), aConnMonEvent.ConnectionId()));
       
   166 
       
   167     TTime currentTime;
       
   168     currentTime.HomeTime();
       
   169 
       
   170     TTimeIntervalHours interval;
       
   171     currentTime.HoursFrom( iLastSyncTime, interval );
       
   172 
       
   173     TRACE(Print(_L("[Cm Scheduler]\t CCmScheduler::EventL() \
       
   174 	    hours from last sync = %d"), interval.Int()));
       
   175 
       
   176     if ( interval.Int() >= 1 && !ApplicationRunning() )
       
   177         {
       
   178         HandleConnectionEventL( aConnMonEvent );
       
   179         }
       
   180 
       
   181     }
       
   182 
       
   183 // --------------------------------------------------------------------------
       
   184 // CCmScheduler::HandleConnectionEventL()
       
   185 // Handles connection event
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 void CCmScheduler::HandleConnectionEventL(
       
   189                             const CConnMonEventBase& aConnMonEvent )
       
   190     {
       
   191     LOG(_L("[Cm Scheduler]\t CCmScheduler::HandleConnectionEventL() \
       
   192 	    HandleConnectionEventL"));
       
   193 
       
   194     if ( aConnMonEvent.EventType() == EConnMonIapAvailabilityChange )
       
   195         {
       
   196         LOG(_L("[Cm Scheduler]\t CCmScheduler::HandleConnectionEventL() \
       
   197             EConnMonIapAvailabilityChange"));
       
   198 
       
   199         TCmSchedulerState newState = ECmScStateOffline;
       
   200 
       
   201         if ( CheckIapAvailabilityL( aConnMonEvent ) )
       
   202             {
       
   203             newState = ECmScStateOnline;
       
   204             }
       
   205 
       
   206         if ( newState != iState )
       
   207             {
       
   208             iState = newState;
       
   209 
       
   210             if ( newState && !iScheduledServiceRunning )
       
   211                 {
       
   212                 LOG(_L("[Cm Scheduler]\t State changed to online,\
       
   213                     starting operation.."));
       
   214                 iSchedulerInitiated = ETrue;// do also harvest
       
   215                 TRACE( Print( _L("[Cm Scheduler]\t HandleConnectionEventL \
       
   216                     iSchedulerInitiated = %d"), iSchedulerInitiated));
       
   217                 iExecuteHarvest = ETrue;
       
   218                 TRACE( Print( _L("[Cm Scheduler]\t HandleConnectionEventL \
       
   219                     iExecuteHarvest = %d"), iExecuteHarvest));
       
   220                 TryToExecuteService( iServiceToExecute );
       
   221                 }
       
   222             else
       
   223                 {
       
   224                 LOG(_L("[Cm Scheduler]\t State changed to offline,\
       
   225                     canceling timer.."));
       
   226                 CancelTimer();
       
   227                 }
       
   228             }
       
   229         }
       
   230     }
       
   231 
       
   232 // --------------------------------------------------------------------------
       
   233 // CCmScheduler::RunL()
       
   234 // Called when the timer elapses
       
   235 // --------------------------------------------------------------------------
       
   236 //
       
   237 void CCmScheduler::RunL()
       
   238     {
       
   239     LOG(_L("[Cm Scheduler]\t CCmScheduler::RunL()"));
       
   240     TRACE( Print( _L("[Cm Scheduler]\t status %d"), iStatus.Int() ));
       
   241     TRACE( Print( _L("[Cm Scheduler]\t state %d"), iState ));
       
   242 
       
   243     if ( KErrNone == iStatus.Int() &&
       
   244          iState == ECmScStateOnline &&
       
   245          !iScheduledServiceRunning )
       
   246         {
       
   247         if ( ++iTimerCount >= KTimerCount && !ApplicationRunning() )
       
   248             {
       
   249             LOG(_L("[Cm Scheduler]\t Online timer passed, \
       
   250                 starting operation.."));
       
   251             iSchedulerInitiated = ETrue;// do also harvest
       
   252             TRACE( Print( _L("[Cm Scheduler]\t RunL \
       
   253                 iSchedulerInitiated = %d"), iSchedulerInitiated));
       
   254             iExecuteHarvest = ETrue;
       
   255             TRACE( Print( _L("[Cm Scheduler]\t RunL \
       
   256                 iExecuteHarvest = %d"), iExecuteHarvest));
       
   257             TryToExecuteService( iServiceToExecute );
       
   258             }
       
   259         else
       
   260             {
       
   261             iTimer.After( iStatus,
       
   262                 TTimeIntervalMicroSeconds32( KTimerInterval ) );
       
   263             SetActive();
       
   264             }
       
   265         }
       
   266     }
       
   267 
       
   268 // --------------------------------------------------------------------------
       
   269 // CCmScheduler::TryToExecuteService()
       
   270 // Starts process if application is not running
       
   271 // --------------------------------------------------------------------------
       
   272 //
       
   273 void CCmScheduler::TryToExecuteService( TCmService aService )
       
   274     {
       
   275     LOG(_L("[Cm Scheduler]\t CCmScheduler::TryToExecuteService()"));
       
   276     TInt err = KErrNone;
       
   277 
       
   278     TRAP( err, iServer.ExecuteServiceL( aService ));
       
   279     iScheduledServiceRunning = !err;
       
   280 
       
   281     if ( !err && aService == ECmServicePreProcessingStore )
       
   282         {
       
   283         iStorePreprocessed = EFalse;
       
   284         }
       
   285 
       
   286     TRACE( Print( _L("[Cm Scheduler]\t ExecuteServiceL err: %d"), err));
       
   287 
       
   288     if ( err )
       
   289         {
       
   290         TryToStartRetryTimer();
       
   291         }
       
   292     }
       
   293 
       
   294 // --------------------------------------------------------------------------
       
   295 // CCmScheduler::TryToStartRetryTimer()
       
   296 // Starts timer if not already active
       
   297 // --------------------------------------------------------------------------
       
   298 //
       
   299 void CCmScheduler::TryToStartRetryTimer()
       
   300     {
       
   301     LOG(_L("[Cm Scheduler]\t CCmScheduler::TryToStartRetryTimer()"));
       
   302 
       
   303     if ( !IsActive() )
       
   304         {
       
   305         LOG(_L("[Cm Scheduler]\t starting one hour resync timer.."));
       
   306 
       
   307         CancelTimer();
       
   308 
       
   309         iTimer.After(
       
   310                 iStatus, TTimeIntervalMicroSeconds32( KTimerInterval ));
       
   311         SetActive();
       
   312         }
       
   313     }
       
   314 
       
   315 // --------------------------------------------------------------------------
       
   316 // CCmScheduler::CancelTimer()
       
   317 // Cancels timer
       
   318 // --------------------------------------------------------------------------
       
   319 //
       
   320 void CCmScheduler::CancelTimer()
       
   321     {
       
   322     LOG(_L("[Cm Scheduler]\t CCmScheduler::CancelTimer"));
       
   323 
       
   324     iTimer.Cancel();
       
   325     iTimerCount = 0;
       
   326     }
       
   327 
       
   328 // --------------------------------------------------------------------------
       
   329 // CCmScheduler::SetEnabledL()
       
   330 // Enabled/disabled connection monitor events
       
   331 // --------------------------------------------------------------------------
       
   332 //
       
   333 EXPORT_C void CCmScheduler::SetEnabledL( TBool aEnable )
       
   334     {
       
   335     LOG(_L("[Cm Scheduler]\t CCmScheduler::SetEnabled()"));
       
   336     if ( iEnabled != aEnable )
       
   337         {
       
   338         iEnabled = aEnable;
       
   339         if ( iEnabled )
       
   340             {
       
   341             LOG(_L("[Cm Scheduler]\t enabling scheduler.."));
       
   342             LOG(_L("[Cm Scheduler]\t starting to listen wlan events.."));
       
   343             User::LeaveIfError( iConnMon.ConnectL() );
       
   344             iConnMon.NotifyEventL( *this );
       
   345 
       
   346             }
       
   347          else // iConnMon is connected when entering here...
       
   348             {
       
   349             LOG(_L("[Cm Scheduler]\t disabling scheduler.."));
       
   350 
       
   351             iConnMon.CancelNotifications();
       
   352             iConnMon.Close();
       
   353 
       
   354             }
       
   355         }
       
   356     }
       
   357 
       
   358 // --------------------------------------------------------------------------
       
   359 // CCmScheduler::SetServiceToExecute
       
   360 // Sets service to be executed
       
   361 // --------------------------------------------------------------------------
       
   362 //
       
   363 EXPORT_C void CCmScheduler::SetServiceToExecute( TCmService aService )
       
   364     {
       
   365     LOG(_L("[Cm Scheduler]\t CCmScheduler::SetServiceToExecute()"));
       
   366     iServiceToExecute = aService;
       
   367     }
       
   368 
       
   369 // --------------------------------------------------------------------------
       
   370 // CCmScheduler::ServiceExecuted
       
   371 // Called when service is ready
       
   372 // --------------------------------------------------------------------------
       
   373 //
       
   374 EXPORT_C void CCmScheduler::ServiceExecuted( TCmService aService, TInt aErr )
       
   375     {
       
   376     LOG(_L("[Cm Scheduler]\t CCmScheduler::ServiceExecuted()"));
       
   377     TRACE( Print( _L("[Cm Scheduler]\t service %d err %d"),
       
   378         aService, aErr));
       
   379 
       
   380     if ( !iScheduledServiceRunning )
       
   381         {
       
   382         LOG(_L("[Cm Scheduler]\t No scheduled service running, returning"));
       
   383         return;
       
   384         }
       
   385 
       
   386     iScheduledServiceRunning = EFalse;
       
   387     TBool startRetryTimer( EFalse );
       
   388     if ( aErr )
       
   389         {
       
   390         startRetryTimer = ETrue;
       
   391         }
       
   392     else
       
   393         {
       
   394         switch ( aService )
       
   395             {
       
   396             case ECmServicePreProcessingStore:
       
   397                 {
       
   398                 if ( iStorePreprocessed == EFalse )
       
   399                     {
       
   400                     iStorePreprocessed = ETrue;
       
   401                     TryToExecuteService( ECmServiceStore );
       
   402                     }
       
   403                 else
       
   404                     {
       
   405                     iLastSyncTime.HomeTime();
       
   406                     startRetryTimer = ETrue;
       
   407                     iSchedulerInitiated = EFalse;
       
   408                     }
       
   409                 break;
       
   410                 }
       
   411             case ECmServiceStore:
       
   412                 {
       
   413                 // execute fill
       
   414                 TryToExecuteService( ECmServiceFill );
       
   415                 break;
       
   416                 }
       
   417 
       
   418             case ECmServiceFill:
       
   419                 {
       
   420                 if ( iExecuteHarvest )
       
   421                     {
       
   422                     TRACE( Print( _L("[Cm Scheduler]\t serviceexecuted \
       
   423                         harvest %d schedulerinitiated %d"),
       
   424                         iExecuteHarvest, iSchedulerInitiated));
       
   425                     // execute harvest
       
   426                     TryToExecuteService( ECmServiceHarvest );
       
   427                     }
       
   428                 else
       
   429                     {
       
   430                     LOG(_L("[Cm Scheduler]\t CCmScheduler::ServiceExecuted \
       
   431                         ExecuteHarvest = EFalse"));
       
   432                     startRetryTimer = ETrue;
       
   433                     iLastSyncTime.HomeTime();
       
   434                     iSchedulerInitiated = EFalse;
       
   435                     TRACE( Print( _L("[Cm Scheduler]\t ServiceExecuted \
       
   436                          iSchedulerInitiated = %d"), iSchedulerInitiated));
       
   437                     }
       
   438                 break;
       
   439                 }
       
   440 
       
   441             case ECmServiceHarvest:
       
   442             // fall through
       
   443             case ECmServicePreProcessingFill:
       
   444                 {
       
   445                 iSchedulerInitiated = EFalse;
       
   446                 TRACE( Print( _L("[Cm Scheduler]\t ServiceExecuted \
       
   447                     iSchedulerInitiated = %d"), iSchedulerInitiated));
       
   448                 startRetryTimer = ETrue;
       
   449                 iLastSyncTime.HomeTime();
       
   450                 break;
       
   451                 }
       
   452 
       
   453             default:
       
   454                 {
       
   455                 LOG(_L("[Cm Scheduler]\t default"));
       
   456                 break;
       
   457                 }
       
   458             }
       
   459 
       
   460         }
       
   461     if ( startRetryTimer )
       
   462         {
       
   463         TryToStartRetryTimer();
       
   464         }
       
   465     }
       
   466 
       
   467 // --------------------------------------------------------------------------
       
   468 // CCmScheduler::DoCancel
       
   469 // Called by framework when timer is cancelled
       
   470 // --------------------------------------------------------------------------
       
   471 //
       
   472 void CCmScheduler::DoCancel()
       
   473     {
       
   474     LOG(_L("[Cm Scheduler]\t CCmScheduler::DoCancel()"));
       
   475 
       
   476     CancelTimer();
       
   477     }
       
   478 
       
   479 // --------------------------------------------------------------------------
       
   480 // CCmScheduler::WlanScanStateChanged
       
   481 // starts/disables timer and connection monitor events depending on state
       
   482 // of wlan scanning interval
       
   483 // --------------------------------------------------------------------------
       
   484 //
       
   485 void CCmScheduler::WlanScanStateChanged( TInt aState )
       
   486     {
       
   487     LOG(_L("[Cm Scheduler]\t CCmScheduler::WlanScanStateChanged()"));
       
   488 
       
   489     iWlanScanState = aState;
       
   490 
       
   491     if ( iCurrentProfile != KOfflineProfile )
       
   492         {
       
   493         if ( aState == KWlanScanNetworkNever )
       
   494             {
       
   495             TRAP_IGNORE( SetEnabledL( EFalse ) );
       
   496             // state is set online so we can try start process
       
   497             iState = ECmScStateOnline;
       
   498             TryToStartRetryTimer();
       
   499             }
       
   500         else
       
   501             {
       
   502             // cancel timer
       
   503             CancelTimer();
       
   504 
       
   505             TRAP_IGNORE( SetEnabledL( ETrue ) );
       
   506             }
       
   507         }
       
   508     }
       
   509 
       
   510 
       
   511 // --------------------------------------------------------------------------
       
   512 // CCmScheduler::ProfileChangedL
       
   513 // --------------------------------------------------------------------------
       
   514 //
       
   515 void CCmScheduler::ProfileChangedL( TInt aProfile )
       
   516     {
       
   517     LOG(_L("[Cm Scheduler]\t CCmScheduler::ProfileChangedL()"));
       
   518 
       
   519     if ( aProfile == KOfflineProfile )
       
   520         {
       
   521         LOG(_L("[Cm Scheduler]\t CCmScheduler::ProfileChangedL() \
       
   522             offline"));
       
   523 
       
   524         iCurrentProfile = aProfile;
       
   525 
       
   526         // disable wlan scanning
       
   527         CmCommonUtils::SetWlanScanL( KWlanScanNetworkNever );
       
   528 
       
   529         // stop receiving events
       
   530         SetEnabledL( EFalse );
       
   531         // cancel timer
       
   532         CancelTimer();
       
   533         }
       
   534     else if ( iCurrentProfile == KOfflineProfile )
       
   535         {
       
   536         LOG(_L("[Cm Scheduler]\t CCmScheduler::ProfileChangedL() \
       
   537             online"));
       
   538 
       
   539         iCurrentProfile = aProfile;
       
   540 
       
   541         // enable wlan scanning
       
   542         CmCommonUtils::SetWlanScanL( KWlanScanNetworkInterval60 );
       
   543 
       
   544         if ( iWlanScanState )
       
   545             {
       
   546             SetEnabledL( ETrue );
       
   547             }
       
   548         else
       
   549             {
       
   550             TryToStartRetryTimer();
       
   551             }
       
   552         }
       
   553     }
       
   554 
       
   555 // --------------------------------------------------------------------------
       
   556 // CCmScheduler::SetScheduledServiceState
       
   557 // --------------------------------------------------------------------------
       
   558 //
       
   559 EXPORT_C void CCmScheduler::SetScheduledServiceState( TBool aState )
       
   560     {
       
   561     LOG(_L("[Cm Scheduler]\t CCmScheduler::SetScheduledServiceState()"));
       
   562 
       
   563     iScheduledServiceRunning = aState;
       
   564     // we don't want to make second round
       
   565     iStorePreprocessed = ETrue;
       
   566     // This function is called when application transfers responsibility
       
   567     // to scheduler. In this case we don't want to do harvest.
       
   568     if ( !iSchedulerInitiated )
       
   569         {
       
   570         LOG(_L("[Cm Scheduler]\t CCmScheduler::SetScheduledServiceState() \
       
   571             iSchedulerInitiated = EFalse"));
       
   572         iExecuteHarvest = EFalse;
       
   573         TRACE( Print( _L("[Cm Scheduler]\t SetScheduledServiceState \
       
   574             iExecuteHarvest = %d"), iExecuteHarvest));
       
   575         }
       
   576 
       
   577     }
       
   578 
       
   579 // --------------------------------------------------------------------------
       
   580 // CCmScheduler::RunError
       
   581 // --------------------------------------------------------------------------
       
   582 //
       
   583 TInt CCmScheduler::RunError( TInt aError )
       
   584     {
       
   585     TRACE( Print( _L("[Cm Scheduler]\t CCmScheduler::RunError \
       
   586         error = %d"), aError));
       
   587 
       
   588     return KErrNone;
       
   589     }
       
   590 
       
   591 // --------------------------------------------------------------------------
       
   592 // CCmScheduler::ApplicationRunning
       
   593 // --------------------------------------------------------------------------
       
   594 //
       
   595 TBool CCmScheduler::ApplicationRunning()
       
   596     {
       
   597     LOG(_L("[Cm Scheduler]\t CCmScheduler::ApplicationRunning()"));
       
   598 
       
   599     TBool mediaServantRunning( EFalse );
       
   600     RWsSession wsSession;
       
   601     TInt err = wsSession.Connect();
       
   602     if ( !err )
       
   603         {
       
   604         TApaTaskList taskList( wsSession );
       
   605         mediaServantRunning = taskList.FindApp( KMediaServantUid ).Exists();
       
   606         wsSession.Close();
       
   607         }
       
   608     return mediaServantRunning;
       
   609     }
       
   610 
       
   611 // --------------------------------------------------------------------------
       
   612 // CCmScheduler::CheckIapAvailabilityL()
       
   613 // --------------------------------------------------------------------------
       
   614 //
       
   615 TBool CCmScheduler::CheckIapAvailabilityL(
       
   616                             const CConnMonEventBase& aConnMonEvent )
       
   617     {
       
   618     LOG(_L("[Cm Scheduler]\t CCmScheduler::CheckIapAvailabilityL()"));
       
   619 
       
   620     TBool iapFound( EFalse );
       
   621     TInt accessPoint( -1 );
       
   622     User::LeaveIfError( iSettings.GetIapL( accessPoint ) );
       
   623     TRACE( Print( _L("[Cm Scheduler]\t \
       
   624         IAP to use is  %d"), accessPoint));
       
   625 
       
   626     CConnMonIapAvailabilityChange* eventIap =
       
   627                     ( CConnMonIapAvailabilityChange* ) &aConnMonEvent;
       
   628 
       
   629     TConnMonIapInfo iaps = eventIap->IapAvailability();
       
   630 
       
   631     for ( TInt i = 0; i < iaps.iCount; i++ )
       
   632         {
       
   633         // Compare available IAPs to our IAP
       
   634         TRACE( Print( _L("[Cm Scheduler]\t CONNMON iap: %d"),
       
   635             iaps.iIap[i].iIapId));
       
   636         if ( accessPoint == iaps.iIap[i].iIapId )
       
   637             {
       
   638             LOG(_L("[Cm Scheduler]\t FOUND CORRECT IAP!"));
       
   639             iapFound = ETrue;
       
   640             i = iaps.iCount;
       
   641             }
       
   642         }
       
   643     return iapFound;
       
   644     }
       
   645 
       
   646 // End of File