startupservices/startupanimation/sanimengine/src/sanimengineimpl.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 /*
       
     2 * Copyright (c) 2007 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 CSAnimEngineImpl class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sanimimageplugin.h"
       
    20 #include "sanimtoneplugin.h"
       
    21 
       
    22 #include "sanimengineimpl.h"
       
    23 #include "sanimpluginctrl.h"
       
    24 #include "trace.h"
       
    25 
       
    26 /** IF UID for Startup Image Plug-in API. */
       
    27 const TUint32 KImagePlugInApiUid = 0x2000B118;
       
    28 
       
    29 /** IF UID for Startup Tone Plug-in API. */
       
    30 const TUint32 KTonePlugInApiUid = 0x2000B119;
       
    31 
       
    32 // ======== LOCAL FUNCTIONS ========
       
    33 
       
    34 static TInt PluginCallBack( TAny* aPtr )
       
    35     {
       
    36     static_cast<CSAnimEngineImpl*>( aPtr )->PluginFinished();
       
    37     return KErrNone;
       
    38     }
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CSAnimEngineImpl::CSAnimEngineImpl
       
    45 //
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CSAnimEngineImpl::CSAnimEngineImpl( RFs& aFs, MSAnimObserver& aObserver )
       
    49   : iFs( aFs ),
       
    50     iObserver( aObserver )
       
    51     {
       
    52     FUNC_LOG;
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CSAnimEngineImpl::~CSAnimEngineImpl
       
    58 //
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CSAnimEngineImpl::~CSAnimEngineImpl()
       
    62     {
       
    63     FUNC_LOG;
       
    64 
       
    65     Cancel();
       
    66 
       
    67     delete iTonePluginCtrl;
       
    68     delete iImagePluginCtrl;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CSAnimEngineImpl::PluginFinished
       
    74 //
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CSAnimEngineImpl::PluginFinished()
       
    78     {
       
    79     FUNC_LOG;
       
    80 
       
    81     if ( iImagePluginCtrl && iTonePluginCtrl )
       
    82         {
       
    83         TInt imgSuccessCode = iImagePluginCtrl->SuccessCode();
       
    84         TInt toneSuccessCode = iTonePluginCtrl->SuccessCode();
       
    85         if ( imgSuccessCode != KRequestPending &&
       
    86              toneSuccessCode != KRequestPending )
       
    87             {
       
    88             if ( imgSuccessCode != KErrNone )
       
    89                 {
       
    90                 CompleteClientRequest( imgSuccessCode );
       
    91                 }
       
    92             else
       
    93                 {
       
    94                 CompleteClientRequest( toneSuccessCode );
       
    95                 }
       
    96             }
       
    97         // else wait until next call
       
    98         }
       
    99     else if ( iImagePluginCtrl )
       
   100         {
       
   101         CompleteClientRequest( iImagePluginCtrl->SuccessCode() );
       
   102         }
       
   103     else if ( iTonePluginCtrl )
       
   104         {
       
   105         CompleteClientRequest( iTonePluginCtrl->SuccessCode() );
       
   106         }
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CSAnimEngineImpl::SetImageProperties
       
   112 //
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TInt CSAnimEngineImpl::SetImageProperties(
       
   116     const TDesC& aImageFileName,
       
   117     const TDisplayMode aDisplayMode,
       
   118     const TSize& aSize,
       
   119     const TTimeIntervalMicroSeconds32& aFrameDelay,
       
   120     const TBool aScalingEnabled,
       
   121     const TInt aRepeatCount )
       
   122     {
       
   123     FUNC_LOG;
       
   124 
       
   125     TInt errorCode = KErrNotReady;
       
   126     if ( ( !iImagePluginCtrl || !( iImagePluginCtrl->IsActive() ) ) &&
       
   127          ( !iTonePluginCtrl || !( iTonePluginCtrl->IsActive() ) ) )
       
   128         {
       
   129         delete iImagePluginCtrl;
       
   130         iImagePluginCtrl = NULL;
       
   131 
       
   132         errorCode = KErrNone;
       
   133         if ( aImageFileName.Length() > 0 )
       
   134             {
       
   135             TRAP( errorCode, iImagePluginCtrl = CSAnimPluginCtrl::NewL(
       
   136                 aImageFileName, KImagePlugInApiUid, &iObserver ) );
       
   137             ERROR_1( errorCode, "Failed to create image plug-in for file '%S'", &aImageFileName );
       
   138             }
       
   139 
       
   140         if ( iImagePluginCtrl )
       
   141             {
       
   142             CSAnimImagePlugin& plugin =
       
   143                 static_cast<CSAnimImagePlugin&>( iImagePluginCtrl->Plugin() );
       
   144             plugin.SetDisplayMode( aDisplayMode );
       
   145             plugin.SetSize( aSize );
       
   146             plugin.SetFrameDelay( aFrameDelay );
       
   147             plugin.SetScalingEnabled( aScalingEnabled );
       
   148             plugin.SetRepeatCount( aRepeatCount );
       
   149             }
       
   150         }
       
   151 
       
   152     return errorCode;
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CSAnimEngineImpl::SetToneProperties
       
   158 //
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 TInt CSAnimEngineImpl::SetToneProperties(
       
   162     const TDesC& aToneFileName,
       
   163     const TInt aVolume,
       
   164     const TTimeIntervalMicroSeconds& aVolumeRamp,
       
   165     const TInt aRepeatCount )
       
   166     {
       
   167     FUNC_LOG;
       
   168 
       
   169     TInt errorCode = KErrNotReady;
       
   170     if ( ( !iImagePluginCtrl || !( iImagePluginCtrl->IsActive() ) ) &&
       
   171          ( !iTonePluginCtrl || !( iTonePluginCtrl->IsActive() ) ) )
       
   172         {
       
   173         delete iTonePluginCtrl;
       
   174         iTonePluginCtrl = NULL;
       
   175 
       
   176         errorCode = KErrNone;
       
   177         if ( aToneFileName.Length() > 0 )
       
   178             {
       
   179             TRAP( errorCode, iTonePluginCtrl =
       
   180                 CSAnimPluginCtrl::NewL( aToneFileName, KTonePlugInApiUid, NULL ) );
       
   181             ERROR_1( errorCode, "Failed to create tone plug-in for file '%S'", &aToneFileName );
       
   182             }
       
   183 
       
   184         if ( iTonePluginCtrl )
       
   185             {
       
   186             CSAnimTonePlugin& plugin =
       
   187                 static_cast<CSAnimTonePlugin&>( iTonePluginCtrl->Plugin() );
       
   188             plugin.SetVolume( aVolume );
       
   189             plugin.SetVolumeRamp( aVolumeRamp );
       
   190             plugin.SetRepeatCount( aRepeatCount );
       
   191             }
       
   192         }
       
   193 
       
   194     return errorCode;
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CSAnimEngineImpl::Load
       
   200 //
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CSAnimEngineImpl::Load( TRequestStatus& aStatus )
       
   204     {
       
   205     FUNC_LOG;
       
   206 
       
   207     if ( ( iImagePluginCtrl && iImagePluginCtrl->IsActive() ) ||
       
   208          ( iTonePluginCtrl && iTonePluginCtrl->IsActive() ) )
       
   209         {
       
   210         TRequestStatus* status = &aStatus;
       
   211         User::RequestComplete( status, KErrNotReady );
       
   212         }
       
   213     else if ( !iImagePluginCtrl && !iTonePluginCtrl )
       
   214         {
       
   215         TRequestStatus* status = &aStatus;
       
   216         User::RequestComplete( status, KErrNone );
       
   217         }
       
   218     else
       
   219         {
       
   220         SetClientRequest( aStatus );
       
   221 
       
   222         if ( iImagePluginCtrl )
       
   223             {
       
   224             iImagePluginCtrl->Load( iFs, TCallBack( PluginCallBack, this ) );
       
   225             }
       
   226         if ( iTonePluginCtrl )
       
   227             {
       
   228             iTonePluginCtrl->Load( iFs, TCallBack( PluginCallBack, this ) );
       
   229             }
       
   230 
       
   231         SetRequestPending(); // Only do it here, just before returning
       
   232         }
       
   233     }
       
   234 
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CSAnimEngineImpl::BackroundColour
       
   238 //
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 TRgb CSAnimEngineImpl::BackroundColour() const
       
   242     {
       
   243     FUNC_LOG;
       
   244 
       
   245     if ( iImagePluginCtrl )
       
   246         {
       
   247         return ( static_cast<CSAnimImagePlugin&>(
       
   248             iImagePluginCtrl->Plugin() ) ).BackroundColour();
       
   249         }
       
   250 
       
   251     return TRgb();
       
   252     }
       
   253 
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CSAnimEngineImpl::Start
       
   257 //
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 void CSAnimEngineImpl::Start( TRequestStatus& aStatus )
       
   261     {
       
   262     FUNC_LOG;
       
   263 
       
   264     if ( ( iImagePluginCtrl && iImagePluginCtrl->IsActive() ) ||
       
   265          ( iTonePluginCtrl && iTonePluginCtrl->IsActive() ) )
       
   266         {
       
   267         TRequestStatus* status = &aStatus;
       
   268         User::RequestComplete( status, KErrNotReady );
       
   269         }
       
   270     else if ( !iImagePluginCtrl && !iTonePluginCtrl )
       
   271         {
       
   272         TRequestStatus* status = &aStatus;
       
   273         User::RequestComplete( status, KErrNone );
       
   274         }
       
   275     else
       
   276         {
       
   277         User::ResetInactivityTime();
       
   278         SetClientRequest( aStatus );
       
   279 
       
   280         if ( iImagePluginCtrl )
       
   281             {
       
   282             iImagePluginCtrl->Start( TCallBack( PluginCallBack, this ) );
       
   283             }
       
   284         if ( iTonePluginCtrl )
       
   285             {
       
   286             iTonePluginCtrl->Start( TCallBack( PluginCallBack, this ) );
       
   287             }
       
   288 
       
   289         SetRequestPending(); // Only do it here, just before returning
       
   290         }
       
   291     }
       
   292 
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CSAnimEngineImpl::Cancel
       
   296 //
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CSAnimEngineImpl::Cancel()
       
   300     {
       
   301     FUNC_LOG;
       
   302 
       
   303     if ( iImagePluginCtrl )
       
   304         {
       
   305         iImagePluginCtrl->Cancel();
       
   306         }
       
   307     if ( iTonePluginCtrl )
       
   308         {
       
   309         iTonePluginCtrl->Cancel();
       
   310         }
       
   311     }
       
   312 
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CSAnimEngineImpl::SetClientRequest
       
   316 //
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 void CSAnimEngineImpl::SetClientRequest( TRequestStatus& aStatus )
       
   320     {
       
   321     FUNC_LOG;
       
   322 
       
   323     __ASSERT_ALWAYS( !iClientStatus, User::Invariant() );
       
   324 
       
   325     iClientStatus = &aStatus;
       
   326     }
       
   327 
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // CSAnimEngineImpl::SetRequestPending
       
   331 //
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CSAnimEngineImpl::SetRequestPending()
       
   335     {
       
   336     FUNC_LOG;
       
   337 
       
   338     if ( iClientStatus ) // It may already have been completed.
       
   339         {
       
   340         *iClientStatus = KRequestPending;
       
   341         }
       
   342     }
       
   343 
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // CSAnimEngineImpl::CompleteClientRequest
       
   347 //
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CSAnimEngineImpl::CompleteClientRequest( const TInt aStatusCode )
       
   351     {
       
   352     FUNC_LOG;
       
   353 
       
   354     if ( iClientStatus )
       
   355         {
       
   356         User::RequestComplete( iClientStatus, aStatusCode );
       
   357         iClientStatus = NULL;
       
   358         }
       
   359     }