wim/Scard/src/ScardResourceRegistry.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:  Registry of smart card resources
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "ScardResourceRegistry.h"
       
    22 #include    "ScardServer.h"
       
    23 #include    "WimTrace.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CScardResourceRegistry::CScardResourceRegistry
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CScardResourceRegistry::CScardResourceRegistry()
       
    34     : iServer( NULL )
       
    35     {
       
    36     _WIMTRACE(_L("WIM|Scard|CScardResourceRegistry::CScardResourceRegistry|Begin"));
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CScardResourceRegistry::ConstructL
       
    41 // Symbian 2nd phase constructor can leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CScardResourceRegistry::ConstructL( CScardServer* aServer )
       
    45     {
       
    46     _WIMTRACE(_L("WIM|Scard|CScardResourceRegistry::ConstructL|Begin"));
       
    47     iServer = aServer;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CScardResourceRegistry::NewL
       
    52 // Two-phased constructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CScardResourceRegistry* CScardResourceRegistry::NewL( CScardServer* aServer )
       
    56     {
       
    57     _WIMTRACE(_L("WIM|Scard|CScardResourceRegistry::NewL|Begin"));
       
    58     CScardResourceRegistry* self = new( ELeave ) CScardResourceRegistry;
       
    59     
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL( aServer );
       
    62     CleanupStack::Pop( self );
       
    63 
       
    64     return self;
       
    65     }
       
    66 
       
    67     
       
    68 // Destructor
       
    69 CScardResourceRegistry::~CScardResourceRegistry()
       
    70     {
       
    71     _WIMTRACE(_L("WIM|Scard|CScardResourceRegistry::~CScardResourceRegistry|Begin"));
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CScardResourceRegistry::CardEventL
       
    77 // If a card is inserted / removed, we need to update the list of cards in use
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CScardResourceRegistry::CardEvent(
       
    81     const TScardServiceStatus aEvent, 
       
    82     const TReaderID aReaderID )
       
    83     {
       
    84     _WIMTRACE(_L("WIM|Scard|CScardResourceRegistry::CardEventL|Begin"));
       
    85     //  First get the access controller for the reader
       
    86     CScardAccessControl* control = iServer->FindAccessControl( aReaderID );
       
    87 
       
    88     // Due to asynchronity, some readers may have closed before the events 
       
    89     // are processed
       
    90     if ( !control )
       
    91         {
       
    92         return;
       
    93         }
       
    94 
       
    95     //  Then the actual reader
       
    96     MScardReader* reader = control->Reader();
       
    97     __ASSERT_ALWAYS( reader, User::Panic( _L( "Unknown reader" ), 
       
    98         KScServerPanicBadRequest ) );
       
    99 
       
   100     switch ( aEvent )
       
   101         {
       
   102         case EScardRemoved: // Flow through 
       
   103         case EReaderRemoved:
       
   104             {
       
   105             TScardATR atr;
       
   106 
       
   107             //  Inform the sessions attached to the reader
       
   108             control->CardEvent( aEvent, atr );
       
   109 
       
   110             break;
       
   111             }
       
   112         case EScardInserted:
       
   113             {
       
   114             //  A new card was inserted, so get the atr bytes
       
   115             TScardATR atr;
       
   116             TInt err = reader->GetATR( atr );
       
   117             if ( !err )
       
   118                 {
       
   119                 }
       
   120             //  Inform sessions
       
   121             control->CardEvent( aEvent, atr );
       
   122             break;
       
   123             }
       
   124         default:
       
   125             break;
       
   126         }
       
   127     }
       
   128 
       
   129 //  End of File