PMDK C++ bindings  1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
ctl.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2019, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_CPP_CTL_HPP
10 #define LIBPMEMOBJ_CPP_CTL_HPP
11 
12 #include <libpmemobj/ctl.h>
13 #include <string>
14 
15 #include <cerrno>
16 #include <cstring>
17 
19 
20 namespace pmem
21 {
22 
23 namespace obj
24 {
25 
26 template <typename T>
27 T
28 ctl_get_detail(PMEMobjpool *pool, const std::string &name)
29 {
30  T tmp;
31 
32 #ifdef _WIN32
33  int ret = pmemobj_ctl_getU(pool, name.c_str(), &tmp);
34 #else
35  int ret = pmemobj_ctl_get(pool, name.c_str(), &tmp);
36 #endif
37  if (ret)
38  throw pmem::ctl_error("ctl_get failed").with_pmemobj_errormsg();
39 
40  return tmp;
41 }
42 
43 template <typename T>
44 T
45 ctl_set_detail(PMEMobjpool *pool, const std::string &name, T arg)
46 {
47 #ifdef _WIN32
48  int ret = pmemobj_ctl_setU(pool, name.c_str(), &arg);
49 #else
50  int ret = pmemobj_ctl_set(pool, name.c_str(), &arg);
51 #endif
52  if (ret)
53  throw pmem::ctl_error("ctl_set failed").with_pmemobj_errormsg();
54 
55  return arg;
56 }
57 
58 template <typename T>
59 T
60 ctl_exec_detail(PMEMobjpool *pool, const std::string &name, T arg)
61 {
62 #ifdef _WIN32
63  int ret = pmemobj_ctl_execU(pool, name.c_str(), &arg);
64 #else
65  int ret = pmemobj_ctl_exec(pool, name.c_str(), &arg);
66 #endif
67  if (ret)
68  throw pmem::ctl_error("ctl_exec failed")
69  .with_pmemobj_errormsg();
70 
71  return arg;
72 }
73 
74 #ifdef _WIN32
75 template <typename T>
76 T
77 ctl_get_detail(PMEMobjpool *pool, const std::wstring &name)
78 {
79  T tmp;
80 
81  int ret = pmemobj_ctl_getW(pool, name.c_str(), &tmp);
82  if (ret)
83  throw pmem::ctl_error("ctl_get failed").with_pmemobj_errormsg();
84 
85  return tmp;
86 }
87 
88 template <typename T>
89 T
90 ctl_set_detail(PMEMobjpool *pool, const std::wstring &name, T arg)
91 {
92  int ret = pmemobj_ctl_setW(pool, name.c_str(), &arg);
93  if (ret)
94  throw pmem::ctl_error("ctl_set failed").with_pmemobj_errormsg();
95 
96  return arg;
97 }
98 
99 template <typename T>
100 T
101 ctl_exec_detail(PMEMobjpool *pool, const std::wstring &name, T arg)
102 {
103  int ret = pmemobj_ctl_execW(pool, name.c_str(), &arg);
104  if (ret)
105  throw pmem::ctl_error("ctl_exec failed")
106  .with_pmemobj_errormsg();
107 
108  return arg;
109 }
110 #endif
111 
112 } /* namespace obj */
113 
114 } /* namespace pmem */
115 
116 #endif /* LIBPMEMOBJ_CPP_CTL_HPP */
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15
pexceptions.hpp
Custom exceptions.
pmem::ctl_error
Custom ctl error class.
Definition: pexceptions.hpp:193