powerd++  0.4.4
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
anonymous_namespace{libloadplay.cpp}::SysctlValue Class Reference

Instances of this class represents a specific sysctl value. More...

Collaboration diagram for anonymous_namespace{libloadplay.cpp}::SysctlValue:
[legend]

Public Member Functions

 SysctlValue ()
 Default constructor.
 
 SysctlValue (SysctlValue const &copy)
 Copy constructor. More...
 
 SysctlValue (SysctlValue &&move)
 Move constructor. More...
 
 SysctlValue (unsigned int type, std::string const &value, callback_function const callback=nullptr)
 Construct from a type, value and optionally callback tuple. More...
 
SysctlValueoperator= (SysctlValue const &copy)
 Copy assignment operator. More...
 
SysctlValueoperator= (SysctlValue &&move)
 Move assignment operator. More...
 
size_t size () const
 Returns the required storage size according to the CTLTYPE. More...
 
template<typename T >
int get (T *dst, size_t &size) const
 Copy a list of values into the given buffer. More...
 
int get (char *dst, size_t &size) const
 Copy a C string into the given buffer. More...
 
template<typename T >
get () const
 Returns a single value. More...
 
int get (void *dst, size_t &size) const
 Copy a list of values into the given buffer. More...
 
template<typename T >
void set (T const *const newp, size_t newlen)
 Set this value to the values in the given buffer. More...
 
int set (void const *const newp, size_t newlen)
 Set this value to the values in the given buffer. More...
 
void set (std::string &&value)
 Move a string to the value. More...
 
void set (std::string const &value)
 Copy a string to the value. More...
 
template<typename T >
void set (T const &value)
 Set the value. More...
 
void registerOnSet (callback_function &&callback)
 Register a callback function. More...
 
void registerOnSet (callback_function const &callback)
 Register a callback function. More...
 

Private Types

typedef std::lock_guard< decltype(mtx)> lock_guard
 Lock guard type, fitting the mutex.
 

Private Member Functions

template<typename T >
size_t size () const
 Provide the size of this value represented as a string of Ts. More...
 

Private Attributes

decltype(onSet) typedef ::function_t callback_function
 Callback function type.
 
std::recursive_mutex mtx
 A stackable mutex. More...
 
unsigned int type
 The sysctl type.
 
std::string value
 The value of the sysctl. More...
 
Callback< SysctlValue & > onSet
 Callback function handle.
 

Detailed Description

Instances of this class represents a specific sysctl value.

There should only be one instance of this class per MIB.

Instances are thread safe.

Constructor & Destructor Documentation

◆ SysctlValue() [1/3]

anonymous_namespace{libloadplay.cpp}::SysctlValue::SysctlValue ( SysctlValue const &  copy)
inline

Copy constructor.

Parameters
copyThe instance to copy

◆ SysctlValue() [2/3]

anonymous_namespace{libloadplay.cpp}::SysctlValue::SysctlValue ( SysctlValue &&  move)
inline

Move constructor.

Parameters
moveThe instance to move

◆ SysctlValue() [3/3]

anonymous_namespace{libloadplay.cpp}::SysctlValue::SysctlValue ( unsigned int  type,
std::string const &  value,
callback_function const  callback = nullptr 
)
inline

Construct from a type, value and optionally callback tuple.

Parameters
typeThe CTLTYPE
valueA string representation of the value
callbackA callback function that is called for each set() call

Member Function Documentation

◆ get() [1/4]

template<typename T >
T anonymous_namespace{libloadplay.cpp}::SysctlValue::get ( ) const
inline

Returns a single value.

Template Parameters
TThe type of the value
Returns
The value

◆ get() [2/4]

int anonymous_namespace{libloadplay.cpp}::SysctlValue::get ( char *  dst,
size_t &  size 
) const
inline

Copy a C string into the given buffer.

Parameters
dst,sizeThe destination buffer and size
Return values
0On success
-1On failure to fit all values into the taget buffer, also sets errno=ENOMEM

◆ get() [3/4]

