|
template<typename... Tail> |
constexpr | Sysctl (mib_t const head, Tail const ... tail) noexcept |
| Initialise the MIB address directly. More...
|
|
size_t | size () const |
| The size of the sysctl. More...
|
|
void | get (void *const buf, size_t const bufsize) const |
| Update the given buffer with a value retrieved from the sysctl. More...
|
|
template<typename T > |
void | get (T &value) const |
| Update the given value with a value retreived from the sysctl. More...
|
|
template<typename T > |
std::unique_ptr< T[]> | get () const |
| Retrieve an array from the sysctl address. More...
|
|
void | set (void const *const buf, size_t const bufsize) |
| Update the the sysctl value with the given buffer. More...
|
|
template<typename T > |
void | set (T const &value) |
| Update the the sysctl value with the given value. More...
|
|
template<size_t MibDepth>
class sys::ctl::Sysctl< MibDepth >
Represents a sysctl MIB address.
It offers set() and get() methods to access these sysctls.
There are two ways of initialising a Sysctl instance, by symbolic name or by directly using the MIB address. The latter one only makes sense for sysctls with a fixed address, known at compile time, e.g. Sysctl<2>{CTL_HW, HW_NCPU}
for "hw.ncpu". Check /usr/include/sys/sysctl.h
for predefined MIBs.
For all other sysctls, symbolic names must be used. E.g. Sysctl<0>{"dev.cpu.0.freq"}
. Creating a Sysctl from a symbolic name may throw.
Suitable deduction guides usually allow omitting the template arguments, i.e. Sysctl{CTL_HW, HW_NCPU} and Sysctl{"dev.cpu.0.freq"} implicitly use the correct template argument.
- Template Parameters
-
MibDepth | The MIB level, e.g. "hw.ncpu" is two levels deep |
template<size_t MibDepth>
template<typename... Tail>
Initialise the MIB address directly.
Some important sysctl values have a fixed address that can be initialised at compile time with a noexcept guarantee.
Spliting the MIB address into head and tail makes sure that Sysctl(char *)
does not match the template and is instead implicitly cast to invoke Sysctl(char const *)
.
- Template Parameters
-
Tail | The types of the trailing MIB address values (must be mib_t) |
- Parameters
-