sdkcreationmw/sdkruntimes/scard/src/SdkCardReader.h
author rajpuroh
Mon, 08 Mar 2010 12:09:11 +0530
changeset 0 b26acd06ea60
permissions -rw-r--r--
First Contribution of SDK components
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     1
/*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     2
* Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     3
* All rights reserved.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     4
* This component and the accompanying materials are made available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     6
* which accompanies this distribution, and is available
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     8
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
     9
* Initial Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    11
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    12
* Contributors:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    13
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    14
* Description: 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    15
*
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    16
*/
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    17
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    18
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    19
#ifndef _SDK_CARDREADER_H_
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    20
#define _SDK_CARDREADER_H_
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    21
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    22
#include <emulator.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    23
#include <winscard.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    24
#include <ScardReader.h>
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    25
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    26
/**
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    27
 * Smart card reader. 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    28
 */
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    29
class SdkScardLauncher;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    30
class CSdkCardReader : public CActive, public MScardReader
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    31
{
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    32
private:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    33
    SdkScardLauncher* iLauncher;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    34
    SCARD_READERSTATE iReaderState;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    35
    SCARDHANDLE iCardHandle;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    36
    TRequestStatus iEventThreadStatus;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    37
    RSemaphore iRequest;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    38
    RThread iEventThread;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    39
    RThread iRequestThread;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    40
    TPtrC iName;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    41
    TReaderID iId;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    42
    TInt iRefCount;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    43
    TBool iFlags; // See below:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    44
    enum TFlags {
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    45
        EFlagHaveSemaphore  = 0x0001,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    46
        EFlagRequestThread  = 0x0002,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    47
        EFlagEventThread    = 0x0004,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    48
        EFlagCardIn         = 0x0008,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    49
        EFlagOpen           = 0x0010,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    50
        EFlagHasId          = 0x0020,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    51
        EFlagDead           = 0x0040
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    52
    };
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    53
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    54
public: 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    55
    static CSdkCardReader* NewL(SdkScardLauncher* aLauncher,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    56
                                const TText* aName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    57
    virtual ~CSdkCardReader();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    58
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    59
    inline TBool HasId() const;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    60
    inline void SetId(TReaderID aId);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    61
    inline TReaderID Id() const;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    62
    inline TBool MatchId(TReaderID aId) const;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    63
    inline const TDesC& Name() const;
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    64
    inline void AddRef();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    65
    TInt ReleaseRef();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    66
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    67
    // CActive
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    68
    virtual void DoCancel();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    69
    virtual void RunL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    70
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    71
    // MScardReader
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    72
    virtual void Open(TRequestStatus& aStatus); 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    73
    virtual TInt Close();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    74
    virtual void CancelTransmit();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    75
    virtual TInt GetATR(TScardATR& anATR);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    76
    virtual TBool GetCapabilities(TRequestStatus& aStatus, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    77
                                  const TInt32 aTag,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    78
                                  TPtr8& aValue,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    79
                                  const TInt32 aTimeout);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    80
    virtual void TransmitToCard(TRequestStatus& aStatus, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    81
                                const TPtrC8& aCommand, 
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    82
                                TPtr8& aResponse,
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    83
                                const TInt32 aTimeout);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    84
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    85
private:
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    86
    CSdkCardReader(SdkScardLauncher* aLauncher, const TText* aName);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    87
    void ConstructL();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    88
    void EventThread();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    89
    static TInt EventThread(TAny* aParam);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    90
    void Notify(TScardServiceStatus aEvent);
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    91
    void SubmitEventRequest();
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    92
};
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    93
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    94
inline TBool CSdkCardReader::HasId() const
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    95
    { return ((iFlags & EFlagHasId) != 0); }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    96
inline void CSdkCardReader::SetId(TReaderID aId)
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    97
    { iId = aId; iFlags |= EFlagHasId; }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    98
inline TReaderID CSdkCardReader::Id() const
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
    99
    { ASSERT(HasId()); return iId; }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   100
inline TBool CSdkCardReader::MatchId(TReaderID aId) const
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   101
    { return (iFlags & EFlagHasId) && (iId == aId); }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   102
inline const TDesC& CSdkCardReader::Name() const
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   103
    { return iName; }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   104
inline void CSdkCardReader::AddRef()
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   105
    { iRefCount++; }
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   106
    
b26acd06ea60 First Contribution of SDK components
rajpuroh
parents:
diff changeset
   107
#endif // _SDK_CARDREADER_H_