Yate: SharedVars Class Reference

Yate

Public Member Functions | Static Public Member Functions | List of all members
SharedVars Class Reference

Atomic access and operations to shared variables. More...

`#include <yatengine.h>`

Inheritance diagram for SharedVars:

## Public Member Functions
| SharedVars (const char *name=0)
void | get (const String &name, String &rval)
void | set (const String &name, const char *val)
bool | create (const String &name, const char *val=0)
void | clear (const String &name)
void | clearAll ()
bool | exists (const String &name)
uint64_t | inc (const String &name, uint64_t wrap=0)
uint64_t | dec (const String &name, uint64_t wrap=0)
uint64_t | add (const String &name, uint64_t val, uint64_t wrap=0)
uint64_t | sub (const String &name, uint64_t val, uint64_t wrap=0)
void | copy (NamedList &dest, const String &prefix=String::empty(), bool skipPrefix=true, bool replace=false)
virtual const String & | toString () const
Public Member Functions inherited from Mutex
| Mutex (bool recursive=false, const char *name=0)
| Mutex (const Mutex &original)
| ~Mutex ()
Mutex & | operator= (const Mutex &original)
virtual bool | lock (long maxwait=-1)
virtual bool | unlock ()
virtual bool | locked () const
const char * | owner () const
bool | recursive () const
virtual Mutex * | lockableMutex ()
Public Member Functions inherited from Lockable
virtual | ~Lockable ()
virtual bool | check (long maxwait=-1)
virtual bool | unlockAll ()
virtual Semaphore * | lockableSemaphore ()
virtual RWLock * | lockableRWLock ()
Public Member Functions inherited from RefObject
| RefObject ()
virtual | ~RefObject ()
virtual void * | getObject (const String &name) const
virtual bool | alive () const
bool | ref ()
bool | deref ()
int | refcount () const
virtual void | destruct ()
Public Member Functions inherited from GenObject
| GenObject ()
virtual | ~GenObject ()
virtual const String & | traceId () const
NamedCounter * | getObjCounter () const
NamedCounter * | setObjCounter (NamedCounter *counter)

## Static Public Member Functions
static bool | getList (RefPointer< SharedVars > &dest, const String &name)
Static Public Member Functions inherited from Mutex
static int | count ()
static int | locks ()
static bool | efficientTimedLock ()
Static Public Member Functions inherited from Lockable
static void | wait (unsigned long maxwait)
static unsigned long | wait ()
static void | startUsingNow ()
static void | enableSafety (bool safe=true)
static bool | safety ()
Static Public Member Functions inherited from RefObject
static bool | alive (const RefObject *obj)
static bool | efficientIncDec ()
Static Public Member Functions inherited from GenObject
static void * | getObject (const String &name, const GenObject *obj)
static bool | getObjCounting ()
static void | setObjCounting (bool enable)
static NamedCounter * | getObjCounter (const String &name, bool create=true)
static ObjList & | getObjCounters ()

## Additional Inherited Members
Protected Member Functions inherited from RefObject
virtual void | zeroRefs ()
bool | resurrect ()
virtual void | destroyed ()

## Detailed Description

Atomic access and operations to shared variables.

Class that implements atomic / locked access and operations to its shared variables

## Constructor & Destructor Documentation

## ◆ SharedVars()

SharedVars | ( | const char * | name = 0 | ) |
| inline

Constructor

Parameters

  name | Optional name

## Member Function Documentation

## ◆ add()

uint64_t add | ( | const String & | name,
|  | uint64_t | val,
|  | uint64_t | wrap = 0 )

Atomically add a value to a variable as unsigned integer

Parameters

  name | Name of the variable
  val | Value to add
  wrap | Value to wrap around at, zero disables

Returns
  Value of the variable before addition, zero if it was not defined or not numeric

## ◆ clear()

void clear | ( | const String & | name | ) |

Clear a variable

Parameters

  name | Name of the variable to clear

## ◆ clearAll()

void clearAll | ( |  | ) |

Clear all variables. Does nothing for Engine (global shared list)

## ◆ copy()

void copy | ( | NamedList & | dest,
|  | const String & | prefix = String::empty(),
|  | bool | skipPrefix = true,
|  | bool | replace = false )
| inline

Atomically copy parameters to destination

Parameters

  dest | Destination list
  prefix | Optional prefix to match in parameter names
  skipPrefix | Skip over the prefix when building new parameter name
  replace | Set to true to replace list parameter instead of adding a new one

References NamedList::copyParams(), and NamedList::copySubParams().

## ◆ create()

bool create | ( | const String & | name,
|  | const char * | val = 0 )

Create and set a variable only if the variable is not already set

Parameters

  name | Name of the variable to set
  val | New value to assign to a variable

Returns
  True if a new variable was created

## ◆ dec()

uint64_t dec | ( | const String & | name,
|  | uint64_t | wrap = 0 )

Atomically decrement a variable as unsigned integer

Parameters

  name | Name of the variable
  wrap | Value to wrap around at, zero disables (stucks at zero)

Returns
  Value of the variable after decrement, zero if it was not defined or not numeric

## ◆ exists()

bool exists | ( | const String & | name | ) |

Check if a variable exists

Parameters

  name | Name of the variable

Returns
  True if the variable exists

## ◆ get()

void get | ( | const String & | name,
|  | String & | rval )

Get the string value of a variable

Parameters

  name | Name of the variable
  rval | String to return the value into

## ◆ getList()

static bool getList | ( | RefPointer< SharedVars > & | dest,
|  | const String & | name )
| static

Retrieve a named list of SharedVars. Create it if not found

Parameters

  dest | Destination to be filled with requested list
  name | Name of the list

Returns
  True id destination is iset. The function will fail if name is empty

## ◆ inc()

uint64_t inc | ( | const String & | name,
|  | uint64_t | wrap = 0 )

Atomically increment a variable as unsigned integer

Parameters

  name | Name of the variable
  wrap | Value to wrap around at, zero disables

Returns
  Value of the variable before increment, zero if it was not defined or not numeric

## ◆ set()

void set | ( | const String & | name,
|  | const char * | val )

Set the string value of a variable

Parameters

  name | Name of the variable to set
  val | New value to assign to a variable

## ◆ sub()

uint64_t sub | ( | const String & | name,
|  | uint64_t | val,
|  | uint64_t | wrap = 0 )

Atomically substract a value from a variable as unsigned integer

Parameters

  name | Name of the variable
  val | Value to substract
  wrap | Value to wrap around at, zero disables

Returns
  Value of the variable after substraction, zero if it was not defined or not numeric

## ◆ toString()

virtual const String & toString | ( |  | ) | const
| inlinevirtual

Retrieve list name

Returns
  List name

Reimplemented from GenObject.

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

- yatengine.h