YPC  0.2.0
privacy_data_reader.h
1 #pragma once
2 #include "ypc/core/byte.h"
3 #include <dlfcn.h>
4 #include <exception>
5 #include <string>
6 
7 namespace ypc {
8 class component_load_failure : public std::exception {
9 public:
10  explicit component_load_failure(const std::string &name);
11  virtual const char *what() const throw();
12 
13 protected:
14  const std::string m_name;
15  std::string m_res;
16 };
17 
18 class component_sym_failure : public std::exception {
19 public:
20  component_sym_failure(const std::string &name, const std::string &sym);
21  virtual const char *what() const throw();
22 
23 protected:
24  const std::string m_name;
25  const std::string m_sym;
26  std::string m_res;
27 };
28 
30 public:
31  privacy_data_reader(const std::string &plugin_path,
32  const std::string &extra_param);
33  virtual ~privacy_data_reader();
34 
35  privacy_data_reader(const privacy_data_reader &) = delete;
37  privacy_data_reader &operator=(privacy_data_reader &&) = delete;
38  privacy_data_reader &operator=(const privacy_data_reader &) = delete;
39 
40  void reset_for_read();
41  bytes read_item_data();
42  uint64_t get_item_number();
43  bytes get_sample_data();
44  std::string get_data_format();
45 
46 protected:
47  template <typename T> T get_func_with_name(const std::string &name) {
48  T r = (T)dlsym(m_lib_handle, name.c_str());
49  if (!r) {
50  throw component_sym_failure(m_plugin_path + "::" + name, dlerror());
51  }
52  return r;
53  }
54 
55  template <typename T> T get_opt_func_with_name(const std::string &name) {
56  T r = (T)dlsym(m_lib_handle, name.c_str());
57  return r;
58  }
59 
60  // NOLINTBEGIN(modernize-use-using)
61  typedef void *(*create_item_reader_func_t)(const char *, int); // NOLINT
62  typedef int (*reset_for_read_func_t)(void *); // NOLINT
63  typedef int (*read_item_data_func_t)(void *, char *, int *); // NOLINT
64  typedef int (*close_item_reader_func_t)(void *); // NOLINT
65  typedef uint64_t (*get_item_number_func_t)(void *); // NOLINT
66  typedef int (*get_sample_data_func_t)(void *, char *, int *); // NOLINT
67  typedef int (*get_data_format_func_t)(void *, char *, int *); // NOLINT
68  // NOLINTEND(modernize-use-using)
69 
70  const std::string m_plugin_path;
71  const std::string m_extra_param;
72 
73  void *m_handle;
74 
75  void *m_lib_handle;
76  create_item_reader_func_t m_create_item_reader;
77  reset_for_read_func_t m_reset_for_read;
78  read_item_data_func_t m_read_item_data;
79  close_item_reader_func_t m_close_item_reader;
80 
81  get_item_number_func_t m_get_item_number;
82  get_sample_data_func_t m_get_sample_data;
83  get_data_format_func_t m_get_data_format;
84 };
85 
86 } // namespace ypc
ypc::privacy_data_reader
Definition: privacy_data_reader.h:29
byte.h
ypc::component_sym_failure
Definition: privacy_data_reader.h:18
ypc::utc::bytes< byte_t, ::ypc::utc::byte_encode::raw_bytes >
ypc::component_load_failure
Definition: privacy_data_reader.h:8