-
Notifications
You must be signed in to change notification settings - Fork 15
/
storage.h
75 lines (54 loc) · 1.72 KB
/
storage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef ST_STORAGE_H
#define ST_STORAGE_H
#include <memory>
#include <list>
#include <map>
#include <boost/property_tree/ptree.hpp>
#include "types.h"
#include "tools.h"
struct item_t {
item_t(const std::string& fn, const std::vector<char>& d, const Attributes& a = Attributes())
: filename(fn)
, data(d)
, attributes(a)
{}
const std::string filename;
const std::vector<char> data;
Attributes attributes;
};
struct storage_t {
virtual ~storage_t(){};
static std::shared_ptr<storage_t> create(const boost::property_tree::ptree& config, const std::string& pin = std::string());
virtual std::list<item_t> items() = 0;
virtual item_t read(const std::string& fn) = 0;
virtual item_t write(const item_t& item) = 0;
virtual bool present() const = 0;
virtual void set_pin(const std::string& pin) = 0;
std::string full_name() const {
if (prev) {
return name() + "|" + prev->full_name();
}
else {
return name();
}
}
protected:
storage_t(const std::string& n, const boost::property_tree::ptree& c, std::shared_ptr<storage_t> s = std::shared_ptr<storage_t>())
: name_(n), prev(s), config_(c){};
storage_t(const storage_t& other) = delete;
storage_t& operator=(const storage_t& other) = delete;
const std::string& name() const {return name_;};
std::string name_;
std::shared_ptr<storage_t> prev;
boost::property_tree::ptree config_;
std::string path_;
};
struct descriptor_t {
descriptor_t(const item_t& it);
~descriptor_t() {}
const item_t item;
std::string first_line;
CK_OBJECT_HANDLE id;
std::shared_ptr<FILE> file;
};
#endif