uiacceltk/hitchcock/plugins/alfcrpplugin/src/alfsynchronizer.cpp
branchRCL_3
changeset 3 d8a3531bc6b8
equal deleted inserted replaced
0:15bf7259bb7c 3:d8a3531bc6b8
       
     1 /*
       
     2 * Copyright (c) 2010 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:  AlfSynchronizer waits for synchronization to complete
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alfsynchronizer.h"
       
    20 #include "alfrenderstageutils.h"
       
    21 
       
    22 // Timeout in microseconds - 500 ms.
       
    23 const TInt KAlfSyncTimeout = 500000;
       
    24 
       
    25 // --------------------------------------------------------------------------
       
    26 // CAlfSynchronizer::NewL
       
    27 // --------------------------------------------------------------------------
       
    28 //    
       
    29 CAlfSynchronizer* CAlfSynchronizer::NewL()
       
    30     {
       
    31     CAlfSynchronizer* self = new (ELeave) CAlfSynchronizer;
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37     
       
    38 // --------------------------------------------------------------------------
       
    39 // CAlfSynchronizer::~CAlfSynchronizer
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 CAlfSynchronizer::~CAlfSynchronizer()
       
    43     {
       
    44     Cancel();
       
    45     
       
    46     iProperty.Close();
       
    47     
       
    48     delete iWait;
       
    49     delete iTimeout;
       
    50     }
       
    51 
       
    52 // --------------------------------------------------------------------------
       
    53 // CAlfSynchronizer::Start
       
    54 // --------------------------------------------------------------------------
       
    55 //
       
    56 void CAlfSynchronizer::Start(TInt aId)
       
    57     {
       
    58     iProperty.Subscribe( iStatus );
       
    59     SetActive();
       
    60     
       
    61     TInt value = 0;
       
    62     iProperty.Get(value);
       
    63     
       
    64     if ( value != aId )
       
    65         {
       
    66         // Launch timeout AO in case there happens to be deadlock in coretoolkit etc.
       
    67         iTimeout->Start( KAlfSyncTimeout, KAlfSyncTimeout, 
       
    68             TCallBack( CallbackSyncTimeout, this ) );
       
    69 
       
    70         // Start wait
       
    71         iSynchId = aId;
       
    72         iWait->Start();
       
    73         }
       
    74     }
       
    75     
       
    76 // --------------------------------------------------------------------------
       
    77 // CAlfSynchronizer::RunL
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 void CAlfSynchronizer::RunL()
       
    81     {
       
    82     if ( !iAsyncStopDone && iStatus.Int() == KErrNone )
       
    83         {
       
    84         iProperty.Subscribe( iStatus );
       
    85         SetActive();
       
    86         }
       
    87     
       
    88     TInt value = 0;
       
    89     iProperty.Get(value);
       
    90         
       
    91     if ( !iAsyncStopDone && value == iSynchId )
       
    92         {
       
    93         iWait->AsyncStop();
       
    94         iAsyncStopDone = ETrue;
       
    95         }
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CAlfSynchronizer::CallbackSyncTimeout
       
   100 // --------------------------------------------------------------------------
       
   101 //
       
   102 TInt CAlfSynchronizer::CallbackSyncTimeout( TAny* aPtr )
       
   103     {
       
   104     ((CAlfSynchronizer*)aPtr)->DoCallbackSyncTimeout();
       
   105     return KErrNone;
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CAlfSynchronizer::DoCallbackSyncTimeout
       
   110 // --------------------------------------------------------------------------
       
   111 //
       
   112 void CAlfSynchronizer::DoCallbackSyncTimeout()
       
   113     {        
       
   114     iTimeout->Cancel();
       
   115     
       
   116     if (!iAsyncStopDone)
       
   117         {
       
   118         iWait->AsyncStop();
       
   119         iAsyncStopDone = ETrue;
       
   120         }
       
   121     }
       
   122 
       
   123 // --------------------------------------------------------------------------
       
   124 // CAlfSynchronizer::DoCancel
       
   125 // --------------------------------------------------------------------------
       
   126 //
       
   127 void CAlfSynchronizer::DoCancel()
       
   128     {
       
   129     iProperty.Cancel();
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // CAlfSynchronizer::CAlfSynchronizer
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 CAlfSynchronizer::CAlfSynchronizer()
       
   137     : CActive( EPriorityHigh )
       
   138     {
       
   139     CActiveScheduler::Add(this);
       
   140     }
       
   141 
       
   142 // --------------------------------------------------------------------------
       
   143 // CAlfSynchronizer::ConstructL
       
   144 // --------------------------------------------------------------------------
       
   145 //
       
   146 void CAlfSynchronizer::ConstructL()
       
   147     {
       
   148     User::LeaveIfError( iProperty.Attach( KAlfPSUidSynchronizer, KAlfPSKeySynchronizer ) );
       
   149 
       
   150     iWait = new (ELeave) CActiveSchedulerWait;
       
   151     
       
   152     iTimeout = CPeriodic::NewL( CActive::EPriorityHigh );
       
   153     }