SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Interface.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_fs_Interface_h
7 #define swcdb_fs_Interface_h
8 
9 
10 #include "swcdb/fs/FileSystem.h"
11 
12 #if defined (BUILTIN_FS_LOCAL) || defined (BUILTIN_FS_ALL)
14 #endif
15 
16 
17 #if defined (BUILTIN_FS_CEPH) || defined (BUILTIN_FS_ALL)
19 #endif
20 
21 
22 #if defined (BUILTIN_FS_HADOOP) || defined (BUILTIN_FS_ALL)
24 #endif
25 
26 #if defined (BUILTIN_FS_HADOOP_JVM) || defined (BUILTIN_FS_ALL)
28 #endif
29 
30 
31 #if defined (BUILTIN_FS_BROKER) || defined (BUILTIN_FS_ALL)
33 #endif
34 
35 
36 
37 namespace SWC { namespace FS {
38 
40 const int ID_SPLIT_LEN = 3;
41 const char ID_SPLIT_LAST = 'g';
42 
44 
45 class Interface final : public std::enable_shared_from_this<Interface> {
46  public:
47 
48  typedef std::shared_ptr<Interface> Ptr;
49 
50  Interface(const Config::Settings::Ptr& settings, Type typ);
51 
53 
55  Ptr ptr() noexcept {
56  return shared_from_this();
57  }
58 
59  ~Interface() noexcept;
60 
61  Type get_type_underlying() const noexcept;
62 
64  FileSystem::Ptr& get_fs() noexcept {
65  return m_fs;
66  }
67 
68  std::string to_string() const;
69 
70  bool need_fds() const noexcept;
71 
72  void stop();
73 
74  void get_structured_ids(int& err, const std::string& base_path,
75  IdEntries_t& entries,
76  const std::string& base_id="");
77 
78  // default form to FS methods
79 
80  void readdir(int& err, const std::string& base_path, DirentList& dirs);
81 
82  bool exists(int& err, const std::string& name);
83 
84  void exists(Callback::ExistsCb_t&& cb, const std::string& name);
85 
86  void mkdirs(int& err, const std::string& name);
87 
88  void rmdir(int& err, const std::string& name);
89 
90  void rmdir_incl_opt_subs(int& err, const std::string& name,
91  const std::string& up_to);
92 
93  void remove(int& err, const std::string& name);
94 
95  void remove(Callback::RemoveCb_t&& cb, const std::string& name);
96 
97  void rename(int& err, const std::string& from , const std::string& to);
98 
99  size_t length(int& err, const std::string& name);
100 
101  void read(int& err, const std::string& name, StaticBuffer* dst);
102 
103  void write(int& err, SmartFd::Ptr smartfd,
104  uint8_t replication, StaticBuffer& buffer);
105 
106  bool open(int& err, SmartFd::Ptr& smartfd);
107 
108  bool create(int& err, SmartFd::Ptr& smartfd, uint8_t replication);
109 
110  void close(int& err, SmartFd::Ptr& smartfd);
111 
112  void close(Callback::CloseCb_t&& cb, SmartFd::Ptr& smartfd);
113 
114  private:
117 
118  struct LoadedDL final {
119  void* lib = nullptr;
120  void* cfg = nullptr;
121  void* make = nullptr;
122  };
124 };
125 
126 
127 
128 void set_structured_id(const std::string& number, std::string& s);
129 
130 } // namespace FS
131 
132 
133 
134 namespace Env {
135 
136 class FsInterface final {
137 
138  public:
139 
140  typedef std::shared_ptr<FsInterface> Ptr;
141 
142  static void init(const SWC::Config::Settings::Ptr& settings, FS::Type typ);
143 
145  static Ptr& get() noexcept {
146  return m_env;
147  }
148 
150  static FS::Interface::Ptr& interface() noexcept {
151  return m_env->m_interface;
152  }
153 
155  static FS::FileSystem::Ptr& fs() noexcept {
156  return m_env->m_interface->get_fs();
157  }
158 
159  static void reset() noexcept {
160  m_env = nullptr;
161  }
162 
163  FsInterface(const SWC::Config::Settings::Ptr& settings, FS::Type typ);
164 
165  ~FsInterface() noexcept { }
166 
167  private:
169  inline static Ptr m_env = nullptr;
170 };
171 
172 
173 } // Env
174 
175 } // SWC
176 
177 
178 #ifdef SWC_IMPL_SOURCE
179 #include "swcdb/fs/Interface.cc"
180 #endif
181 
182 
183 #endif // swcdb_fs_Interface_h
SWC::Env::FsInterface::init
static void init(const SWC::Config::Settings::Ptr &settings, FS::Type typ)
Definition: Interface.cc:513
SWC::FS::FileSystem::Ptr
std::shared_ptr< FileSystem > Ptr
Definition: FileSystem.h:104
SWC::Env::FsInterface::get
static SWC_CAN_INLINE Ptr & get() noexcept
Definition: Interface.h:145
FileSystem.h
SWC::FS::Interface::rmdir_incl_opt_subs
void rmdir_incl_opt_subs(int &err, const std::string &name, const std::string &up_to)
Definition: Interface.cc:261
SWC::FS::Interface::to_string
std::string to_string() const
Definition: Interface.cc:128
SWC::Config::Settings::Ptr
std::shared_ptr< Settings > Ptr
Definition: Settings.h:29
SWC::Env::FsInterface::FsInterface
FsInterface(const SWC::Config::Settings::Ptr &settings, FS::Type typ)
Definition: Interface.cc:518
SWC::FS::Type
Type
Definition: FileSystem.h:20
SWC::FS::Interface::write
void write(int &err, SmartFd::Ptr smartfd, uint8_t replication, StaticBuffer &buffer)
Definition: Interface.cc:374
SWC::FS::Interface
Interface to FileSystems.
Definition: Interface.h:45
FileSystem.h
SWC::FS::Interface::open
bool open(int &err, SmartFd::Ptr &smartfd)
Definition: Interface.cc:412
SWC::Env::FsInterface::interface
static SWC_CAN_INLINE FS::Interface::Ptr & interface() noexcept
Definition: Interface.h:150
SWC::FS::Interface::get_fs
SWC_CAN_INLINE FileSystem::Ptr & get_fs() noexcept
Definition: Interface.h:64
SWC::FS::Interface::rmdir
void rmdir(int &err, const std::string &name)
Definition: Interface.cc:245
SWC::FS::FileSystem
Definition: FileSystem.h:101
FileSystem.h
SWC::FS::Interface::remove
void remove(int &err, const std::string &name)
Definition: Interface.cc:289
SWC::FS::Callback::ExistsCb_t
std::function< void(int, bool)> ExistsCb_t
Definition: Callbacks.h:20
SWC::FS::Interface::~Interface
~Interface() noexcept
Definition: Interface.cc:117
SWC::FS::Callback::CloseCb_t
std::function< void(int)> CloseCb_t
Definition: Callbacks.h:41
SWC::FS::Interface::LoadedDL
Definition: Interface.h:118
SWC::FS::Interface::stop
void stop()
Definition: Interface.cc:137
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::FS::Interface::get_structured_ids
void get_structured_ids(int &err, const std::string &base_path, IdEntries_t &entries, const std::string &base_id="")
Definition: Interface.cc:141
SWC::FS::Interface::exists
bool exists(int &err, const std::string &name)
Definition: Interface.cc:201
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::FS::Interface::readdir
void readdir(int &err, const std::string &base_path, DirentList &dirs)
Definition: Interface.cc:183
SWC::FS::ID_SPLIT_LAST
const char ID_SPLIT_LAST
Definition: Interface.h:41
SWC::Env::FsInterface
Definition: Interface.h:136
FileSystem.h
SWC::Core::Buffer
Definition: Buffer.h:18
SWC::FS::Interface::create
bool create(int &err, SmartFd::Ptr &smartfd, uint8_t replication)
Definition: Interface.cc:429
SWC::Env::FsInterface::fs
static SWC_CAN_INLINE FS::FileSystem::Ptr & fs() noexcept
Definition: Interface.h:155
SWC::FS::Interface::Interface
Interface(const Config::Settings::Ptr &settings, Type typ)
Definition: Interface.cc:19
SWC::FS::Interface::need_fds
bool need_fds() const noexcept
Definition: Interface.cc:133
SWC::FS::Interface::close
void close(int &err, SmartFd::Ptr &smartfd)
Definition: Interface.cc:446
SWC::FS::ID_SPLIT_LEN
const int ID_SPLIT_LEN
Definition: Interface.h:40
SWC::FS::Callback::RemoveCb_t
std::function< void(int)> RemoveCb_t
Definition: Callbacks.h:21
SWC::FS::Interface::rename
void rename(int &err, const std::string &from, const std::string &to)
Definition: Interface.cc:326
SWC::Env::FsInterface::m_env
static Ptr m_env
Definition: Interface.h:169
SWC::FS::Interface::mkdirs
void mkdirs(int &err, const std::string &name)
Definition: Interface.cc:229
SWC::FS::SmartFd
Smart FileDescriptor.
Definition: SmartFd.h:34
SWC::FS::IdEntries_t
Core::Vector< uint64_t > IdEntries_t
Definition: Interface.h:39
SWC::Core::Vector
Definition: Vector.h:14
SWC::Env::FsInterface::m_interface
FS::Interface::Ptr m_interface
Definition: Interface.h:168
SWC::Condition::from
Comp from(const char **buf, uint32_t *remainp, uint8_t extended=0x00) noexcept
Definition: Comparators.cc:15
SWC::FS::Interface::use_filesystem
FileSystem::Ptr use_filesystem(const Config::Settings::Ptr &settings)
Definition: Interface.cc:27
SWC::FS::Interface::length
size_t length(int &err, const std::string &name)
Definition: Interface.cc:355
SWC::FS::Interface::m_fs
FileSystem::Ptr m_fs
Definition: Interface.h:116
SWC::Env::FsInterface::~FsInterface
~FsInterface() noexcept
Definition: Interface.h:165
SWC::FS::Interface::get_type_underlying
Type get_type_underlying() const noexcept
Definition: Interface.cc:124
SWC::FS::Interface::ptr
SWC_CAN_INLINE Ptr ptr() noexcept
Definition: Interface.h:55
SWC::FS::Interface::read
void read(int &err, const std::string &name, StaticBuffer *dst)
Definition: Interface.cc:394
SWC::Env::FsInterface::Ptr
std::shared_ptr< FsInterface > Ptr
Definition: Interface.h:140
SWC::FS::set_structured_id
void set_structured_id(const std::string &number, std::string &s)
Definition: Interface.cc:494
FileSystem.h
FileSystem.h
SWC::FS::Interface::Ptr
std::shared_ptr< Interface > Ptr
Definition: Interface.h:48
SWC::FS::Interface::loaded_dl
LoadedDL loaded_dl
Definition: Interface.h:123
SWC::Env::FsInterface::reset
static void reset() noexcept
Definition: Interface.h:159
Interface.cc
SWC::FS::Interface::m_type
Type m_type
Definition: Interface.h:115