videoscheduler/SchedulerServer/src/CCseSchedulerUniPluginController.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 uni plugin controllers*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CCseSchedulerUniPluginController.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 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 // None.
       
    32 
       
    33 // EXTERNAL FUNCTION PROTOTYPES  
       
    34 // None.
       
    35 
       
    36 // CONSTANTS
       
    37 // None
       
    38 
       
    39 // MACROS
       
    40 // None.
       
    41 
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 // None.
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 // None.
       
    47 
       
    48 // LOCAL FUNCTION PROTOTYPES
       
    49 // None.
       
    50 
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CCseSchedulerUniPluginController::CCseSchedulerUniPluginController
       
    56 // C++ default constructor can NOT contain any code, that might leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CCseSchedulerUniPluginController::CCseSchedulerUniPluginController (
       
    60                                         CCseSchedulerServerEngine& aEngine,
       
    61                                         TInt32 aPluginUid ) :
       
    62                                         CCseSchedulerPluginControllerBase( aEngine, aPluginUid ),                                        
       
    63                                         iLandLord( NULL ),
       
    64                                         iIsLandLordWorking( EFalse )
       
    65     {
       
    66     CSELOGSTRING_HIGH_LEVEL(
       
    67         ">>>CCseSchedulerUniPluginController::CCseSchedulerUniPluginController");
       
    68         
       
    69     CSELOGSTRING_HIGH_LEVEL(
       
    70         "<<<CCseSchedulerUniPluginController::CCseSchedulerUniPluginController");
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCseSchedulerUniPluginController::NewL
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CCseSchedulerUniPluginController* CCseSchedulerUniPluginController::NewL(
       
    79                                         CCseSchedulerServerEngine& aEngine,
       
    80                                         TInt32 aPluginUid )
       
    81     {
       
    82     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::NewL");
       
    83     
       
    84     CCseSchedulerUniPluginController* self =
       
    85             new( ELeave ) CCseSchedulerUniPluginController( aEngine, aPluginUid );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL( );
       
    88     CleanupStack::Pop( self );
       
    89     
       
    90     CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::NewL");
       
    91     return self;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CCseSchedulerUniPluginController::ConstructL
       
    96 // Symbian 2nd phase constructor can leave.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CCseSchedulerUniPluginController::ConstructL()
       
   100     {
       
   101     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::ConstructL");
       
   102     
       
   103     CCseSchedulerPluginControllerBase::ConstructL();
       
   104        
       
   105 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::ConstructL");
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCseSchedulerUniPluginController::~CCseSchedulerUniPluginController
       
   110 // Destructor.
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CCseSchedulerUniPluginController::~CCseSchedulerUniPluginController()
       
   114     {
       
   115     CSELOGSTRING_HIGH_LEVEL(
       
   116         ">>>CCseSchedulerUniPluginController::~CCseSchedulerUniPluginController");
       
   117     delete iLandLord;
       
   118     iLandLord = NULL;
       
   119     CSELOGSTRING_HIGH_LEVEL(
       
   120         "<<<CCseSchedulerUniPluginController::~CCseSchedulerUniPluginController");
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CCseSchedulerUniPluginController::RunPluginsL
       
   125 // 
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CCseSchedulerUniPluginController::RunPluginsL()
       
   129     {
       
   130     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::RunPluginsL");
       
   131 
       
   132     // Is there something to be run?!?
       
   133     if(iScheduleArray.Count() >0 )
       
   134         {
       
   135         // Check if there is security reasons for this schedule why this
       
   136         // schedule shouldn't be run
       
   137         if( iEngine.IsAllowedToRun( iScheduleArray[0]->DbIdentifier() ) )
       
   138             {
       
   139             // Check if LandLord is still working. If he is, we just fall through
       
   140             // because schedule will be kicked when current plugin completes
       
   141             if( iIsLandLordWorking == EFalse )
       
   142                 {                    
       
   143                 // When we come here in UniPluginController it means that there isn't any
       
   144                 // threads running on LandLord side. Scrap the old if it exists and create new one.
       
   145                 if ( iLandLord )
       
   146                     {
       
   147                     delete iLandLord;
       
   148                     iLandLord = NULL;
       
   149                     }
       
   150                 
       
   151                 iLandLord = CCseSchedulerLandLord::NewL( this );
       
   152                 
       
   153                 iLandLord->SetScheduleL( *iScheduleArray[0] );
       
   154                 
       
   155                 iEngine.IncreaseScheduleRunCountL( iScheduleArray[0]->DbIdentifier() );
       
   156                 
       
   157                 iIsLandLordWorking = ETrue;
       
   158                 
       
   159                 iLandLord->RunPluginL();
       
   160                 }
       
   161             }
       
   162         else
       
   163             {
       
   164             // Schedule cannot be run anymore due to security reasons
       
   165             // Signal engine to remove schedule from DB
       
   166             iEngine.ScheduleNotValid( iScheduleArray[0]->DbIdentifier() );
       
   167             
       
   168             // Remove schedule own list
       
   169             delete iScheduleArray[0];
       
   170             iScheduleArray.Remove( 0 );
       
   171             
       
   172             // Call ourselves again.
       
   173             RunPluginsL();
       
   174             }            
       
   175         }
       
   176     else
       
   177         {
       
   178         // No schedules...!?!? REEEEESCHEDULE!!!
       
   179         iEngine.RequestReschedule();
       
   180         }
       
   181 
       
   182     CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::RunPluginsL");
       
   183     }
       
   184     
       
   185 // -----------------------------------------------------------------------------
       
   186 // CCseSchedulerUniPluginController::SetSchedulesL
       
   187 //
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CCseSchedulerUniPluginController::SetSchedulesL(
       
   191                                             RPointerArray<CCseScheduledProgram>& aScheduleArray )
       
   192     {
       
   193 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::SetSchedules");
       
   194 
       
   195     //  The aScheduleArray parameter contains schedules which are either before
       
   196     //  or at the same time as the existing ones in the iScheduleArray.
       
   197     //  Just destroy the old ones and replace with new ones.
       
   198     //  Also cancel the timer because the schedule to run may be different
       
   199 
       
   200     iScheduleArray.ResetAndDestroy();
       
   201     iTimer->Cancel();
       
   202 
       
   203 	// Go through all given schedules and copy them our array
       
   204 	for( TInt i = 0; i < aScheduleArray.Count(); i++)
       
   205 	    {
       
   206         CCseScheduledProgram* schedule =
       
   207                 CCseScheduledProgram::NewL(*aScheduleArray[i] );
       
   208         CleanupStack::PushL( schedule );
       
   209 
       
   210 	    iScheduleArray.AppendL( schedule );
       
   211 
       
   212 	    CleanupStack::Pop( schedule );
       
   213 	    }
       
   214 
       
   215     //  If we have schedules, set the timer
       
   216     if (iScheduleArray.Count() > 0  && !iIsLandLordWorking)
       
   217         {
       
   218         //  All the schedules have same time
       
   219         iTimer->SetTimer( iScheduleArray[0]->StartTime() );
       
   220         }
       
   221 
       
   222 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::SetSchedules");
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CCseSchedulerUniPluginController::ScheduledEventCompleted
       
   227 //
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CCseSchedulerUniPluginController::ScheduleCompletedL( const TUint32 aDbIdentifier,
       
   231                                                            TInt aCompletitionCode )
       
   232 	{	
       
   233 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::ScheduleCompletedL");
       
   234     
       
   235     if ( aCompletitionCode == KErrNone )
       
   236         {
       
   237         ScheduleCompletedSuccesfullyL( aDbIdentifier );
       
   238         }
       
   239     else
       
   240         {        
       
   241         HandleScheduleErrorL( aDbIdentifier, aCompletitionCode );
       
   242         }    
       
   243      
       
   244 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::ScheduleCompletedL");
       
   245 	}
       
   246 	
       
   247 // -----------------------------------------------------------------------------
       
   248 // CCseSchedulerUniPluginController::ScheduleCompletedSuccesfullyL
       
   249 //
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CCseSchedulerUniPluginController::ScheduleCompletedSuccesfullyL( const TUint32 aDbIdentifier )
       
   253 	{
       
   254 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::ScheduleCompletedSuccesfullyL");
       
   255 	
       
   256 	// Remove completed schedule from list
       
   257     for ( TInt i = iScheduleArray.Count(); i > 0; i--)
       
   258         {
       
   259         if( iScheduleArray[i-1]->DbIdentifier() == aDbIdentifier )
       
   260             {
       
   261             delete iScheduleArray[i-1];
       
   262             iScheduleArray.Remove( i-1 );                
       
   263             }
       
   264         }
       
   265 
       
   266     // After all this LandLord has finished everything. He may rest now    
       
   267     iIsLandLordWorking = EFalse;            
       
   268         
       
   269     // Notify engine about completition.
       
   270     iEngine.ScheduleCompletedSuccesfullyL( aDbIdentifier );
       
   271     
       
   272     // If there is still schedule(s), set timer for it
       
   273     if( iScheduleArray.Count() > 0 )
       
   274         {
       
   275         iTimer->SetTimer( iScheduleArray[0]->StartTime() );
       
   276         }    
       
   277     
       
   278 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::ScheduleCompletedSuccesfullyL");	
       
   279 	}
       
   280 	
       
   281 // -----------------------------------------------------------------------------
       
   282 // CCseSchedulerUniPluginController::HandleScheduleErrorL
       
   283 //
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CCseSchedulerUniPluginController::HandleScheduleErrorL( const TUint32 aDbIdentifier,
       
   287                                                             TUint32 aCompletitionCode )
       
   288 	{	
       
   289 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::HandleScheduleErrorL");
       
   290 	
       
   291     // Remove completed schedule from list
       
   292     for ( TInt i = iScheduleArray.Count(); i > 0; i--)
       
   293         {
       
   294         if( iScheduleArray[i-1]->DbIdentifier() == aDbIdentifier )
       
   295             {
       
   296             delete iScheduleArray[i-1];
       
   297             iScheduleArray.Remove( i-1 );                
       
   298             }
       
   299         }
       
   300 
       
   301     // After all this LandLord has finished everything. He may rest now    
       
   302     iIsLandLordWorking = EFalse;            
       
   303 	
       
   304 	// Here we could try to handle plugin errors. Problem is that scheduler doesn't
       
   305 	// know anything about schedule it is running and so there cannot be tailored
       
   306 	// error handling for each plugin. In the end, we just complete schedule
       
   307 	// to engine with error code (ends up removing schedule from DB).
       
   308 	iEngine.ScheduleCompletedWithErrorL( aDbIdentifier, aCompletitionCode );
       
   309 	
       
   310 	// If there is still schedule(s), set timer for it
       
   311     if( iScheduleArray.Count() > 0 )
       
   312         {
       
   313         iTimer->SetTimer( iScheduleArray[0]->StartTime() );
       
   314         }
       
   315 
       
   316 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::HandleScheduleErrorL");
       
   317 	}
       
   318 	
       
   319 // -----------------------------------------------------------------------------
       
   320 // CCseSchedulerUniPluginController::TimerErrorL
       
   321 //
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CCseSchedulerUniPluginController::TimerErrorL( const TInt32 aError )
       
   325 	{	
       
   326 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::TimerErrorL");
       
   327 	
       
   328 	if ( aError == KErrAbort )
       
   329 		{
       
   330 		 // System time changed. Make sanity check and start timer again.
       
   331 		CSELOGSTRING_HIGH_LEVEL(
       
   332 		    ">>>CCseSchedulerUniPluginController::TimerErrorL, system time has changed");
       
   333 		if ( iScheduleArray.Count() > 0 )
       
   334 			{
       
   335 			TTime now;
       
   336 			now.UniversalTime();
       
   337 			// Time still in the future
       
   338 			if ( now < iScheduleArray[0]->StartTime() )
       
   339 				{
       
   340 				iTimer->SetTimer( iScheduleArray[0]->StartTime() );
       
   341 				}
       
   342 			else
       
   343 				{
       
   344 				// If schedule is in the past let the "normal" route decide when
       
   345 				// it is he's her time to be run
       
   346 				RunPluginsL();
       
   347 				}
       
   348 			}
       
   349 		return; 
       
   350 		}
       
   351 
       
   352 	if ( aError == KErrUnderflow )
       
   353 		{
       
   354 		 // Scheduled time is in the past, pass it to notifier. It should decide what to do
       
   355 		CSELOGSTRING_HIGH_LEVEL(
       
   356 		    ">>>CCseSchedulerServerEngine::TimerErrorL, scheduled time is in the past");
       
   357 		RunPluginsL();
       
   358 		return;
       
   359 		}
       
   360 			
       
   361 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::TimerErrorL");
       
   362 	}
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CCseSchedulerUniPluginController::ClearController
       
   366 //
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CCseSchedulerUniPluginController::ClearControllerL( )
       
   370 	{	
       
   371 	CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::ClearControllerL");	
       
   372 
       
   373     iLandLord->ClearL();
       
   374         
       
   375     iScheduleArray.ResetAndDestroy();
       
   376         
       
   377 	CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::ClearControllerL");
       
   378 	}
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // CCseSchedulerUniPluginController::ClearController
       
   382 //
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 TBool CCseSchedulerUniPluginController::IsControllerActive( )
       
   386     {
       
   387     CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerUniPluginController::IsControllerActive");
       
   388     
       
   389     CSELOGSTRING2_HIGH_LEVEL("<<<CCseSchedulerUniPluginController::IsControllerActive: %d",
       
   390                             iIsLandLordWorking);
       
   391     
       
   392     return iIsLandLordWorking;
       
   393     }
       
   394 
       
   395 // End of file.