template<typename T >
int anonymous_namespace{libloadplay.cpp}::SysctlValue::get ( T *  dst,
size_t &  size 
) const
inline

Copy a list of values into the given buffer.

Template Parameters
TThe type of the values to extract
Parameters
dst,sizeThe destination buffer and size
Return values
0On success
-1On failure to fit all values into the target buffer, also sets errno=ENOMEM

◆ get() [4/4]

int anonymous_namespace{libloadplay.cpp}::SysctlValue::get ( void *  dst,
size_t &  size 
) const
inline

Copy a list of values into the given buffer.

Parameters
dst,sizeThe destination buffer and size
Return values
0On success
-1On failure to fit all values into the taget buffer, also sets errno=ENOMEM

◆ operator=() [1/2]

SysctlValue& anonymous_namespace{libloadplay.cpp}::SysctlValue::operator= ( SysctlValue &&  move)
inline

Move assignment operator.

Parameters
moveThe instance to move
Returns
A self reference

◆ operator=() [2/2]

SysctlValue& anonymous_namespace{libloadplay.cpp}::SysctlValue::operator= ( SysctlValue const &  copy)
inline

Copy assignment operator.

Parameters
copyThe instance to copy
Returns
A self reference

◆ registerOnSet() [1/2]

void anonymous_namespace{libloadplay.cpp}::SysctlValue::registerOnSet ( callback_function &&  callback)
inline

Register a callback function.

Parameters
callbackThe function to move to the callback handler

◆ registerOnSet() [2/2]

void anonymous_namespace{libloadplay.cpp}::SysctlValue::registerOnSet ( callback_function const &  callback)
inline

Register a callback function.

Parameters
callbackThe function to copy to the callback handler

◆ set() [1/5]

void anonymous_namespace{libloadplay.cpp}::SysctlValue::set ( std::string &&  value)
inline

Move a string to the value.

Parameters
valueThe new value

◆ set() [2/5]

void anonymous_namespace{libloadplay.cpp}::SysctlValue::set ( std::string const &  value)
inline

Copy a string to the value.

Parameters
valueThe new value

◆ set() [3/5]

template<typename T >
void anonymous_namespace{libloadplay.cpp}::SysctlValue::set ( T const &  value)
inline

Set the value.

Template Parameters
TThe value type
Parameters
valueThe value to set

◆ set() [4/5]

template<typename T >
void anonymous_namespace{libloadplay.cpp}::SysctlValue::set ( T const *const  newp,
size_t  newlen 
)
inline

Set this value to the values in the given buffer.

Template Parameters
TThe type of the values
Parameters
newp,newlenThe source buffer and size

◆ set() [5/5]

int anonymous_namespace{libloadplay.cpp}::SysctlValue::set ( void const *const  newp,
size_t  newlen 
)
inline

Set this value to the values in the given buffer.

The buffer will be treated as an array of CTLTYPE values.

Parameters
newp,newlenThe source buffer and size

◆ size() [1/2]

template<typename T >
size_t anonymous_namespace{libloadplay.cpp}::SysctlValue::size ( ) const
inlineprivate

Provide the size of this value represented as a string of Ts.

Template Parameters
TThe type this value is supposed to be a array of
Returns
The size of the whole string of Ts

◆ size() [2/2]

size_t anonymous_namespace{libloadplay.cpp}::SysctlValue::size ( ) const
inline

Returns the required storage size according to the CTLTYPE.

Returns
The required buffer size to hold the values.
Exceptions
intThrows -1 if the current CTLTYPE is not implemented.

Member Data Documentation

◆ mtx

std::recursive_mutex anonymous_namespace{libloadplay.cpp}::SysctlValue::mtx
mutableprivate

A stackable mutex.

nice for exposing methods publicly and still let them allow accessing each other.

◆ value

std::string anonymous_namespace{libloadplay.cpp}::SysctlValue::value
private

The value of the sysctl.

This is stored as a string and converted to the appropriate type by the set() and get() methods.


The documentation for this class was generated from the following file: