Browse Source

reader inline

master
Robin Thoni 9 years ago
parent
commit
9413225130
3 changed files with 41 additions and 38 deletions
  1. 3
    31
      src/DataAccess/ScReader.cpp
  2. 5
    6
      src/include/ScReader.h
  3. 33
    1
      src/include/ScReader.hxx

+ 3
- 31
src/DataAccess/ScReader.cpp View File

5
 #include <winscard.h>
5
 #include <winscard.h>
6
 #include <vector>
6
 #include <vector>
7
 #include <string.h>
7
 #include <string.h>
8
-#include <reader.h>
9
 #include "ScReader.h"
8
 #include "ScReader.h"
10
 
9
 
11
 thread_local LPSCARDCONTEXT ScReader::_context = nullptr;
10
 thread_local LPSCARDCONTEXT ScReader::_context = nullptr;
90
     return readers;
89
     return readers;
91
 }
90
 }
92
 
91
 
93
-LONG ScReader::getLastStaticResult()
94
-{
95
-    return _lastStaticResult;
96
-}
97
-
98
-LONG ScReader::getLastResult()
99
-{
100
-    return _lastResult;
101
-}
102
-
103
 std::string ScReader::getAttribute(DWORD attr)
92
 std::string ScReader::getAttribute(DWORD attr)
104
 {
93
 {
105
     DWORD len = SCARD_AUTOALLOCATE;
94
     DWORD len = SCARD_AUTOALLOCATE;
106
     BYTE* data = nullptr;
95
     BYTE* data = nullptr;
107
     _lastResult = SCardGetAttrib(*_card, attr, (BYTE*)&data, &len);
96
     _lastResult = SCardGetAttrib(*_card, attr, (BYTE*)&data, &len);
97
+    std::string str((char*)data, len);
98
+    SCardFreeMemory(*_context, data);
108
     if (_lastResult == SCARD_S_SUCCESS)
99
     if (_lastResult == SCARD_S_SUCCESS)
109
-        return std::string((char*)data, len);
100
+        return str;
110
     return std::string();
101
     return std::string();
111
 }
102
 }
112
 
103
 
113
-std::string ScReader::getAtr()
114
-{
115
-    return getAttribute(SCARD_ATTR_ATR_STRING);
116
-}
117
-
118
-std::string ScReader::getResultString(const LONG& error)
119
-{
120
-    return pcsc_stringify_error(error);
121
-}
122
-
123
-std::string ScReader::getLastStaticResultString()
124
-{
125
-    return getResultString(_lastStaticResult);
126
-}
127
-
128
-std::string ScReader::getLastResultString()
129
-{
130
-    return getResultString(_lastResult);
131
-}

+ 5
- 6
src/include/ScReader.h View File

8
 # include <wintypes.h>
8
 # include <wintypes.h>
9
 # include <pcsclite.h>
9
 # include <pcsclite.h>
10
 # include <memory>
10
 # include <memory>
11
-#include <bits/stl_bvector.h>
12
 # include "ScCommand.h"
11
 # include "ScCommand.h"
13
 # include "ScResult.h"
12
 # include "ScResult.h"
14
 
13
 
23
 
22
 
24
     static LONG getLastStaticResult();
23
     static LONG getLastStaticResult();
25
 
24
 
26
-    static std::string getLastStaticResultString();
25
+    static inline std::string getLastStaticResultString();
27
 
26
 
28
-    static std::string getResultString(const LONG& result);
27
+    static inline std::string getResultString(const LONG& result);
29
 
28
 
30
-    LONG getLastResult();
29
+    inline LONG getLastResult();
31
 
30
 
32
-    std::string getLastResultString();
31
+    inline std::string getLastResultString();
33
 
32
 
34
     static bool establishContext();
33
     static bool establishContext();
35
 
34
 
46
 
45
 
47
     std::string getAttribute(DWORD attr);
46
     std::string getAttribute(DWORD attr);
48
 
47
 
49
-    std::string getAtr();
48
+    inline std::string getAtr();
50
 
49
 
51
 private:
50
 private:
52
     std::string _name;
51
     std::string _name;

+ 33
- 1
src/include/ScReader.hxx View File

2
 // Created by robin on 6/28/15.
2
 // Created by robin on 6/28/15.
3
 //
3
 //
4
 
4
 
5
+#include <reader.h>
6
+
5
 ScReader::ScReader(std::string name)
7
 ScReader::ScReader(std::string name)
6
     : _name(name)
8
     : _name(name)
7
     , _card(nullptr)
9
     , _card(nullptr)
12
 const std::string ScReader::getName() const
14
 const std::string ScReader::getName() const
13
 {
15
 {
14
     return _name;
16
     return _name;
15
-}
17
+}
18
+
19
+LONG ScReader::getLastStaticResult()
20
+{
21
+    return _lastStaticResult;
22
+}
23
+
24
+LONG ScReader::getLastResult()
25
+{
26
+    return _lastResult;
27
+}
28
+
29
+std::string ScReader::getAtr()
30
+{
31
+    return getAttribute(SCARD_ATTR_ATR_STRING);
32
+}
33
+
34
+std::string ScReader::getResultString(const LONG& error)
35
+{
36
+    return pcsc_stringify_error(error);
37
+}
38
+
39
+std::string ScReader::getLastStaticResultString()
40
+{
41
+    return getResultString(_lastStaticResult);
42
+}
43
+
44
+std::string ScReader::getLastResultString()
45
+{
46
+    return getResultString(_lastResult);
47
+}

Loading…
Cancel
Save