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,7 +5,6 @@
5 5
 #include <winscard.h>
6 6
 #include <vector>
7 7
 #include <string.h>
8
-#include <reader.h>
9 8
 #include "ScReader.h"
10 9
 
11 10
 thread_local LPSCARDCONTEXT ScReader::_context = nullptr;
@@ -90,42 +89,15 @@ std::vector<std::shared_ptr<ScReader>> ScReader::getReaders()
90 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 92
 std::string ScReader::getAttribute(DWORD attr)
104 93
 {
105 94
     DWORD len = SCARD_AUTOALLOCATE;
106 95
     BYTE* data = nullptr;
107 96
     _lastResult = SCardGetAttrib(*_card, attr, (BYTE*)&data, &len);
97
+    std::string str((char*)data, len);
98
+    SCardFreeMemory(*_context, data);
108 99
     if (_lastResult == SCARD_S_SUCCESS)
109
-        return std::string((char*)data, len);
100
+        return str;
110 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,7 +8,6 @@
8 8
 # include <wintypes.h>
9 9
 # include <pcsclite.h>
10 10
 # include <memory>
11
-#include <bits/stl_bvector.h>
12 11
 # include "ScCommand.h"
13 12
 # include "ScResult.h"
14 13
 
@@ -23,13 +22,13 @@ public:
23 22
 
24 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 33
     static bool establishContext();
35 34
 
@@ -46,7 +45,7 @@ public:
46 45
 
47 46
     std::string getAttribute(DWORD attr);
48 47
 
49
-    std::string getAtr();
48
+    inline std::string getAtr();
50 49
 
51 50
 private:
52 51
     std::string _name;

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

@@ -2,6 +2,8 @@
2 2
 // Created by robin on 6/28/15.
3 3
 //
4 4
 
5
+#include <reader.h>
6
+
5 7
 ScReader::ScReader(std::string name)
6 8
     : _name(name)
7 9
     , _card(nullptr)
@@ -12,4 +14,34 @@ ScReader::ScReader(std::string name)
12 14
 const std::string ScReader::getName() const
13 15
 {
14 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