videoscheduler/SchedulerServer/src/CCseSchedulerMultiPluginController.cpp
branchRCL_3
changeset 23 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
22:826cea16efd9 23:13a33d82ad98
       
     1 /*
       
     2 * Copyright (c) 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 the License "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:    Base class for multi plugin controllers*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CCseSchedulerMultiPluginController.h"
       
    23 #include "CseDebug.h"                           // Debug macros
       
    24 #include "CCseSchedulerPluginStarter.h"
       
    25 #include "CCseSchedulerLandLord.h"
       
    26 #include <ipvideo/CCseScheduledProgram.h>
       
    27 #include "CCseSchedulerTimer.h"
       
    28 #include "CCseSchedulerServerEngine.h"
       
    29 #include "CCseSchedulerThreadPacket.h"
       
    30 
       
    31 // EXTERNAL DATA STRUCTURES
       
    32 // None.
       
    33 
       
    34 // EXTERNAL FUNCTION PROTOTYPES  
       
    35 // None.
       
    36 
       
    37 // CONSTANTS
       
    38 // None
       
    39 
       
    40 // MACROS
       
    41 // None.
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 // None.
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 // None.
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 // None.
       
    51 
       
    52 
       
    53 // ============================ MEMBER FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCseSchedulerPluginControllerBase::CCseSchedulerMultiPluginController
       
    57 // C++ default constructor can NOT contain any code, that might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CCseSchedulerMultiPluginController::CCseSchedulerMultiPluginController(
       
    61                                         CCseSchedulerServerEngine& aEngine,
       
    62                                         TInt32 aPluginUid ) :
       
    63                                         CCseSchedulerPluginControllerBase( aEngine, aPluginUid )
       
    64 
       
    65     {
       
    66     CSELOGSTRING_HIGH_LEVEL(
       
    67         ">>>CCseSchedulerMultiPluginController::CCseSchedulerMultiPluginController");
       
    68         
       
    69     CSELOGSTRING_HIGH_LEVEL(
       
    70         "<<<CCseSchedulerMultiPluginController::CCseSchedulerMultiPluginController");
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCseSchedulerMultiPluginController::NewL
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CCseSchedulerMultiPluginController* CCseSchedulerMultiPluginController::NewL( 
       
    79                                         CCseSchedulerServerEngine& aEngine,
       
    80                                         TInt32 aPluginUid )
       
    81     {
       
    82     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::NewL");
       
    83     
       
    84     CCseSchedulerMultiPluginController* self = 
       
    85             new( ELeave ) CCseSchedulerMultiPluginController( aEngine, aPluginUid );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     CleanupStack::Pop( self );
       
    89     
       
    90     CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::NewL");
       
    91     return self;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CCseSchedulerMultiPluginController::ConstructL
       
    96 // Symbian 2nd phase constructor can leave.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CCseSchedulerMultiPluginController::ConstructL()
       
   100     {
       
   101     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::ConstructL");
       
   102 
       
   103     CCseSchedulerPluginControllerBase::ConstructL();
       
   104        
       
   105 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::ConstructL");
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCseSchedulerMultiPluginController::~CCseSchedulerMultiPluginController
       
   110 // Destructor.
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CCseSchedulerMultiPluginController::~CCseSchedulerMultiPluginController()
       
   114     {
       
   115     CSELOGSTRING_HIGH_LEVEL(
       
   116         ">>>CCseSchedulerMultiPluginController::~CCseSchedulerMultiPluginController");
       
   117     
       
   118     iLandLords.ResetAndDestroy( );
       
   119     iLandLords.Close();    
       
   120 		
       
   121     CSELOGSTRING_HIGH_LEVEL(
       
   122         "<<<CCseSchedulerMultiPluginController::~CCseSchedulerMultiPluginController");
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCseSchedulerMultiPluginController::RunPluginsL
       
   127 //
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CCseSchedulerMultiPluginController::RunPluginsL()
       
   131     {
       
   132     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::RunPluginsL");
       
   133     TBool scheduleAlreadyRunning( EFalse );
       
   134     
       
   135     if(iScheduleArray.Count() >0 )
       
   136         {
       
   137         // Kick those schedules running that aren't already running
       
   138         for( TInt i = 0; i < iScheduleArray.Count(); i++)
       
   139             {
       
   140             for ( TInt ii = 0; ii < iLandLords.Count(); ii++ )
       
   141                 {
       
   142                 if( iScheduleArray[i]->DbIdentifier() ==
       
   143                         iLandLords[ii]->ThreadPacket()->Schedule()->DbIdentifier() )
       
   144                     {
       
   145                     scheduleAlreadyRunning = ETrue;
       
   146                     }                
       
   147                 }
       
   148             if( !scheduleAlreadyRunning )
       
   149                 {
       
   150                 if( iEngine.IsAllowedToRun( iScheduleArray[i]->DbIdentifier() ) )
       
   151                     {                    
       
   152                     // Create new LandLord for each schedule to be run
       
   153                     CCseSchedulerLandLord* landLord = CCseSchedulerLandLord::NewL( this );
       
   154                                                   
       
   155                     CleanupStack::PushL( landLord );                    
       
   156                                                                                     
       
   157                     // Set schedule for LandLord
       
   158                     landLord->SetScheduleL( *iScheduleArray[i] );
       
   159                     
       
   160                     // Increase run count
       
   161                     iEngine.IncreaseScheduleRunCountL( iScheduleArray[0]->DbIdentifier() );
       
   162                     
       
   163                     // Order the LandLord to run plugin
       
   164                     landLord->RunPluginL();
       
   165                     
       
   166                     CleanupStack::Pop( landLord );
       
   167                     
       
   168                     // Add created landLord to array. Destroyed later when landLord
       
   169                     // is not needed anymore.
       
   170                     iLandLords.AppendL( landLord );
       
   171                     
       
   172                     CleanupStack::Pop( landLord );
       
   173                     }        
       
   174                 else
       
   175                     {
       
   176                     // Schedule cannot be run anymore due to security reasons
       
   177                     // Signal engine to remove schedule from DB
       
   178                     iEngine.ScheduleNotValid( iScheduleArray[i]->DbIdentifier() );
       
   179                     
       
   180                     // Remove schedule own list
       
   181                     delete iScheduleArray[i];
       
   182                     iScheduleArray.Remove( i );
       
   183                     i--;
       
   184                     }
       
   185                 }
       
   186             }
       
   187         if( iLandLords.Count() == 0 )
       
   188             {
       
   189             // We've gone through all our schedules and still no LandLords.
       
   190             // We need to request new schedules.
       
   191             iEngine.RequestReschedule(); 
       
   192             }
       
   193         }
       
   194     else
       
   195         {
       
   196         // No schedules...!?!? REEEEESCHEDULE!!!
       
   197         iEngine.RequestReschedule();
       
   198         }     
       
   199         
       
   200     CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::RunPluginsL");
       
   201     }
       
   202     
       
   203 // -----------------------------------------------------------------------------
       
   204 // CCseSchedulerMultiPluginController::ScheduleCompletedL
       
   205 //
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CCseSchedulerMultiPluginController::ScheduleCompletedL( const TUint32 aDbIdentifier,
       
   209                                                              TInt aCompletitionCode )
       
   210 	{	
       
   211 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::ScheduleCompletedL");
       
   212 
       
   213     if ( aCompletitionCode == KErrNone )
       
   214         {
       
   215         ScheduleCompletedSuccesfullyL( aDbIdentifier );            
       
   216         }
       
   217     else
       
   218         {
       
   219         HandleScheduleErrorL( aDbIdentifier, aCompletitionCode );
       
   220         }    
       
   221  
       
   222 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::ScheduleCompletedL");
       
   223 	}
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CCseSchedulerUniPluginController::ScheduleCompletedSuccesfullyL
       
   227 //
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CCseSchedulerMultiPluginController::ScheduleCompletedSuccesfullyL( const TUint32 aDbIdentifier )
       
   231 	{
       
   232 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::ScheduleCompletedSuccesfullyL");
       
   233 
       
   234     // Remove schedule from list
       
   235     for ( TInt i = 0; i < iScheduleArray.Count(); i ++)
       
   236         {
       
   237         if( iScheduleArray[i]->DbIdentifier() == aDbIdentifier )
       
   238             {
       
   239             delete iScheduleArray[i];
       
   240             iScheduleArray.Remove( i );                
       
   241             }
       
   242         }
       
   243         
       
   244     // Notify engine about completition.
       
   245     iEngine.ScheduleCompletedSuccesfullyL( aDbIdentifier );
       
   246     
       
   247 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::ScheduleCompletedSuccesfullyL");	
       
   248 	}
       
   249 	
       
   250 // -----------------------------------------------------------------------------
       
   251 // CCseSchedulerMultiPluginController::HandleScheduleErrorl
       
   252 //
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CCseSchedulerMultiPluginController::HandleScheduleErrorL( const TUint32 aDbIdentifier,
       
   256                                                               TUint32 aCompletitionCode )
       
   257 	{	
       
   258 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::HandleScheduleError");
       
   259 	
       
   260 	// Here we could try to handle plugin errors. Problem is that scheduler doesn't
       
   261 	// know anything about schedule it is running and so there cannot be tailored
       
   262 	// error handling for each plugin. In the end, we just complete schedule
       
   263 	// to engine with error code (ends up removing schedule from DB).
       
   264 	
       
   265 	// Remove schedule from list
       
   266     for ( TInt i = 0; i < iScheduleArray.Count(); i ++)
       
   267         {
       
   268         if( iScheduleArray[i]->DbIdentifier() == aDbIdentifier )
       
   269             {
       
   270             delete iScheduleArray[i];
       
   271             iScheduleArray.Remove( i ); 
       
   272             break;               
       
   273             }
       
   274         }
       
   275 	
       
   276 	iEngine.ScheduleCompletedWithErrorL( aDbIdentifier, aCompletitionCode );
       
   277 
       
   278 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::HandleScheduleError");
       
   279 	}
       
   280 	
       
   281 // -----------------------------------------------------------------------------
       
   282 // CCseSchedulerMultiPluginController::DoCleanUp::DoCleanUp
       
   283 //
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CCseSchedulerMultiPluginController::DoCleanUp( )
       
   287 	{
       
   288 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::DoCleanUp");
       
   289     TBool scheduleFound( EFalse );
       
   290 
       
   291     // Check all LandLords. If we found that there is no schedules related to 
       
   292     // one we destroy it.
       
   293     for (TInt i = iLandLords.Count(); i > 0; i--)
       
   294         {
       
   295         for ( TInt ii = 0; ii < iScheduleArray.Count(); ii++ )
       
   296             {
       
   297             // Compare LandLords DbIdentifier with the ones in schedules
       
   298             if( iLandLords[i-1]->ThreadPacket()->Schedule()->DbIdentifier() ==
       
   299                     iScheduleArray[ii]->DbIdentifier() )
       
   300                 {
       
   301                 scheduleFound = ETrue;
       
   302                 break;
       
   303                 }            
       
   304             }
       
   305         // Remove LandLord if there is no schedule for it.
       
   306         if( !scheduleFound )
       
   307             {
       
   308             delete iLandLords[i-1];
       
   309             iLandLords.Remove(i-1);
       
   310             }
       
   311         scheduleFound = EFalse;
       
   312         }
       
   313    
       
   314     
       
   315 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::DoCleanUp");	
       
   316 	}
       
   317 	
       
   318 // -----------------------------------------------------------------------------
       
   319 // CCseSchedulerMultiPluginController::ClearPlugin
       
   320 //
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 void CCseSchedulerMultiPluginController::ClearControllerL( )
       
   324 	{	
       
   325 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerMultiPluginController::ClearControllerL");
       
   326 	for( TInt i = 0 ; i < iLandLords.Count() ; i++ )
       
   327 	    {
       
   328 	    iLandLords[i]->ClearL();
       
   329 	    }
       
   330 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerMultiPluginController::ClearControllerL");
       
   331 	}	
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CCseSchedulerMultiPluginController::IsControllerActive
       
   335 //
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 TBool CCseSchedulerMultiPluginController::IsControllerActive( )
       
   339     {
       
   340     TBool retVal( EFalse );
       
   341     
       
   342     for( TInt i = 0; i < iLandLords.Count(); i++ )
       
   343         {
       
   344         if( iLandLords[i]->IsWorking() )
       
   345             {
       
   346             retVal = ETrue ;
       
   347             break;
       
   348             }            
       
   349         }
       
   350     return retVal;
       
   351     }   
       
   352 
       
   353 // End of file.