ManagerInterface.h

Go to the documentation of this file.
00001 
00008 // Revision $Revision: 134 $
00009 #pragma once
00010 
00011 typedef unsigned int uint;
00012 typedef unsigned char byte;
00013 typedef unsigned short word;
00014 typedef unsigned long dword;
00015 typedef unsigned short ushort;
00017 typedef std::vector<byte> ByteVec;
00018 
00019 struct ConnectionBase;
00020 
00022 
00025 class ManagerInterface
00026 {
00027 private: //disable object copying
00028         ManagerInterface(const ManagerInterface &);
00029         ManagerInterface& operator=(const ManagerInterface &);
00030 
00031 public:
00032         ManagerInterface(void): mLogger(NULL) {}
00033         virtual ~ManagerInterface(void) {}
00035         virtual uint getReaderCount() = 0;
00037         virtual std::string getReaderName(uint index)  = 0;
00039         virtual std::string getReaderState(uint index) = 0;
00041         virtual std::string getATRHex(uint index) = 0;
00043         virtual ConnectionBase * connect(uint index,bool forceT0=false) = 0;
00045         virtual ConnectionBase * reconnect(ConnectionBase *c,bool forceT0=false) {return c;}
00047         inline void setLogging(std::ostream *logStream) {mLogger = logStream;}
00048 protected:
00049         std::ostream  *mLogger;
00050         friend struct ConnectionBase;
00051         friend struct Transaction;
00052         friend class  CardBase;
00053         friend class SmartCardManager;
00054         friend struct SmartCardConnection;
00055         virtual void makeConnection(ConnectionBase *c,uint idx) = 0;
00056         virtual void deleteConnection(ConnectionBase *c) = 0;
00057         virtual void beginTransaction(ConnectionBase *c) = 0;
00058         virtual void endTransaction(ConnectionBase *c,bool forceReset = false) = 0;
00059 
00060         virtual void execCommand(ConnectionBase *c,std::vector<byte> &cmd,std::vector<byte> &recv,
00061                 unsigned int &recvLen) = 0;
00062         virtual void execPinEntryCommand(ConnectionBase *c,std::vector<byte> &cmd) {
00063                 throw std::runtime_error("This manager does not support PIN entry commands");
00064                 }
00065         virtual void execPinChangeCommand(ConnectionBase *c,std::vector<byte> &cmd
00066                 ,size_t oldPinLen,size_t newPinLen) { 
00067                 throw std::runtime_error("This manager does not support PIN change commands");
00068                 }
00070         virtual bool isT1Protocol(ConnectionBase *c) = 0;
00071 };
00072 
00074 
00077 struct ConnectionBase {
00079         ManagerInterface &mManager;
00081         uint mIndex;
00083         bool mForceT0;
00085         bool mOwnConnection;
00086 
00088         virtual bool isSecure() {return false;}
00089         ConnectionBase(ManagerInterface &manager) : 
00090                 mManager(manager),mIndex(-1),mForceT0(false),mOwnConnection(false) {}
00091         ConnectionBase(ManagerInterface &manager,unsigned int index,bool f) 
00092                 : mManager(manager),mIndex(index),mForceT0(f),mOwnConnection(true) {
00093                 mManager.makeConnection(this,index);
00094                 }
00095         virtual ~ConnectionBase() {
00096                 if (mOwnConnection)
00097                         mManager.deleteConnection(this);
00098                 }
00099 };
00100 
00102 
00105 struct Transaction {
00106         ManagerInterface& mManager;
00107         ConnectionBase *mConnection;
00108         Transaction(ManagerInterface& manager,ConnectionBase *connection): mManager(manager),mConnection(connection) {
00109                 mManager.beginTransaction(mConnection);
00110                 }
00111         ~Transaction() {
00112                 mManager.endTransaction(mConnection);
00113                 }
00114         };

Generated on Fri Oct 31 12:29:36 2008 for Cardlib reference by  doxygen 1.5.1