powerd++  0.4.4
Classes | Typedefs | Functions
sys::ctl Namespace Reference

This namespace contains safer c++ wrappers for the sysctl() interface. More...

Classes

struct  error
 The domain error type. More...
 
class  Once
 A read once representation of a Sysctl. More...
 
class  Sync
 This is a wrapper around Sysctl that allows semantically transparent use of a sysctl. More...
 
class  Sysctl
 Represents a sysctl MIB address. More...
 
class  Sysctl< 0 >
 This is a specialisation of Sysctl for sysctls using symbolic names. More...
 

Typedefs

typedef int mib_t
 Management Information Base identifier type (see sysctl(3)).
 
template<typename T , size_t MibDepth = 0>
using SysctlSync = Sync< T, Sysctl< MibDepth > >
 A convenience alias around Sync. More...
 
template<typename T , size_t MibDepth = 0>
using SysctlOnce = Once< T, Sysctl< MibDepth > >
 A convenience alias around Once. More...
 

Functions

void sysctl_raw (mib_t const *name, u_int const namelen, void *const oldp, size_t *const oldlenp, void const *const newp, size_t const newlen)
 A wrapper around the sysctl() function. More...
 
template<size_t MibDepth>
void sysctl_get (mib_t const (&mib)[MibDepth], void *const oldp, size_t &oldlen)
 Returns a sysctl() value to a buffer. More...
 
template<size_t MibDepth>
void sysctl_set (mib_t const (&mib)[MibDepth], void const *const newp, size_t const newlen)
 Sets a sysctl() value. More...
 
template<typename ... ArgTs>
 Sysctl (mib_t const, ArgTs const ...) -> Sysctl<(1+sizeof...(ArgTs))>
 Create a Sysctl from a set of predefined MIBs. More...
 
 Sysctl (char const *const) -> Sysctl< 0 >
 Create a Sysctl<0> by name.
 
 Sysctl () -> Sysctl< 0 >
 Default construct a Sysctl<0>.
 

Detailed Description

This namespace contains safer c++ wrappers for the sysctl() interface.

The template class Sysctl represents a sysctl address and offers handles to retrieve or set the stored value.

The template class Sync represents a sysctl value that is read and written synchronously.

The template class Once represents a read once value.


Class Documentation

◆ sys::ctl::error

struct sys::ctl::error

The domain error type.

Typedef Documentation

◆ SysctlOnce

template<typename T , size_t MibDepth = 0>
using sys::ctl::SysctlOnce = typedef Once<T, Sysctl<MibDepth> >

A convenience alias around Once.

// Once<coreid_t, Sysctl<2>> ncpu{0, {CTL_HW, HW_NCPU}};
SysctlOnce<coreid_t, 2> ncpu{1, {CTL_HW, HW_NCPU}};
Template Parameters
TThe type to represent the sysctl as
MibDepthThe maximum allowed MIB depth

◆ SysctlSync

template<typename T , size_t MibDepth = 0>
using sys::ctl::SysctlSync = typedef Sync<T, Sysctl<MibDepth> >

A convenience alias around Sync.

// Sync<int, Sysctl<0>> sndUnit{{"hw.snd.default_unit"}};
SysctlSync<int> sndUnit{{"hw.snd.default_unit"}};
if (sndUnit != 3) { // read from sysctl
sndUnit = 3; // assign to sysctl
}
Template Parameters
TThe type to represent the sysctl as
MibDepthThe MIB depth, provide only for compile time initialisation

Function Documentation

◆ Sysctl()

template<typename ... ArgTs>
sys::ctl::Sysctl ( mib_t const  ,
ArgTs  const ... 
) -> Sysctl<(1+sizeof...(ArgTs))>

Create a Sysctl from a set of predefined MIBs.

Template Parameters
ArgsList of argument types, should all be mib_t

◆ sysctl_get()

template<size_t MibDepth>
void sys::ctl::sysctl_get ( mib_t const (&)  mib[MibDepth],
void *const  oldp,
size_t &  oldlen 
)

Returns a sysctl() value to a buffer.

Template Parameters
MibDepthThe length of the MIB buffer
Parameters
mibThe MIB buffer
oldp,oldlenA pointers to the return buffer and a reference to its length
Exceptions
sys::sc_error<error>Throws if sysctl() fails for any reason

◆ sysctl_raw()

void sys::ctl::sysctl_raw ( mib_t const *  name,
u_int const  namelen,
void *const  oldp,
size_t *const  oldlenp,
void const *const  newp,
size_t const  newlen 
)
inline

A wrapper around the sysctl() function.

All it does is throw an exception if sysctl() fails.

Parameters
name,namelenThe MIB buffer and its length
oldp,oldlenpPointers to the return buffer and its length
newp,newlenA pointer to the buffer with the new value and the buffer length
Exceptions
sys::sc_error<error>Throws if sysctl() fails for any reason

◆ sysctl_set()

template<size_t MibDepth>
void sys::ctl::sysctl_set ( mib_t const (&)  mib[MibDepth],
void const *const  newp,
size_t const  newlen 
)

Sets a sysctl() value.

Template Parameters
MibDepthThe length of the MIB buffer
Parameters
mibThe MIB buffer
newp,newlenA pointer to the buffer with the new value and the buffer length
Exceptions
sys::sc_error<error>Throws if sysctl() fails for any reason