Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core Namespace Reference

Basic building blocks. More...

Classes

class  Array
 Dynamic array. More...
 
class  Atomic
 Atomic integer. More...
 
class  Buffer
 Buffer. More...
 
class  BufferPool
 Buffer pool. More...
 
class  Cond
 Condition variable. More...
 
class  CrashHandler
 Crash handler. More...
 
class  errno_to_str
 Convert errno to string. More...
 
class  HeapAllocator
 Heap allocator implementation. More...
 
class  IAllocator
 Memory allocator interface. More...
 
class  List
 Intrusive doubly-linked list. More...
 
class  ListNode
 Base class for list element. More...
 
class  Logger
 Logger. More...
 
union  MaxAlign
 A union with maximum possible allignment. More...
 
class  Mutex
 Mutex. More...
 
class  NonCopyable
 Base class for non-copyable objects. More...
 
struct  NoOwnership
 No ownership. More...
 
class  Pool
 Pool. More...
 
class  RateLimiter
 Rate limiter. More...
 
class  RefCnt
 Base class for reference countable objects. More...
 
struct  RefCntOwnership
 Reference countable object ownership. More...
 
class  ScopedDestructor
 Destroys the object via custom deleter. More...
 
class  ScopedLock
 RAII mutex lock. More...
 
class  SharedPtr
 Shared ownership intrusive pointer. More...
 
class  Singleton
 Singleton. More...
 
class  Slice
 Slice. More...
 
class  TempFile
 Temporary file. More...
 
class  Thread
 Base class for thread objects. More...
 
class  Ticker
 Ticker. More...
 
class  UniquePtr
 Unique ownrship pointer. More...
 

Typedefs

typedef void(* LogHandler) (LogLevel level, const char *module, const char *message)
 Log handler. More...
 
typedef int64_t nanoseconds_t
 Nanoseconds. More...
 

Enumerations

enum  ColorsMode { ColorsDisabled, ColorsEnabled }
 Colors mode. More...
 

Functions

size_t max_align (size_t sz)
 Adjust the given size to be maximum aligned. More...
 
size_t padding (size_t size, size_t alignment)
 Calculate padding required for given alignment. More...
 
void print_backtrace ()
 Print backtrace to stderr. More...
 
void print_emergency_backtrace ()
 Print backtrace to stderr (emergency mode). More...
 
void print_emergency_message (const char *str)
 Print message to stderr (emergency mode). More...
 
const char * demangle (const char *mangled, char *&demangled_buf, size_t &demangled_size)
 Demangle symbol name. More...
 
template<class T1 , class T2 >
bool operator== (const SharedPtr< T1 > &a, const SharedPtr< T2 > &b)
 Equality check. More...
 
bool colors_available ()
 Check if current stderr is connected to a tty. More...
 
bool format_colored (LogLevel level, const char *str, char *buf, size_t bufsz)
 Fill colored str into buf according to the log level. More...
 
void crash (const char *message) ROC_ATTR_NORETURN
 Report a crash and abort application. More...
 
uint16_t ntoh16 (uint16_t v)
 Network to host (16 bits). More...
 
uint32_t ntoh32 (uint32_t v)
 Network to host (32 bits). More...
 
uint16_t hton16 (uint16_t v)
 Host to network (16 bits). More...
 
uint32_t hton32 (uint32_t v)
 Host to network (32 bits). More...
 
void fast_exit (int code) ROC_ATTR_NORETURN
 Terminate process immediately without calling destructors. More...
 
bool format_time (char *buf, size_t bufsz)
 Retrieve and format current time. More...
 
unsigned random (unsigned upper)
 Get random integer. More...
 
unsigned random (unsigned from, unsigned to)
 Get random integer. More...
 
