javaextensions/satsa/pki/src.s60/caosynchronizer.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "caosynchronizer.h"
       
    20 
       
    21 
       
    22 
       
    23 EXPORT_C CAOSynchronizer* CAOSynchronizer::NewL()
       
    24 {
       
    25     CAOSynchronizer* self = new(ELeave) CAOSynchronizer();
       
    26     CleanupStack::PushL(self);
       
    27     self->ConstructL();
       
    28     CleanupStack::Pop();
       
    29     return self;
       
    30 }
       
    31 
       
    32 CAOSynchronizer::~CAOSynchronizer()
       
    33 {
       
    34     Cancel();
       
    35     delete iTimer;
       
    36     delete iCas;
       
    37     delete iWait;
       
    38 }
       
    39 
       
    40 void CAOSynchronizer::ConstructL()
       
    41 {
       
    42     if (CActiveScheduler::Current() == NULL)
       
    43     {
       
    44         // Need to create our own ActiveScheduler
       
    45         iCas = new(ELeave) CActiveScheduler;
       
    46         CActiveScheduler::Install(iCas);
       
    47     }
       
    48 
       
    49     // Register as an active object
       
    50     CActiveScheduler::Add(this);
       
    51     iWait = new(ELeave) CActiveSchedulerWait();
       
    52 }
       
    53 
       
    54 EXPORT_C void CAOSynchronizer::ExecuteL(TTimeIntervalMicroSeconds32 aTimeout)
       
    55 {
       
    56     delete iTimer;
       
    57     iTimer = NULL;
       
    58     if (aTimeout > (TTimeIntervalMicroSeconds32)0)
       
    59     {
       
    60         iTimer = CTimeOutTimer::NewL(CActive::EPriorityStandard, *this);
       
    61         iTimer->After(aTimeout);
       
    62     }
       
    63 
       
    64     SetActive();
       
    65 
       
    66     if (iCas)
       
    67     {
       
    68         iCas->Start();
       
    69     }
       
    70     else
       
    71     {
       
    72         if (!iWait->IsStarted())
       
    73         {
       
    74             iWait->Start();
       
    75         }
       
    76     }
       
    77 }
       
    78 
       
    79 void CAOSynchronizer::Complete()
       
    80 {
       
    81     if (iTimer)
       
    82     {
       
    83         iTimer->Cancel();
       
    84     }
       
    85 
       
    86     if (iCas)
       
    87     {
       
    88         iCas->Stop();
       
    89     }
       
    90     else
       
    91     {
       
    92         if (iWait->IsStarted())
       
    93         {
       
    94             iWait->AsyncStop();
       
    95         }
       
    96     }
       
    97 }
       
    98 
       
    99 // From CActive
       
   100 void CAOSynchronizer::DoCancel()
       
   101 {
       
   102     Complete();
       
   103 }
       
   104 
       
   105 void CAOSynchronizer::RunL()
       
   106 {
       
   107     Complete();
       
   108 }
       
   109 
       
   110 // From CTimeoutTimer
       
   111 void CAOSynchronizer::TimerExpired()
       
   112 {
       
   113     Complete();
       
   114 }
       
   115 
       
   116