0
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2005 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 |
#ifndef _SDK_CARDREADER_H_
|
|
20 |
#define _SDK_CARDREADER_H_
|
|
21 |
|
|
22 |
#include <emulator.h>
|
|
23 |
#include <winscard.h>
|
|
24 |
#include <ScardReader.h>
|
|
25 |
|
|
26 |
/**
|
|
27 |
* Smart card reader.
|
|
28 |
*/
|
|
29 |
class SdkScardLauncher;
|
|
30 |
class CSdkCardReader : public CActive, public MScardReader
|
|
31 |
{
|
|
32 |
private:
|
|
33 |
SdkScardLauncher* iLauncher;
|
|
34 |
SCARD_READERSTATE iReaderState;
|
|
35 |
SCARDHANDLE iCardHandle;
|
|
36 |
TRequestStatus iEventThreadStatus;
|
|
37 |
RSemaphore iRequest;
|
|
38 |
RThread iEventThread;
|
|
39 |
RThread iRequestThread;
|
|
40 |
TPtrC iName;
|
|
41 |
TReaderID iId;
|
|
42 |
TInt iRefCount;
|
|
43 |
TBool iFlags; // See below:
|
|
44 |
enum TFlags {
|
|
45 |
EFlagHaveSemaphore = 0x0001,
|
|
46 |
EFlagRequestThread = 0x0002,
|
|
47 |
EFlagEventThread = 0x0004,
|
|
48 |
EFlagCardIn = 0x0008,
|
|
49 |
EFlagOpen = 0x0010,
|
|
50 |
EFlagHasId = 0x0020,
|
|
51 |
EFlagDead = 0x0040
|
|
52 |
};
|
|
53 |
|
|
54 |
public:
|
|
55 |
static CSdkCardReader* NewL(SdkScardLauncher* aLauncher,
|
|
56 |
const TText* aName);
|
|
57 |
virtual ~CSdkCardReader();
|
|
58 |
|
|
59 |
inline TBool HasId() const;
|
|
60 |
inline void SetId(TReaderID aId);
|
|
61 |
inline TReaderID Id() const;
|
|
62 |
inline TBool MatchId(TReaderID aId) const;
|
|
63 |
inline const TDesC& Name() const;
|
|
64 |
inline void AddRef();
|
|
65 |
TInt ReleaseRef();
|
|
66 |
|
|
67 |
// CActive
|
|
68 |
virtual void DoCancel();
|
|
69 |
virtual void RunL();
|
|
70 |
|
|
71 |
// MScardReader
|
|
72 |
virtual void Open(TRequestStatus& aStatus);
|
|
73 |
virtual TInt Close();
|
|
74 |
virtual void CancelTransmit();
|
|
75 |
virtual TInt GetATR(TScardATR& anATR);
|
|
76 |
virtual TBool GetCapabilities(TRequestStatus& aStatus,
|
|
77 |
const TInt32 aTag,
|
|
78 |
TPtr8& aValue,
|
|
79 |
const TInt32 aTimeout);
|
|
80 |
virtual void TransmitToCard(TRequestStatus& aStatus,
|
|
81 |
const TPtrC8& aCommand,
|
|
82 |
TPtr8& aResponse,
|
|
83 |
const TInt32 aTimeout);
|
|
84 |
|
|
85 |
private:
|
|
86 |
CSdkCardReader(SdkScardLauncher* aLauncher, const TText* aName);
|
|
87 |
void ConstructL();
|
|
88 |
void EventThread();
|
|
89 |
static TInt EventThread(TAny* aParam);
|
|
90 |
void Notify(TScardServiceStatus aEvent);
|
|
91 |
void SubmitEventRequest();
|
|
92 |
};
|
|
93 |
|
|
94 |
inline TBool CSdkCardReader::HasId() const
|
|
95 |
{ return ((iFlags & EFlagHasId) != 0); }
|
|
96 |
inline void CSdkCardReader::SetId(TReaderID aId)
|
|
97 |
{ iId = aId; iFlags |= EFlagHasId; }
|
|
98 |
inline TReaderID CSdkCardReader::Id() const
|
|
99 |
{ ASSERT(HasId()); return iId; }
|
|
100 |
inline TBool CSdkCardReader::MatchId(TReaderID aId) const
|
|
101 |
{ return (iFlags & EFlagHasId) && (iId == aId); }
|
|
102 |
inline const TDesC& CSdkCardReader::Name() const
|
|
103 |
{ return iName; }
|
|
104 |
inline void CSdkCardReader::AddRef()
|
|
105 |
{ iRefCount++; }
|
|
106 |
|
|
107 |
#endif // _SDK_CARDREADER_H_
|