wim/Scard/src/ScardEventStack.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003 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:  A class implementing two stacks. One is a fifo-stack of
       
    15 *               reader events, the other a random-access stack of service
       
    16 *               providers that are not used with a given reader
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include    "ScardBase.h"
       
    24 #include    "ScardEventStack.h"
       
    25 #include    "ScardConnector.h"
       
    26 #include    "WimTrace.h"
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CScardEventStack::CScardEventStack
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CScardEventStack::CScardEventStack()
       
    37     {
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CScardEventStack::ConstructL
       
    42 // Symbian 2nd phase constructor can leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CScardEventStack::ConstructL( CScardConnector* aConnector )
       
    46     {
       
    47     _WIMTRACE(_L("WIM|Scard|CScardEventStack::ConstructL|Begin"));
       
    48     iConnector = aConnector;
       
    49     iEvents = new ( ELeave ) CArrayFixFlat<TQueueEvent>( 1 );
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CScardEventStack::NewL
       
    54 // Two-phased constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CScardEventStack* CScardEventStack::NewL( CScardConnector* aConnector )
       
    58     {
       
    59     _WIMTRACE(_L("WIM|Scard|CScardEventStack::NewL|Begin"));
       
    60     CScardEventStack* self = new( ELeave ) CScardEventStack;
       
    61     
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL( aConnector );
       
    64     CleanupStack::Pop( self );
       
    65 
       
    66     return self;
       
    67     }
       
    68 
       
    69     
       
    70 // Destructor
       
    71 CScardEventStack::~CScardEventStack()
       
    72     {
       
    73     _WIMTRACE(_L("WIM|Scard|CScardEventStack::~CScardEventStack|Begin"));
       
    74     if ( iEvents )
       
    75         {
       
    76         iEvents->Reset();
       
    77         }
       
    78     delete iEvents;    
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CScardEventStack::QueueEvent
       
    83 // Queue event
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CScardEventStack::QueueEvent(
       
    87     const TReaderID aReaderID, 
       
    88     const TScardServiceStatus aEventType )
       
    89     {
       
    90     _WIMTRACE(_L("WIM|Scard|CScardEventStack::QueueEvent|Begin"));
       
    91     //  Remove any old events for this reader to ensure that no out-of-date 
       
    92     //  events are in the stack
       
    93     for ( TInt i( 0 ); i < iEvents->Count(); i++ )
       
    94         {
       
    95         if ( iEvents->At( i ).iReaderID == aReaderID )
       
    96             {
       
    97             iEvents->Delete( i );
       
    98             break;
       
    99             }
       
   100         }
       
   101 
       
   102     //  Add event to the stack
       
   103     TQueueEvent event;
       
   104     event.iEventType = aEventType;
       
   105     event.iReaderID = aReaderID;
       
   106     TRAPD( mem_ok, iEvents->AppendL( event ) );
       
   107     __ASSERT_MEMORY( mem_ok );
       
   108     }
       
   109 
       
   110 //  End of File