void panic (const char *module, const char *file, int line, const char *format,...) ROC_ATTR_NORETURN ROC_ATTR_PRINTF(4
 Print error message and terminate program gracefully. More...
 
bool parse_duration (const char *string, nanoseconds_t &result)
 Parse duration from string. More...
 
void print_buffer (const uint8_t *data, size_t size)
 Print bytes buffer. More...
 
void print_buffer (const float *data, size_t size)
 Print floats buffer. More...
 
void print_buffer_slice (const uint8_t *inner, size_t inner_size, const uint8_t *outer, size_t outer_size)
 Print a slice of bytes buffer. More...
 
void print_buffer_slice (const float *inner, size_t inner_size, const float *outer, size_t outer_size)
 Print a slice of floats buffer. More...
 
nanoseconds_t timestamp ()
 Get current timestamp in nanoseconds. More...
 
void sleep_until (nanoseconds_t timestamp)
 Sleep until the specified absolute time point has been reached. More...
 
void sleep_for (nanoseconds_t duration)
 Sleep specified amount of time. More...
 

Variables

const LogLevel DefaultLogLevel = LogError
 Default log level. More...
 
const ColorsMode DefaultColorsMode = ColorsDisabled
 Default colors mode. More...
 
const nanoseconds_t Nanosecond = 1
 One nanosecond represented in nanoseconds. More...
 
const nanoseconds_t Microsecond = 1000 * Nanosecond
 One microsecond represented in nanoseconds. More...
 
const nanoseconds_t Millisecond = 1000 * Microsecond
 One millisecond represented in nanoseconds. More...
 
const nanoseconds_t Second = 1000 * Millisecond
 One second represented in nanoseconds. More...
 
const nanoseconds_t Minute = 60 * Second
 One minute represented in nanoseconds. More...
 
const nanoseconds_t Hour = 60 * Minute
 One hour represented in nanoseconds. More...
 

Detailed Description

Basic building blocks.

Typedef Documentation

typedef void(* roc::core::LogHandler) (LogLevel level, const char *module, const char *message)

Log handler.

Definition at line 54 of file log.h.

typedef int64_t roc::core::nanoseconds_t

Nanoseconds.

Definition at line 21 of file time.h.

Enumeration Type Documentation

Colors mode.

Enumerator
ColorsDisabled 

Do not use colored logs.

ColorsEnabled 

Use colored logs.

Definition at line 45 of file log.h.

Function Documentation

bool roc::core::colors_available ( )

Check if current stderr is connected to a tty.

void roc::core::crash ( const char *  message)

Report a crash and abort application.

const char* roc::core::demangle ( const char *  mangled,
char *&  demangled_buf,
size_t &  demangled_size 
)

Demangle symbol name.

This function is not signal-safe.

Remarks
demangled_buf and demangled_size specify the buffer for demangled name. When necessary, this function malloc()s or realloc()s demangled_buf and updates demangled_size accrodingly. The buffer may be NULL. The buffer may be resused across several calls. The user should manually free() the buffer when it's not needed anymore.
Returns
demangled symbol or NULL if the symbol can't be demangled.
void roc::core::fast_exit ( int  code)

Terminate process immediately without calling destructors.

bool roc::core::format_colored ( LogLevel  level,
const char *  str,
char *  buf,
size_t  bufsz 
)

Fill colored str into buf according to the log level.

bool roc::core::format_time ( char *  buf,
size_t  bufsz 
)

Retrieve and format current time.

Remarks
The time is printed in the format "13:10:05.123".
Returns
false if an error occured or buffer is too small.
Note
This function should not log anything because it is used in the logger implementation.
uint16_t roc::core::hton16 ( uint16_t  v)
inline

Host to network (16 bits).

Definition at line 34 of file endian.h.

uint32_t roc::core::hton32 ( uint32_t  v)
inline

Host to network (32 bits).

Definition at line 39 of file endian.h.

size_t roc::core::max_align ( size_t  sz)
inline

Adjust the given size to be maximum aligned.

Definition at line 27 of file alignment.h.

uint16_t roc::core::ntoh16 ( uint16_t  v)
inline

Network to host (16 bits).

Definition at line 24 of file endian.h.

uint32_t roc::core::ntoh32 ( uint32_t  v)
inline

Network to host (32 bits).

Definition at line 29 of file endian.h.

template<class T1 , class T2 >
bool roc::core::operator== ( const SharedPtr< T1 > &  a,
const SharedPtr< T2 > &  b 
)
inline

Equality check.

Definition at line 124 of file shared_ptr.h.

size_t roc::core::padding ( size_t  size,
size_t  alignment 
)
inline

Calculate padding required for given alignment.

Definition at line 36 of file alignment.h.

void roc::core::panic ( const char *  module,
const char *  file,
int  line,
const char *  format,
  ... 
)

Print error message and terminate program gracefully.

bool roc::core::parse_duration ( const char *  string,
nanoseconds_t result 
)

Parse duration from string.

Remarks
The input string should be in one of the following forms:
  • "<number>ns"
  • "<number>us"
  • "<number>ms"
  • "<number>s"
  • "<number>m"
  • "<number>h"
Returns
false if string can't be parsed.
void roc::core::print_backtrace ( )

Print backtrace to stderr.

Remarks
This function is not signal-safe. It can use heap and stdio.
void roc::core::print_buffer ( const uint8_t *  data,
size_t  size 
)

Print bytes buffer.

void roc::core::print_buffer ( const float *  data,
size_t  size 
)

Print floats buffer.

void roc::core::print_buffer_slice ( const uint8_t *  inner,
size_t  inner_size,
const uint8_t *  outer,
size_t  outer_size 
)

Print a slice of bytes buffer.

void roc::core::print_buffer_slice ( const float *  inner,
size_t  inner_size,
const float *  outer,
size_t  outer_size 
)

Print a slice of floats buffer.

void roc::core::print_emergency_backtrace ( )

Print backtrace to stderr (emergency mode).

Remarks
This function is signal-safe. It can't use heap and stdio.
void roc::core::print_emergency_message ( const char *  str)

Print message to stderr (emergency mode).

Remarks
This function is signal-safe. It can't use heap and stdio.
unsigned roc::core::random ( unsigned  upper)

Get random integer.

Returns
random value in range [0; upper).
unsigned roc::core::random ( unsigned  from,
unsigned  to 
)

Get random integer.

Returns
random value in range [from; to].
void roc::core::sleep_for ( nanoseconds_t  duration)

Sleep specified amount of time.

Remarks
duration specifies number of nanoseconds to sleep.
void roc::core::sleep_until ( nanoseconds_t  timestamp)

Sleep until the specified absolute time point has been reached.

Remarks
timestamp specifies absolute time point in nanoseconds.
nanoseconds_t roc::core::timestamp ( )

Get current timestamp in nanoseconds.

Variable Documentation

const ColorsMode roc::core::DefaultColorsMode = ColorsDisabled

Default colors mode.

Definition at line 51 of file log.h.

const LogLevel roc::core::DefaultLogLevel = LogError

Default log level.

Definition at line 42 of file log.h.

const nanoseconds_t roc::core::Hour = 60 * Minute

One hour represented in nanoseconds.

Definition at line 39 of file time.h.

const nanoseconds_t roc::core::Microsecond = 1000 * Nanosecond

One microsecond represented in nanoseconds.

Definition at line 27 of file time.h.

const nanoseconds_t roc::core::Millisecond = 1000 * Microsecond

One millisecond represented in nanoseconds.

Definition at line 30 of file time.h.

const nanoseconds_t roc::core::Minute = 60 * Second

One minute represented in nanoseconds.

Definition at line 36 of file time.h.

const nanoseconds_t roc::core::Nanosecond = 1

One nanosecond represented in nanoseconds.

Definition at line 24 of file time.h.

const nanoseconds_t roc::core::Second = 1000 * Millisecond

One second represented in nanoseconds.

Definition at line 33 of file time.h.