00001 /*************************************************************************** 00002 $RCSfile: ctcardbase.h,v $ 00003 ------------------- 00004 cvs : $Id: ctcardbase.h,v 1.1 2003/04/24 01:49:28 aquamaniac Exp $ 00005 begin : Wed Apr 23 2003 00006 copyright : (C) 2003 by Martin Preuss 00007 email : martin@libchipcard.de 00008 00009 *************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00024 * MA 02111-1307 USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 00029 #ifndef CTCARDBASE_H 00030 #define CTCARDBASE_H 00031 00032 #include <chipcard/ctpointer.h> 00033 #include <chipcard/ctreadercontext.h> 00034 #include <chipcard/ctreadertrader.h> 00035 00036 #include <string> 00037 using namespace std; 00038 00039 00043 class CTCardBase { 00044 public: 00045 typedef enum { 00046 CallBackContinue=0, 00047 CallBackAbort 00048 } CallBackResult; 00049 00050 protected: 00051 00052 private: 00053 int _openCount; 00054 int _timeout; 00055 CTReaderContext _reader; 00056 string _atr; 00057 00058 int _responseLoop(int reqid, int maxloop); 00059 CTError _abortConnect(int prevreq, int timeout); 00060 00061 CTError allocate(); 00062 CTError release(); 00063 CTError connect(string &atr); 00064 CTError disconnect(); 00065 CTError command(const string &apdu, string &response); 00066 00067 public: 00068 CTCardBase(const CTReaderContext &ctx); 00069 00073 CTCardBase(const CTCardBase &c); 00074 00075 virtual ~CTCardBase(); 00076 00077 virtual CallBackResult callback(bool first); 00078 00079 CTError open(); 00080 CTError close(bool force=false); 00081 bool isOpen() const { return _openCount>0;}; 00082 00092 const string atr() const { return _atr;}; 00093 00103 unsigned int readerFlags() const; 00104 00105 unsigned int readerStatus() const; 00106 00110 const CHIPCARD_READERDESCR &readerDescription() const; 00111 00117 void setTimeout(int t) { _timeout=t;}; 00118 00123 int timeout() const { return _timeout;}; 00124 00128 CTError sendAPDU(const string &apdu, string &response); 00129 00130 }; 00131 00132 00133 00134 00135 #endif 00136 00137