src/screensaverctrlplugin.cpp
changeset 14 8a173132b0aa
parent 2 058b1fc1663a
equal deleted inserted replaced
2:058b1fc1663a 14:8a173132b0aa
     1 /*
       
     2 * Copyright (c) 2009 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 screensaver plugin display object class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <AknDef.h>
       
    21 #include <power_save_display_mode.h>
       
    22 
       
    23 #include "ScreensaverpluginIntDef.h"
       
    24 #include "screensaverctrlplugin.h"
       
    25 #include "screensaverview.h"
       
    26 #include "screensaverappui.h"
       
    27 #include "screensaverutility.h"
       
    28 #include "ScreensaverUtils.h"
       
    29 #include "screensavershareddatai.h"
       
    30 
       
    31 // If plugin refresh rate is lower than this threshold, wserv heartbeat
       
    32 // is stopped between redraws
       
    33 const TInt KStopWsHbPluginRefreshThreshold = 1000000; // 1 sec
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CScreensaverCtrlPlugin::NewL
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CScreensaverCtrlPlugin* CScreensaverCtrlPlugin::NewL()
       
    40     {
       
    41     CScreensaverCtrlPlugin* self = new( ELeave ) CScreensaverCtrlPlugin();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop();
       
    45     return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CScreensaverCtrlPlugin::~CScreensaverCtrlPlugin
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CScreensaverCtrlPlugin::~CScreensaverCtrlPlugin()
       
    53     {
       
    54     DeleteTimer( iPluginRefreshTimer );
       
    55     DeleteTimer( iPluginTimeoutTimer );
       
    56     DeletePlugin();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CScreensaverCtrlPlugin::StartTimer
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CScreensaverCtrlPlugin::StartTimer()
       
    64     {
       
    65     // Notify plugin that screensaver is starting
       
    66     SendPluginEvent( EScreensaverEventStarting );
       
    67     
       
    68     
       
    69     StartPluginRefreshTimer();
       
    70 
       
    71     if ( RefreshTimerValue() >= KStopWsHbPluginRefreshThreshold )
       
    72         {
       
    73         StartCaptureScreenTimer();
       
    74         }
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CScreensaverCtrlPlugin::CancelTimer
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CScreensaverCtrlPlugin::CancelTimer()
       
    82     {
       
    83     DeleteTimer( iPluginRefreshTimer );
       
    84     DeleteTimer( iPluginTimeoutTimer );
       
    85     
       
    86     SendPluginEvent( EScreensaverEventStopping );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CScreensaverCtrlPlugin::DrawObject
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CScreensaverCtrlPlugin::DrawObject()
       
    94     {
       
    95     CScreensaverBase::DrawObject();
       
    96 
       
    97     if( iPluginFlag.IsSet( EPluginFlagSuspend ) )
       
    98     	{
       
    99     	Suspend( -1 );
       
   100     	iPluginFlag.Clear( EPluginFlagSuspend );
       
   101     	}
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CScreensaverCtrlPlugin::ClearScreen
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CScreensaverCtrlPlugin::ClearScreen()
       
   109     {
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CScreensaverCtrlPlugin::Refresh
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CScreensaverCtrlPlugin::Refresh()
       
   117     {
       
   118     SCRLOGGER_WRITEF( _L("SCR:CScreensaverCtrlPlugin::Refresh start") );
       
   119     // Currently only keylock indicator is updated, because
       
   120     // thats the only indicator whose state may change while screensaver
       
   121     // is displaying. Other indicators' state changing also dismisses
       
   122     // screensaver. Once redisplaying, the indicators are updated anyway.
       
   123     // Key lock indicator depends on status of key guard.
       
   124     Array().SetDependencyStatus( ESsKeyLockInd, !Model().SharedDataInterface()->IsKeyguardOn() );
       
   125     Array().SetVisibilityForIndicators();
       
   126 
       
   127     SCRLOGGER_WRITEF( _L("SCR:CScreensaverCtrlPlugin::Refresh DrawObject") );
       
   128     // Cause a redraw
       
   129     DrawObject();
       
   130 
       
   131     SCRLOGGER_WRITEF( _L("SCR:CScreensaverCtrlPlugin::Refresh finish") );
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CScreensaverCtrlPlugin::SendPluginEvent
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TInt CScreensaverCtrlPlugin::SendPluginEvent( TScreensaverEvent aEvent )
       
   139     {
       
   140     if ( iPlugin )
       
   141         {
       
   142         TRAPD( err, iPlugin->HandleScreensaverEventL( aEvent, NULL ) );
       
   143         return err;
       
   144         }
       
   145 
       
   146     return KErrNone;
       
   147     }
       
   148 
       
   149 // From MScreensaverPluginHost
       
   150 // -----------------------------------------------------------------------------
       
   151 // CScreensaverCtrlPlugin::UseStandardIndicators
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 void CScreensaverCtrlPlugin::UseStandardIndicators()
       
   155     {
       
   156     SCRLOGGER_WRITE("Host: UseStandardIndicators()");
       
   157 
       
   158     iPluginFlag.Clear( EPluginFlagOverrideIndicators );
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CScreensaverCtrlPlugin::OverrideStandardIndicators
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CScreensaverCtrlPlugin::OverrideStandardIndicators()
       
   166     {
       
   167     SCRLOGGER_WRITE("Host: OverrideStandardIndicators()");
       
   168 
       
   169     iPluginFlag.Set( EPluginFlagOverrideIndicators );
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CScreensaverCtrlPlugin::StandardIndicatorsUsed
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 TBool CScreensaverCtrlPlugin::StandardIndicatorsUsed() const
       
   177     {
       
   178     SCRLOGGER_WRITE("Host: StandardIndicatorsUsed()");
       
   179 
       
   180     return iPluginFlag.IsClear( EPluginFlagOverrideIndicators );
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CScreensaverCtrlPlugin::SetRefreshTimerValue
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CScreensaverCtrlPlugin::SetRefreshTimerValue( TInt aValue )
       
   188     {
       
   189     SCRLOGGER_WRITEF( _L("SCR: Host: SetRefreshTimerValue(%d)"), aValue );
       
   190 
       
   191     iPluginRefreshRate = aValue;
       
   192     iPluginFlag.Clear( EPluginFlagTimerNotUsed );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CScreensaverCtrlPlugin::RefreshTimerValue
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 TInt CScreensaverCtrlPlugin::RefreshTimerValue() const
       
   200     {
       
   201     SCRLOGGER_WRITE("Host: RefreshTimerValue()");
       
   202 
       
   203     return iPluginRefreshRate;
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CScreensaverCtrlPlugin::GetIndicatorPayload
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 TInt CScreensaverCtrlPlugin::GetIndicatorPayload( 
       
   211     TScreensaverIndicatorIndex aIndex, TIndicatorPayload& aResult ) const
       
   212     {
       
   213     SCRLOGGER_WRITEF( _L("SCR: Host: GetIndicatorPayload(%d, %x)"),
       
   214         aIndex, &aResult );
       
   215 
       
   216     return Model().IndicatorArray().GetIndicatorPayload( ( TScreensaverIndicatorId ) aIndex, aResult );
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CScreensaverCtrlPlugin::SetActiveDisplayArea
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TInt CScreensaverCtrlPlugin::SetActiveDisplayArea( 
       
   224     TRect& aRect, const TScreensaverPartialMode& aMode )
       
   225     {
       
   226     SCRLOGGER_WRITEF( _L("SCR: Host: SetActiveDisplayArea(<rect>, %d)"), aMode );
       
   227     SCRLOGGER_WRITEF( _L("    -> rect: (%d, %d, %d, %d)"),
       
   228         aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY );
       
   229     // Make sure everything is in display memory
       
   230     ScreensaverUtility::FlushDrawBuffer();
       
   231 
       
   232     // Save the active area
       
   233     TInt err = SetPowerSaveDisplayActiveArea( aRect );
       
   234     if ( err == KErrNone )
       
   235         {
       
   236         // And activate power save display. Full mode = full colors
       
   237 //        err = ActivatePowerSaveDisplay( aMode.iType
       
   238 //            == EPartialModeTypeFull );
       
   239         }
       
   240 
       
   241     return err;
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CScreensaverCtrlPlugin::SetActiveDisplayArea
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 TInt CScreensaverCtrlPlugin::SetActiveDisplayArea( 
       
   249     TInt aStartRow, TInt aEndRow, const TScreensaverPartialMode& aMode )
       
   250     {
       
   251     SCRLOGGER_WRITEF( _L("SCR: Host: SetActiveDisplayArea(%d, %d, %d)"),
       
   252         aStartRow, aEndRow, aMode );
       
   253     
       
   254     TRect psRect( 0, aStartRow, 1, aEndRow);
       
   255     return SetActiveDisplayArea( psRect, aMode );
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CScreensaverCtrlPlugin::ExitPartialMode
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CScreensaverCtrlPlugin::ExitPartialMode()
       
   263     {
       
   264     SCRLOGGER_WRITE("Host: ExitPartialMode()");
       
   265 
       
   266     LcdPartialMode()->Exit();
       
   267     // Make sure the partial area is empty
       
   268     // Make this less idiotic
       
   269     TRect psRect( 0, 0, 0, 0);
       
   270     SetPowerSaveDisplayActiveArea( psRect );
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CScreensaverCtrlPlugin::GetColorModel
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 const TScreensaverColorModel& CScreensaverCtrlPlugin::GetColorModel() const
       
   278     {
       
   279     SCRLOGGER_WRITE("Host / Own use: GetColorModel()");
       
   280 
       
   281     return Model().GetColorModel();
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CScreensaverCtrlPlugin::Suspend
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void CScreensaverCtrlPlugin::Suspend( TInt aTime )
       
   289     {
       
   290     SCRLOGGER_WRITEF( _L("SCR: Host: Suspend(%d)"), aTime );
       
   291 
       
   292     View()->SetDisplayObject( Model().SharedDataInterface()->DefaultScreensaverType() );
       
   293 
       
   294     View()->ShowDisplayObject();
       
   295     
       
   296     if ( aTime >= 0 )
       
   297         {
       
   298         CScreensaverEngine& model = MUTABLE_CAST( CScreensaverEngine&, Model() );
       
   299         
       
   300         model.StartSuspendTimer( aTime );
       
   301         }
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CScreensaverCtrlPlugin::RequestLights
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CScreensaverCtrlPlugin::RequestLights( TInt aSecs )
       
   309     {
       
   310     SCRLOGGER_WRITEF( _L("SCR: Host: RequestLights(%d)"), aSecs );
       
   311 
       
   312     if ( aSecs <= 0 )
       
   313         {
       
   314         // Turn lights off, kill lights timer
       
   315         Model().SharedDataInterface()->SetSSForcedLightsOn( 0 );
       
   316         }
       
   317     else
       
   318         {
       
   319         // Make sure nobody tries to overextend our hospitality
       
   320         TInt secs = (aSecs > KMaxLightsOnTime) ? KMaxLightsOnTime : aSecs;
       
   321 
       
   322         // Turn lights on, start lights timer
       
   323         Model().SharedDataInterface()->SetSSForcedLightsOn( secs );
       
   324         }
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CScreensaverCtrlPlugin::DisplayInfo
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 TInt CScreensaverCtrlPlugin::DisplayInfo( TScreensaverDisplayInfo* aInfo )
       
   332     {
       
   333     SCRLOGGER_WRITEF( _L("SCR: Host: DisplayInfo(%x)"), aInfo );
       
   334 
       
   335     if ( !aInfo )
       
   336         {
       
   337         return KErrArgument;
       
   338         }
       
   339     // Sanity check: the indicated size of the info struct should be
       
   340     // same or less than the actual size (allows for extensibility)
       
   341     if ( aInfo->iSize > sizeof( TScreensaverDisplayInfo ) )
       
   342         {
       
   343         ASSERT( EFalse );
       
   344         return KErrArgument;
       
   345         }
       
   346 
       
   347     // Fill our own perception of the info structure
       
   348     TScreensaverDisplayInfo info;
       
   349 
       
   350     info.iSize = aInfo->iSize;
       
   351 
       
   352     // Currently whole screen
       
   353     info.iRect = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
       
   354     info.iParent = this;
       
   355 
       
   356     // Copy only the size of the caller struct
       
   357     Mem::Copy( aInfo, &info, aInfo->iSize );
       
   358 
       
   359     return KErrNone;
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CScreensaverCtrlPlugin::UseRefreshTimer
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CScreensaverCtrlPlugin::UseRefreshTimer( TBool aOn )
       
   367     {
       
   368     SCRLOGGER_WRITEF( _L("SCR: Host: UseRefreshTimer(%d)"), aOn );
       
   369 
       
   370     if ( aOn )
       
   371         {
       
   372         // Use normal timer, plugin timer allowed
       
   373         iPluginFlag.Clear( EPluginFlagTimerNotUsed );
       
   374         }
       
   375     else
       
   376         {
       
   377         // Plugin does not want Draw() calls, let timer tick the usual way
       
   378         iPluginFlag.Set( EPluginFlagTimerNotUsed );
       
   379         }
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CScreensaverCtrlPlugin::RequestTimeout
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CScreensaverCtrlPlugin::RequestTimeout( TInt aSecs )
       
   387     {
       
   388     StartPluginTimeoutTimer( aSecs );
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CScreensaverCtrlPlugin::RevertToDefaultSaver
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CScreensaverCtrlPlugin::RevertToDefaultSaver()
       
   396     {
       
   397     SCRLOGGER_WRITE("Host: RevertToDefaultSaver()");
       
   398 
       
   399     Model().SharedDataInterface()->SetDisplayObjectType( 
       
   400         Model().SharedDataInterface()->DefaultScreensaverType() );
       
   401     }
       
   402 
       
   403 // --- end MScreensaverPluginHost ---
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CScreensaverCtrlPlugin::CScreensaverCtrlPlugin
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 CScreensaverCtrlPlugin::CScreensaverCtrlPlugin()
       
   410     :iPluginFlag()
       
   411     {
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CScreensaverCtrlPlugin::ConstructL
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CScreensaverCtrlPlugin::ConstructL()
       
   419     {
       
   420     iPluginFlag.ClearAll();
       
   421 
       
   422     
       
   423     CreateWindowL();
       
   424     
       
   425     SetRect( iCoeEnv->ScreenDevice()->SizeInPixels() );
       
   426     ConstructAndConnectLCDL();
       
   427     LoadPluginL( this );
       
   428     ActivateL();
       
   429     
       
   430     // Notify plugin that display control has changed
       
   431     SendPluginEvent( EScreensaverEventDisplayChanged );
       
   432     
       
   433     if( Model().ScreenSaverIsPreviewing() )
       
   434         {
       
   435         SendPluginEvent( EScreensaverEventPreview );
       
   436         }
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CScreensaverCtrlPlugin::HandleResourceChange
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void CScreensaverCtrlPlugin::HandleResourceChange( TInt aType )
       
   444     {
       
   445     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   446         {
       
   447         // Screen layout has changed - resize
       
   448         SetRect( iCoeEnv->ScreenDevice()->SizeInPixels() );
       
   449         // Notify plugin that the display has changed
       
   450         SendPluginEvent( EScreensaverEventDisplayChanged );
       
   451         }
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // CScreensaverCtrlPlugin::SizeChanged
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 void CScreensaverCtrlPlugin::SizeChanged()
       
   459     {
       
   460     }
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CScreensaverCtrlPlugin::Draw
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 void CScreensaverCtrlPlugin::Draw( const TRect& /*aRect*/ ) const
       
   467     {
       
   468     
       
   469     if ( !Model().ScreenSaverIsOn() && !Model().ScreenSaverIsPreviewing() )
       
   470         {
       
   471         return;
       
   472         }
       
   473 
       
   474     // Graphics context to draw on.
       
   475     CWindowGc& gc = SystemGc();
       
   476     
       
   477     // Fix for error ESMG-74Y4PE - S60 3.2 wk26, Power Saver: 
       
   478     // Flickering when power saver is deactivated.
       
   479     // We now clear the screen with a black brush so the screensaver 
       
   480     // background is changed to black. There will no longer be a white
       
   481     // intermediate screen and this will reduce the "flicker" effect.
       
   482     gc.SetBrushColor( KRgbBlack );
       
   483 
       
   484     // Start with a clear screen
       
   485     // If there is no plugin module, indicator view overrides plugin module or
       
   486     // plugin drawing is suspended then the standard screensaver bar is shown,
       
   487     // let's draw it.
       
   488 
       
   489         // Let plugin module handle the drawing, unless not requested
       
   490     
       
   491     TInt err = KErrNone;
       
   492     if ( iPluginFlag.IsClear( EPluginFlagTimerNotUsed ) )
       
   493         {
       
   494         err = iPlugin->Draw( gc );
       
   495         }
       
   496     //Notice:add this code to shield the issue ELWG-7SF3R3.
       
   497     //Prevent screensaver plugin from being called unexpected draw function,
       
   498     //which would cause chosen images are not displayed.
       
   499     //Check the err code return by iPlugin->Draw:
       
   500     //If draw action is correct and iPluginFlag has already been set EPluginFlagSuspend,
       
   501     //then clear this EPluginFlagSuspend
       
   502     if ( KErrNone == err && iPluginFlag.IsSet( EPluginFlagSuspend ) )
       
   503         {
       
   504         iPluginFlag.Clear( EPluginFlagSuspend );
       
   505         }
       
   506 
       
   507     if( err != KErrNone )
       
   508         {
       
   509         iPluginFlag.Set( EPluginFlagSuspend );
       
   510         }
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CScreensaverCtrlPlugin::LoadPluginL
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CScreensaverCtrlPlugin::LoadPluginL(  MScreensaverPluginHost* /*aPluginHost*/ )
       
   518     {
       
   519     DeletePlugin();
       
   520     LoadPluginModuleL();
       
   521     User::LeaveIfNull( iPlugin );
       
   522     }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // CScreensaverCtrlPlugin::LoadPluginModule
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CScreensaverCtrlPlugin::LoadPluginModuleL()
       
   529     {
       
   530     TFileName pluginName;
       
   531         
       
   532     Model().SharedDataInterface()->GetPluginName( pluginName );
       
   533     
       
   534     // Create plugin object in the DLL
       
   535     // Convert the UID of the given screensaver plugin from text to integer
       
   536     // The string format of the UID: [12345678]
       
   537     // The number inside the brackets in hexadecimal format
       
   538     TLex lex( pluginName );
       
   539     
       
   540     // Skip the first character: '['
       
   541     lex.Get();
       
   542     
       
   543     TUint screenSaverPluginImpUid;
       
   544     
       
   545     // Get the UID
       
   546     TInt err = lex.Val( screenSaverPluginImpUid, EHex );
       
   547     
       
   548     // Bail out, if the UID is not parseable
       
   549     if ( err != KErrNone )
       
   550         {
       
   551         iPlugin = NULL;
       
   552         }
       
   553     //codescanner will crib if leaving function inside trap is called
       
   554     //after line break within the macro. Hence the following trap call
       
   555     //is made in a single line
       
   556     TRAP(err, iPlugin = STATIC_CAST( MScreensaverPlugin*, 
       
   557         CScreensaverPluginInterfaceDefinition::NewL( 
       
   558             TUid::Uid( screenSaverPluginImpUid ) ) ) );
       
   559     
       
   560     if( err != KErrNone )
       
   561         return;
       
   562     
       
   563     TRAP( err, err = iPlugin->InitializeL( this ) );
       
   564     
       
   565     if( err != KErrNone )
       
   566         {
       
   567         // Loaded OK, but failed to initialize - cannot use plugin
       
   568         delete iPlugin;
       
   569         iPlugin = NULL;
       
   570         }
       
   571     
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CScreensaverCtrlPlugin::DeletePlugin
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 void CScreensaverCtrlPlugin::DeletePlugin()
       
   579     {
       
   580     if( iPlugin )
       
   581         {
       
   582         delete iPlugin;
       
   583         iPlugin = NULL;
       
   584         }
       
   585     }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CScreensaverCtrlPlugin::StartPluginRefreshTimer
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 void CScreensaverCtrlPlugin::StartPluginRefreshTimer()
       
   592     {
       
   593     DeleteTimer( iPluginRefreshTimer );
       
   594 
       
   595     if( ( iPluginRefreshRate != 0 ) )
       
   596         {
       
   597         TRAP_IGNORE( iPluginRefreshTimer = CPeriodic::NewL( CActive::EPriorityStandard ) );
       
   598         
       
   599         iPluginRefreshTimer->Start( iPluginRefreshRate, iPluginRefreshRate,
       
   600             TCallBack( HandleRefreshTimerExpiry, this ) );
       
   601         SCRLOGGER_WRITEF( _L("SCR: iRefreshTimer->Start(%d, %d, HandleRefreshTimerExpiry)"),
       
   602             iPluginRefreshRate,iPluginRefreshRate );
       
   603         }
       
   604     }
       
   605 
       
   606 // -----------------------------------------------------------------------------
       
   607 // CScreensaverCtrlPlugin::StartPluginTimeoutTimer
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 void CScreensaverCtrlPlugin::StartPluginTimeoutTimer( TInt aSecs )
       
   611     {
       
   612     // Cancel pending timeouts
       
   613     DeleteTimer( iPluginTimeoutTimer );
       
   614 
       
   615     TRAP_IGNORE( iPluginTimeoutTimer = CPeriodic::NewL( CActive::EPriorityStandard ) );
       
   616     
       
   617     // Nothing more to do?
       
   618     if( ( aSecs <= 0 ) || ( aSecs > ( 35 * 60 ) ) ) // 35 mins max
       
   619         {
       
   620         return;
       
   621         }
       
   622 
       
   623     TInt timeOut = aSecs * 1000000; // uSecs
       
   624 
       
   625     iPluginTimeoutTimer->Start( timeOut, timeOut, TCallBack(
       
   626         HandlePluginTimeoutTimerExpiry, this ) );
       
   627     SCRLOGGER_WRITEF( _L("SCR: iPluginTimeoutTimer->Start(%d, %d, HandlePluginTimeoutTimerTimeout)"),
       
   628         timeOut, timeOut );
       
   629     }
       
   630 
       
   631 // -----------------------------------------------------------------------------
       
   632 // CScreensaverCtrlPlugin::HandlePluginTimeoutTimerExpiry
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 TInt CScreensaverCtrlPlugin::HandlePluginTimeoutTimerExpiry( TAny* aPtr )
       
   636     {
       
   637     CScreensaverCtrlPlugin *plugin= STATIC_CAST( CScreensaverCtrlPlugin*, aPtr );
       
   638     SCRLOGGER_WRITEF( _L("SCR: Inside CScreensaverView::HandlePluginTimeoutTimerTimeout()") );
       
   639     if ( plugin )
       
   640         {
       
   641         plugin->DeleteTimer( plugin->iPluginRefreshTimer );
       
   642         plugin->DeleteTimer( plugin->iPluginTimeoutTimer );
       
   643         plugin->SendPluginEvent( EScreensaverEventTimeout );
       
   644         }
       
   645 
       
   646     return KErrNone;
       
   647     }
       
   648 //End of file