CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
Utils.h File Reference

Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory, processes, sockets, files, strings, conversions and randomness. More...

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdarg.h>
#include <iomanip>
#include "Types.h"
#include "Base64.h"
#include <semaphore.h>
#include <dlfcn.h>
#include <errno.h>
#include <sys/utsname.h>
#include <sys/time.h>
#include <pthread.h>
#include <signal.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/sysinfo.h>
#include <sys/socket.h>
#include <netdb.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <dirent.h>
#include <netinet/tcp.h>
#include <sys/wait.h>
#include <execinfo.h>
#include <sys/resource.h>
#include <limits>
#include "PsyTime.h"
Include dependency graph for Utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  cmlabs::CleanShutdown
 RAII guard whose single static instance triggers global utility cleanup at program exit. More...
struct  cmlabs::LogEntry
 Wire/storage layout of one log record: fixed header immediately followed by the message text. More...
class  cmlabs::LogReceiver
 Callback interface for receiving log entries produced through LogSystem. More...
class  cmlabs::LogSystem
 Process-wide singleton logging hub with per-topic verbosity/debug levels. More...
struct  cmlabs::utils::DrumBeatInfo
 Bookkeeping record for one periodic "drum beat" timer. More...
class  cmlabs::utils::Mutex
 Recursive mutual-exclusion lock, optionally named for cross-process use. More...
class  cmlabs::utils::Semaphore
 Counting semaphore, optionally named for cross-process use. More...
class  cmlabs::utils::Event
 Auto-reset notification event (condition variable style), optionally named for cross-process use. More...
struct  cmlabs::utils::TimerSchedule
 One scheduled entry inside a Timer: id, active window and platform timer handle. More...
struct  cmlabs::utils::TimerTrigger
 A single timer expiry: which timer fired and when. More...
class  cmlabs::utils::Timer
 Multiplexing timer: schedule many periodic timers and consume their expiries from one queue. More...
class  cmlabs::utils::WaitQueue< T >
 Thread-safe FIFO queue with blocking waits, the workhorse producer/consumer channel in CMSDK. More...
class  cmlabs::utils::WaitQueuePointer< T >
 WaitQueue specialization for owned heap pointers: clear()/destructor delete remaining entries. More...
struct  cmlabs::utils::TimeQueueEntry< T >
 One (time, entry) pair inside a TimeQueue. More...
class  cmlabs::utils::TimeQueue< T >
 Thread-safe queue of entries ordered by due time; entries become retrievable once their timestamp passes. More...
class  cmlabs::utils::TimeQueuePointer< T >
 TimeQueue specialization for owned heap pointers: clear()/destructor delete remaining entries. More...
class  cmlabs::utils::CommandLineInfo
 Singleton snapshot of the parsed process command line (set via SetCommandLine()). More...
class  cmlabs::utils::Library
 Thin RAII wrapper around a dynamically loaded library (LoadLibrary / dlopen). More...
struct  cmlabs::utils::NetworkInterfaces
 Description of one local network interface (IPv4 address, MAC and names). More...
struct  cmlabs::utils::FileDetails
 Existence, type, permission and timestamp information for one file, as returned by GetFileDetails(). More...

Namespaces

namespace  cmlabs
namespace  cmlabs::utils

Macros

#define GetCurrentDirEx   getcwd
#define WINSHMEMSPACE   "Local"
#define MAXKEYNAMELEN   256
#define MAXVALUENAMELEN   1024
#define MAXCONTENTLEN   4196
#define MAXCOMMANDLINELEN   1024
#define MAXFILENAMELEN   256
#define MAXSHMEMNAMELEN   1024
#define MAXSCRIPTLEN   10*1024
#define THREAD_NONE   0
#define THREAD_TERMINATED   1
#define THREAD_INIT   2
#define THREAD_RUNNING   3
#define THREAD_PAUSED   4
#define THREAD_INTERRUPTED   5
#define THREAD_STATS_OFF   0
#define THREAD_STATS_AUTO   1
#define THREAD_STATS_ADHOC   2
#define ThreadHandle   pthread_t
#define THREAD_RET   void *
#define THREAD_FUNCTION_CALL
#define THREAD_ARG   void*
#define thread_ret_val(ret)
#define stricmp   strcasecmp
#define MUTEX_INVALID   0
#define SOCKET   int
#define SOCKET_ERROR   -1
#define INVALID_SOCKET   -1
#define closesocket(X)
#define SOCKETWOULDBLOCK   EINPROGRESS
#define SOCKETTRYAGAIN   EAGAIN
#define abs64   llabs
#define MUTEXMEMSIZE   64
#define EVENTMEMSIZE   256
#define SEMAPHOREMEMSIZE   256
#define _strcmpi   strcasecmp
#define _strnicmp   strnicmp
#define DllExport
#define SD_BOTH   2
#define OSCPU_UNKNOWN   0
#define OSCPU_X86   1
#define OSCPU_AMD64   2
#define OSCPU_IA64   3
#define ERROR64   0xFFFFFFFFFFFFFFFFL
#define ERROR32   0xFFFFFFFF
#define ERROR16   0xFFFF
#define ERROR8   0xFF
#define LOG_NOTOPIC   0
#define LOG_SYSTEM   1
#define LOG_NETWORK   2
#define LOG_MEMORY   3
#define LOG_PROCESS   4
#define LOG_TOPIC5   5
#define LOG_TOPIC6   6
#define LOG_TOPIC7   7
#define LOG_TOPIC8   8
#define LOG_TOPIC9   9
#define LOG_TOPIC10   10
#define LOG_TOPIC11   11
#define LOG_MAXCOUNT   12
#define LOGPRINT   1
#define LOGDEBUG   2
#define LogPrint   LogSystem::LogSystemPrint
#define LogDebug   LogSystem::LogSystemDebug
#define SharedMemoryFileHandleMapType   std::map<void*, std::string>
#define PROC_ERROR   0
#define PROC_TERMINATED   1
#define PROC_NOTSTARTED   2
#define PROC_RUNNING   3
#define PROC_TIMEOUT   4
#define NUM_PIPES   2
#define PARENT_WRITE_PIPE   0
#define PARENT_READ_PIPE   1
#define READ_FD   0
#define WRITE_FD   1
#define PARENT_READ_FD   ( (*pipes)[PARENT_READ_PIPE][READ_FD] )
#define PARENT_WRITE_FD   ( (*pipes)[PARENT_WRITE_PIPE][WRITE_FD] )
#define CHILD_READ_FD   ( (*pipes)[PARENT_WRITE_PIPE][READ_FD] )
#define CHILD_WRITE_FD   ( (*pipes)[PARENT_READ_PIPE][WRITE_FD] )
#define PROCBUFSIZE   4096
#define DLLHandle   void*

Typedefs

typedef THREAD_RET(* THREAD_FUNCTION) (void *)
typedef struct sockaddr SOCKADDR
typedef std::pair< std::string, Mutex * > cmlabs::utils::SharedMemoryMutexMapPair
typedef std::pair< std::string, Semaphore * > cmlabs::utils::SharedMemorySemaphoreMapPair
typedef std::pair< std::string, Event * > cmlabs::utils::SharedMemoryEventMapPair

Functions

bool cmlabs::ClearUtilsMaps ()
 Free all lazily-allocated global registries (mutex/semaphore/event/shared-memory maps).
std::string cmlabs::GetDataTypeName (uint32 datatype)
 Translate a CMSDK datatype id (e.g.
uint32 cmlabs::GetDataTypeID (const char *typeName)
 Inverse of GetDataTypeName(): look up the numeric datatype id for a type name.
C-string helpers

Low-level, allocation-free operations on raw char buffers.

bool cmlabs::utils::UtilsTest ()
 Run the built-in self test of the utils module.
void cmlabs::utils::PrintBinary (void *p, uint32 size, bool asInt, const char *title)
 Hex/decimal dump a memory region to stdout for debugging.
const char * cmlabs::utils::stristr (const char *str, const char *substr, uint32 len=0)
 Case-insensitive strstr.
bool cmlabs::utils::GetNextLineEnd (const char *str, uint32 size, uint32 &len, uint32 &crSize)
 Find the end of the current line.
uint32 cmlabs::utils::TextReplaceCharsInPlace (char *str, uint32 size, char find, char replace)
 Replace every occurrence of a character, in place.
bool cmlabs::utils::TextEndsWith (const char *str, const char *end, bool caseSensitive=true)
 Test whether str ends with end.
bool cmlabs::utils::TextStartsWith (const char *str, const char *start, bool caseSensitive=true)
 Test whether str starts with start.
uint32 cmlabs::utils::strcpyavail (char *dst, const char *src, uint32 maxlen, bool copyAvailable)
 Bounded strcpy that always NUL-terminates.
const char * cmlabs::utils::laststrstr (const char *str1, const char *str2)
 Find the last occurrence of str2 in str1.
const char * cmlabs::utils::laststristr (const char *str1, const char *str2)
 Case-insensitive laststrstr().
Timers and queues
static void cmlabs::utils::TimerCallback (int sig, siginfo_t *siginfo, void *context)
 POSIX signal-based timer callback trampoline (SIGEV_SIGNAL); routes the expiry into the owning Timer's trigger queue.
bool cmlabs::utils::UnitTest_Timer ()
 Self test for the Timer class.
bool cmlabs::utils::UnitTest_Utils ()
 Aggregate self test for miscellaneous utils functionality.
Shared memory

Named segments are implemented with CreateFileMapping on Windows and shm_open/mmap on POSIX; names are prefixed with the shared system instance so independent CMSDK deployments do not collide.

char * cmlabs::utils::CreateSharedMemorySegment (const char *name, uint64 size, bool force=false)
 Create a named shared memory segment and map it into this process.
char * cmlabs::utils::OpenSharedMemorySegment (const char *name, uint64 size)
 Open and map an existing named shared memory segment.
bool cmlabs::utils::CloseSharedMemorySegment (char *data, uint64 size)
 Unmap a segment previously created/opened here.
Bit field operations

Helpers for compact allocation bitmaps (used e.g.

by the shared-memory block allocators). Bit 0 is the least significant bit of the first byte.

uint64 cmlabs::utils::ntoh64 (const uint64 *input)
 Convert a 64-bit value from network to host byte order.
uint64 cmlabs::utils::hton64 (const uint64_t *input)
 Convert a 64-bit value from host to network byte order.
uint32 cmlabs::utils::Calc32BitFieldSize (uint32 bitsize)
 Compute the byte size needed for a bitfield of bitsize bits, rounded up to a 32-bit boundary.
bool cmlabs::utils::Reset32BitField (char *bitfield, uint32 bytesize)
 Zero the whole bitfield, marking every bit as free.
bool cmlabs::utils::GetFirstFreeBitLoc (const char *bitfield, uint32 bytesize, uint32 &loc)
 Find the first 0 (free) bit.
bool cmlabs::utils::GetFirstFreeBitLocN (const char *bitfield, uint32 bytesize, uint32 num, uint32 &loc)
 Find the first run of num consecutive 0 bits.
bool cmlabs::utils::SetBit (uint32 loc, bit value, char *bitfield, uint32 bytesize)
 Set bit loc to value.
bool cmlabs::utils::SetBitN (uint32 loc, uint32 num, bit value, char *bitfield, uint32 bytesize)
 Set num consecutive bits starting at loc to value.
bool cmlabs::utils::GetBit (uint32 loc, const char *bitfield, uint32 bytesize, bit &val)
 Read bit loc.
bool cmlabs::utils::GetLastOccupiedBitLoc (const char *bitfield, uint32 bytesize, uint32 &loc)
 Find the highest set (occupied) bit.
std::string cmlabs::utils::GetBitFieldAsString (const char *bitfield, uint32 bytesize, uint32 size)
 Render the first size bits as a '0'/'1' string, for debugging.
std::string cmlabs::utils::PrintBitFieldString (const char *bitfield, uint32 bytesize, uint32 size, const char *title)
 Like GetBitFieldAsString() but prefixed with title and formatted for printing.
Threading and CPU statistics
std::string cmlabs::utils::PrintProgramTrace (uint32 startLine=0, uint32 endLine=0)
 Format the current call stack as printable text.
std::list< std::string > cmlabs::utils::GetProgramTrace ()
 Capture the current call stack.
int32 cmlabs::utils::AtomicIncrement32 (int32 volatile &v)
 Atomically increment a 32-bit value.
int64 cmlabs::utils::AtomicIncrement64 (int64 volatile &v)
 Atomically increment a 64-bit value.
int32 cmlabs::utils::AtomicDecrement32 (int32 volatile &v)
 Atomically decrement a 32-bit value.
int64 cmlabs::utils::AtomicDecrement64 (int64 volatile &v)
 Atomically decrement a 64-bit value.
bool cmlabs::utils::Sleep (uint32 ms)
 Suspend the calling thread.
bool cmlabs::utils::CreateThread (THREAD_FUNCTION func, void *args, ThreadHandle &thread, uint32 &osID)
 Start a new OS thread.
bool cmlabs::utils::WaitForThreadToFinish (ThreadHandle hThread, uint32 timeoutMS=0)
 Join a thread.
bool cmlabs::utils::CheckForThreadFinished (ThreadHandle hThread)
 Non-blocking check whether a thread has terminated.
bool cmlabs::utils::TerminateThread (ThreadHandle hThread)
 Forcibly kill a thread.
bool cmlabs::utils::PauseThread (ThreadHandle hThread)
 Suspend a thread's execution.
bool cmlabs::utils::ContinueThread (ThreadHandle hThread)
 Resume a thread paused with PauseThread().
bool cmlabs::utils::GetCurrentThreadUniqueID (uint32 &tid)
 Get a process-unique id for the calling thread.
bool cmlabs::utils::GetCurrentThreadOSID (uint32 &tid)
 Get the OS-level id of the calling thread (gettid / GetCurrentThreadId).
bool cmlabs::utils::GetCurrentThread (ThreadHandle &thread)
 Get the handle of the calling thread.
bool cmlabs::utils::IsThreadRunning (ThreadHandle hThread)
 Check whether a thread is still alive.
uint32 cmlabs::utils::GetThreadStatColAbility ()
 Report this platform's capability for per-thread CPU statistics collection.
bool cmlabs::utils::GetCPUTicks (ThreadHandle hThread, uint64 &ticks)
 Get accumulated CPU time of a specific thread.
bool cmlabs::utils::GetCPUTicks (uint64 &ticks)
 Get accumulated CPU time of the calling thread.
bool cmlabs::utils::GetProcessCPUTicks (uint64 &ticks)
 Get accumulated CPU time of the current process.
bool cmlabs::utils::GetProcessCPUTicks (uint32 osProcID, uint64 &ticks)
 Get accumulated CPU time of another process.
bool cmlabs::utils::GetProcAndOSCPUUsage (double &procPercentUse, double &osPercentUse, uint64 &prevOSTicks, uint64 &prevOSIdleTicks, uint64 &prevProcTicks)
 Sample CPU usage of this process and of the whole OS since the previous call.
bool cmlabs::utils::GetProcAndOSCPUUsage (uint32 osProcID, double &procPercentUse, double &osPercentUse, uint64 &prevOSTicks, uint64 &prevOSIdleTicks, uint64 &prevProcTicks)
 As GetProcAndOSCPUUsage() above, but for an arbitrary process.
bool cmlabs::utils::GetOSCPUUsage (double &percentUse)
 Get the instantaneous total OS CPU usage.
bool cmlabs::utils::GetThreadPriority (ThreadHandle hThread, uint16 priority)
 Query a thread's scheduling priority.
bool cmlabs::utils::SetThreadPriority (ThreadHandle hThread, uint16 priority)
 Set a thread's scheduling priority.
int cmlabs::utils::ToOSPriority (int pri)
 Map a CMSDK priority value to the platform's native priority scale.
int cmlabs::utils::FromOSPriority (int pri)
 Map a native OS priority back to the CMSDK priority scale.
bool cmlabs::utils::SignalThread (ThreadHandle hThread, int32 signal)
 Send a signal to a thread (POSIX pthread_kill; limited emulation on Windows).
Desktop and console
bool cmlabs::utils::GetDesktopSize (uint32 &width, uint32 &height)
 Get the primary desktop resolution.
bool cmlabs::utils::RenameConsoleWindow (const char *name, bool prepend=false)
 Set the console window title.
bool cmlabs::utils::MoveConsoleWindow (int32 x=-1, int32 y=-1, int32 w=-1, int32 h=-1)
 Move/resize the console window.
Process management
int cmlabs::utils::RunOSCommand (const char *cmdline, const char *initdir, uint32 timeout, std::string &stdoutString, std::string &stderrString)
 Run a command synchronously and capture its output.
uint32 cmlabs::utils::NewProcess (const char *cmdline, const char *initdir=NULL, const char *title=NULL, int16 x=-1, int16 y=-1, int16 w=-1, int16 h=-1)
 Launch a detached child process.
uint8 cmlabs::utils::GetProcessStatus (uint32 proc, int &returncode)
 Poll a child started with NewProcess().
bool cmlabs::utils::EndProcess (uint32 proc)
 Forcibly terminate a child process.
uint8 cmlabs::utils::WaitForProcess (uint32 proc, uint32 timeout, int &returncode)
 Wait for a child to exit.
uint32 cmlabs::utils::GetLocalProcessID ()
 Get the OS process id of the current process.
OS and hardware information
const char * cmlabs::utils::GetComputerName ()
 Get this machine's hostname.
uint64 cmlabs::utils::GetProcessMemoryUsage ()
 Current resident memory usage of this process.
uint64 cmlabs::utils::GetPeakProcessMemoryUsage ()
 Peak resident memory usage of this process.
uint16 cmlabs::utils::GetCPUCount ()
 Number of logical CPU cores.
uint16 cmlabs::utils::GetCPUArchitecture ()
 CPU architecture id.
uint64 cmlabs::utils::GetCPUSpeed ()
 Nominal CPU clock speed.
uint64 cmlabs::utils::GetSystemMemorySize ()
 Total physical RAM installed.
bool cmlabs::utils::GetSystemMemoryUsage (uint64 &totalRAM, uint64 &freeRAM)
 Query total and free physical memory.
const char * cmlabs::utils::GetSystemArchitecture ()
 Architecture name string, e.g.
const char * cmlabs::utils::GetSystemOSName ()
 OS name string, e.g.
bool cmlabs::utils::GetSystemOSVersion (uint16 &major, uint16 &minor, uint16 &build, char *text, uint16 textSize)
 Detailed OS version.
Registry access (Windows; no-ops/defaults elsewhere)

Keys are given as full paths, e.g.

"HKEY_LOCAL_MACHINE\\Software\\...". On non-Windows platforms these functions return failure/empty values.

uint32 cmlabs::utils::ReadRegistryDWORD (const char *key, const char *entry)
 Read a 32-bit registry value.
uint64 cmlabs::utils::ReadRegistryQWORD (const char *key, const char *entry)
 Read a 64-bit registry value.
std::string cmlabs::utils::ReadRegistryString (const char *key, const char *entry)
 Read a string registry value.
bool cmlabs::utils::WriteRegistryDWORD (const char *key, const char *entry, uint32 value)
 Write a 32-bit registry value (creates the key when needed).
bool cmlabs::utils::WriteRegistryQWORD (const char *key, const char *entry, uint64 value)
 Write a 64-bit registry value.
bool cmlabs::utils::WriteRegistryString (const char *key, const char *entry, const char *value)
 Write a string registry value.
bool cmlabs::utils::DeleteRegistryEntry (const char *key, const char *entry)
 Delete a single value from a key.
bool cmlabs::utils::DeleteRegistryKey (const char *key)
 Delete a (leaf) registry key.
bool cmlabs::utils::DeleteRegistryTree (const char *root, const char *key)
 Recursively delete a key and all subkeys.
bool cmlabs::utils::CopyRegistryTree (const char *entry, const char *newName)
 Recursively copy a registry subtree.
String replacement and templating
uint32 cmlabs::utils::StringSingleReplace (std::string &text, std::string key, std::string value, bool onlyFirst)
 Replace occurrences of key with value in text.
uint32 cmlabs::utils::StringMultiReplace (std::string &text, std::map< std::string, std::string > &map, bool onlyFirst)
 Apply many key→value replacements in one pass.
uint32 cmlabs::utils::StringScriptReplace (std::string &text, std::string name, std::list< std::map< std::string, std::string > > &list)
 Expand a named repeating template block in text once per map in list, substituting each map's keys inside the block.
Text case, trimming, splitting and joining

All functions return new std::string values and leave inputs untouched.

NULL inputs are treated as empty strings unless noted.

std::string cmlabs::utils::TextCapitalise (const char *text)
 Capitalise the first letter of text.
std::string cmlabs::utils::TextUppercase (const char *text)
 Convert to upper case (ASCII/current locale).
std::string cmlabs::utils::TextLowercase (const char *text)
 Convert to lower case (ASCII/current locale).
std::string cmlabs::utils::TextIndent (const char *text, const char *indent)
 Prefix every line of text with indent.
std::string cmlabs::utils::TextUnindent (const char *text)
 Remove one level of leading indentation from every line.
std::string cmlabs::utils::TextTrimQuotes (const char *text)
 Strip a single pair of surrounding quotes if present.
std::string cmlabs::utils::TextTrim (const char *text)
 Strip leading and trailing whitespace.
std::multimap< std::string, std::string > cmlabs::utils::TextMultiMapSplit (const char *text, const char *outersplit, const char *innersplit)
 Split "k=v<sep>k=v..." text into a multimap (duplicate keys preserved).
std::map< std::string, std::string > cmlabs::utils::TextMapSplit (const char *text, const char *outersplit, const char *innersplit)
 Split "k=v<sep>k=v..." text into a map (later duplicates overwrite earlier ones).
std::string cmlabs::utils::TextJoin (std::vector< std::string > &list, const char *split, uint32 start=0, uint32 count=0)
 Join vector elements with split.
std::string cmlabs::utils::TextJoin (std::list< std::string > &list, const char *split, uint32 start=0, uint32 count=0)
 Join list elements with split.
std::string cmlabs::utils::TextJoin (std::map< std::string, std::string > &map, const char *innersplit, const char *outersplit, bool keyquotes, bool valquotes)
 Join a map as "key<innersplit>value<outersplit>..." with optional quoting.
std::string cmlabs::utils::TextJoinJSON (std::map< std::string, std::string > &map)
 Serialize a map as a JSON object (keys/values escaped).
std::string cmlabs::utils::TextJoinXML (std::map< std::string, std::string > &map, const char *innernodeName, const char *outernodeName)
 Serialize a map as XML, one innernodeName element per pair inside an outernodeName element.
std::vector< std::string > cmlabs::utils::TextListSplit (const char *text, const char *split, bool keepEmpty=true, bool autoTrim=false)
 Split text on a separator.
std::vector< std::string > cmlabs::utils::TextListSplitLines (const char *text, bool keepEmpty=true, bool autoTrim=false)
 Split text into lines, handling both \n and \r\n.
std::vector< std::string > cmlabs::utils::TextListBreakLines (const char *text, uint32 maxLineLength=80)
 Word-wrap text into lines no longer than maxLineLength.
std::string cmlabs::utils::TextListBreakLines (const char *text, uint32 maxLineLength, const char *breakstr)
 Word-wrap text, joining the wrapped lines with breakstr.
std::string cmlabs::utils::TextVectorConcat (std::vector< std::string >, const char *sep, bool allowEmpty=true)
 Concatenate vector entries with sep.
std::vector< std::string > cmlabs::utils::TextCommandlineSplit (const char *cmdline)
 Split a command line into arguments, honouring quoting rules.
char ** cmlabs::utils::SplitCommandline (const char *cmdline, int &argc)
 Split a command line into a malloc'ed argv array.
wchar_t ** cmlabs::utils::SplitCommandlineW (const char *cmdline, int &argc)
 Wide-character variant of SplitCommandline() (for Windows APIs).
bool cmlabs::utils::DeleteCommandline (char **argv, int argc)
 Free an argv array produced by SplitCommandline().
printf-style string formatting
std::string cmlabs::utils::StringFormat (const char *format,...)
 printf into a std::string.
char * cmlabs::utils::StringFormat (uint32 &size, const char *format,...)
 printf into a freshly allocated buffer.
bool cmlabs::utils::StringFormatInto (char *dst, uint32 maxsize, const char *format,...)
 printf into a caller-supplied buffer with truncation.
char * cmlabs::utils::StringFormatVA (uint32 &size, const char *format, va_list args)
 va_list core used by the other StringFormat overloads.
Numeric conversion and checksums
unsigned char cmlabs::utils::Hex2Char (const char *str)
 Parse two hex digits into a byte.
unsigned char cmlabs::utils::Dec2Char (const char *str)
 Parse up to three decimal digits into a byte.
int cmlabs::utils::CRC32 (const char *addr, uint32 length, int32 crc=0)
 Compute (or continue) a CRC-32 checksum.
int8 cmlabs::utils::CompareFloats (float64 a, float64 b)
 Compare two doubles with epsilon tolerance.
ASCII ↔ number conversion

The Ascii2* parsers operate on a substring [start,end) of the input; end=0 means "until NUL".

They skip surrounding whitespace and never throw.

Note
Common behaviour of the Ascii2Int64/Uint64/Int32/Uint32/Float64 family: NULL input, start>end or entirely non-numeric text all yield 0, which is indistinguishable from a legitimate parsed zero — call IsTextNumeric() first when validity matters. Parsing is strtoll/strtod based, so leading whitespace is skipped, parsing stops at the first non-numeric character, and out-of-range values saturate to the type's min/max without an error indication. When end!=0 a temporary substring copy is allocated internally; the end=0 form is allocation-free. Ascii2Float64 always parses with '.' as the decimal point regardless of the process locale.
char * cmlabs::utils::Int2Ascii (int64 value, char *result, uint16 size, uint8 base)
 Render a signed integer as text in an arbitrary base.
char * cmlabs::utils::Uint2Ascii (uint64 value, char *result, uint16 size, uint8 base)
 Render an unsigned integer as text in an arbitrary base.
unsigned char * cmlabs::utils::Ascii2UTF16LE (const char *ascii, uint32 len, uint32 &size)
 Convert 8-bit ASCII text to UTF-16LE (used for Windows wide APIs and some protocols).
bool cmlabs::utils::IsTextNumeric (const char *ascii, uint32 start=0, uint32 end=0)
 Test whether a (sub)string is a valid number.
int64 cmlabs::utils::Ascii2Int64 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse a signed 64-bit decimal integer from a substring.
uint64 cmlabs::utils::Ascii2Uint64 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse an unsigned 64-bit decimal integer from a substring.
uint64 cmlabs::utils::AsciiHex2Uint64 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse an unsigned 64-bit hexadecimal integer (with or without 0x) from a substring.
int32 cmlabs::utils::Ascii2Int32 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse a signed 32-bit decimal integer from a substring.
uint32 cmlabs::utils::Ascii2Uint32 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse an unsigned 32-bit decimal integer from a substring.
uint32 cmlabs::utils::AsciiHex2Uint32 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse an unsigned 32-bit hexadecimal integer from a substring.
float64 cmlabs::utils::Ascii2Float64 (const char *ascii, uint32 start=0, uint32 end=0)
 Parse a 64-bit float from a substring (decimal point, not locale dependent).
char * cmlabs::utils::TextSubstringCopy (const char *ascii, uint32 start, uint32 end)
 Copy the substring [start,end) into a new NUL-terminated buffer.
std::string cmlabs::utils::DecodeJSON (std::string str)
 Unescape a JSON string value (\" \\ \n \t \uXXXX etc.).
std::string cmlabs::utils::EncodeJSON (std::string str)
 Escape text for embedding as a JSON string value.
Random numbers and human-readable sizes
bool cmlabs::utils::SeedRandomValues (uint32 seedvalue=0)
 Seed the pseudo-random generator.
double cmlabs::utils::RandomValue ()
 Uniform random double in [0,1).
double cmlabs::utils::RandomValue (double to)
 Uniform random double in [0,to).
double cmlabs::utils::RandomValue (double from, double to)
 Uniform random double in [from,to).
double cmlabs::utils::RandomValue (double from, double to, double interval)
 Uniform random double in [from,to) quantized to multiples of interval.
int64 cmlabs::utils::RandomInt (int64 from=0, int64 to=100)
 Uniform random integer in [from,to].
std::string cmlabs::utils::BytifySize (double val)
 Format a byte count with binary units, e.g.
std::string cmlabs::utils::BytifySizes (double val1, double val2)
 Format two byte counts as "x / y" with matching units.
std::string cmlabs::utils::BytifyRate (double val)
 Format a byte rate, e.g.
std::string cmlabs::utils::BytifyRates (double val1, double val2)
 Format two byte rates as "x / y" with matching units.

Variables

static SharedMemoryFileHandleMapTypecmlabs::utils::SharedMemoryFileHandleMap = NULL
static uint16 cmlabs::utils::SharedSystemInstance = 0
static Mutexcmlabs::utils::SharedMemoryMutexMapMutex = NULL
static std::map< std::string, Mutex * > * cmlabs::utils::SharedMemoryMutexMap = NULL
static Mutexcmlabs::utils::SharedMemorySemaphoreMapMutex = NULL
static std::map< std::string, Semaphore * > * cmlabs::utils::SharedMemorySemaphoreMap = NULL
static Mutexcmlabs::utils::SharedMemoryEventMapMutex = NULL
static std::map< std::string, Event * > * cmlabs::utils::SharedMemoryEventMap = NULL

Sockets and networking

Thin portability layer over BSD sockets / Winsock.

On non-Windows builds SOCKET is a plain int and closesocket() maps to close(); CHECKNETWORKINIT expands to a Winsock WSAStartup guard on Windows and to nothing elsewhere.

#define CHECKNETWORKINIT
#define WSAEWOULDBLOCK   EAGAIN
#define LOCALHOSTIP   16777343
#define MALLOC(x)
#define FREE(x)
#define GETIPPORT(a)
#define GETIPADDRESS(a)
#define GETIPADDRESSPORT(a, p)
#define GETIPADDRESSQUAD(a)
#define GETIPADDRESSQUADPORT(a)
bool cmlabs::utils::GetSocketError (int wsaError, char *errorString, uint16 errorStringMaxSize, bool *isRecoverable)
 Translate a socket error code into text and classify it.
int cmlabs::utils::GetLastOSErrorNumber ()
 Get the last OS error number (errno / GetLastError()).
std::string cmlabs::utils::GetLastOSErrorMessage ()
 Get the last OS error as human-readable text.
bool cmlabs::utils::WaitForSocketReadability (SOCKET s, int32 timeout)
 Wait until a socket has data to read.
bool cmlabs::utils::WaitForSocketWriteability (SOCKET s, int32 timeout)
 Wait until a socket can be written without blocking.
bool cmlabs::utils::SetSocketNonBlockingMode (SOCKET s)
 Put a socket into non-blocking mode.
bool cmlabs::utils::SetSocketBlockingMode (SOCKET s)
 Put a socket into blocking mode.
bool cmlabs::utils::LookupIPAddress (const char *name, uint32 &address)
 Resolve a hostname to an IPv4 address.
bool cmlabs::utils::LookupHostname (uint32 address, char *name, uint32 maxSize)
 Reverse-resolve an IPv4 address to a hostname.
std::string cmlabs::utils::GetLocalHostnameString ()
 Local hostname as std::string.
bool cmlabs::utils::GetLocalHostname (char *name, uint32 maxSize)
 Local hostname into a caller buffer.
bool cmlabs::utils::IsLocalIPAddress (const char *addr)
 Test whether a textual address refers to this machine (loopback or a local interface).
bool cmlabs::utils::IsLocalIPAddress (uint32 &address)
 Test whether a numeric IPv4 address is local.
bool cmlabs::utils::GetLocalIPAddress (uint32 &address)
 Get the primary local IPv4 address.
uint32 * cmlabs::utils::GetLocalIPAddresses (uint32 &count)
 List all local IPv4 addresses.
bool cmlabs::utils::GetLocalMACAddress (uint64 &address)
 Get the primary local MAC address.
uint64 * cmlabs::utils::GetLocalMACAddresses (uint32 &count)
 List all local MAC addresses.
NetworkInterfacescmlabs::utils::GetLocalInterfaces (uint32 &count)
 Enumerate local network interfaces with address, MAC and names.
bool cmlabs::utils::GetNextAvailableLocalPort (uint16 lastPort, uint16 &nextPort)
 Find the next free TCP port above lastPort.

File system

Paths accept the platform's native separator; most functions also tolerate '/' on Windows.

Directory listing uses dirent (via direntwin.h on Windows).

#define NOSUCHFILE   0
#define STANDARDFILE   1
#define STANDARDDIR   2
std::string cmlabs::utils::ReadAFileString (std::string filename)
 Read an entire file into a std::string.
char * cmlabs::utils::ReadAFile (const char *filename, uint32 &length, bool binary=false)
 Read an entire file into a new buffer.
char * cmlabs::utils::ReadAFile (const char *dir, const char *filename, uint32 &length, bool binary=false)
 Read dir/filename into a new buffer; see ReadAFile().
bool cmlabs::utils::WriteAFile (const char *filename, const char *data, uint32 length, bool binary=false)
 Write (create/overwrite) a file.
bool cmlabs::utils::WriteAFile (const char *dir, const char *filename, const char *data, uint32 length, bool binary=false)
 Write dir/filename; see WriteAFile().
bool cmlabs::utils::AppendToAFile (const char *filename, const char *data, uint32 length, bool binary=false)
 Append to a file, creating it if missing.
bool cmlabs::utils::AppendToAFile (const char *dir, const char *filename, const char *data, uint32 length, bool binary=false)
 Append to dir/filename; see AppendToAFile().
char * cmlabs::utils::GetFileList (const char *dirname, const char *ext, uint32 &count, bool fullpath, uint32 maxNameLen=256)
 List files in a directory matching an extension.
FileDetails cmlabs::utils::GetFileDetails (const char *filename)
 Stat a file.
std::string cmlabs::utils::GetFilePath (const char *filename)
 Directory portion of a path.
const char * cmlabs::utils::GetFileBasename (const char *filename)
 Filename portion of a path.
std::string cmlabs::utils::GetCurrentDir ()
 Current working directory.
bool cmlabs::utils::DeleteAFile (const char *filename, bool force)
 Delete a file.
bool cmlabs::utils::DeleteAFile (const char *dir, const char *filename, bool force)
 Delete dir/filename; see DeleteAFile().
bool cmlabs::utils::DeleteADir (const char *dirname, bool force)
 Delete a directory (recursively when force).
bool cmlabs::utils::CreateADir (const char *dirname)
 Create a directory (parents included where supported).
bool cmlabs::utils::DoesADirExist (const char *dirname)
 Test whether a directory exists.
bool cmlabs::utils::DoesAFileExist (const char *filename)
 Test whether a regular file exists.
bool cmlabs::utils::DeleteFilesInADir (const char *dirname, bool force)
 Delete all files inside a directory, leaving the directory itself.
bool cmlabs::utils::ChangeAFileAttr (const char *filename, bool read, bool write)
 Change read/write permission attributes of a file.
bool cmlabs::utils::MoveAFile (const char *oldfilename, const char *newfilename, bool force=false)
 Move/rename a file.
bool cmlabs::utils::MoveAFile (const char *olddir, const char *oldfilename, const char *newdir, const char *newfilename, bool force=false)
 Move a file between directories; see MoveAFile().
bool cmlabs::utils::CopyAFile (const char *oldfilename, const char *newfilename, bool force=false)
 Copy a file.
bool cmlabs::utils::CopyAFile (const char *olddir, const char *oldfilename, const char *newdir, const char *newfilename, bool force=false)
 Copy a file between directories; see CopyAFile().

Synchronization primitives (mutexes, semaphores, events, drum beats)

Named primitives are backed by OS objects shared between processes (Windows kernel objects, POSIX shared memory + pthread process-shared objects, or dispatch/mach objects on macOS); unnamed ones are process-local.

typedef bool(* cmlabs::utils::DrumBeatFunc) (uint32 id, uint32 count)
 Callback invoked on every drum-beat tick.
static std::map< uint32, DrumBeatInfo > * cmlabs::utils::DrumBeatMap = NULL
bool cmlabs::utils::SetSharedSystemInstance (uint32 inst)
 Set the instance number used to namespace shared OS objects, allowing several independent CMSDK systems on one host.
uint32 cmlabs::utils::GetSharedSystemInstance ()
 Get the current shared-system instance number.
bool cmlabs::utils::CreateDrumBeat (uint32 id, uint32 interval, DrumBeatFunc func, bool autostart=false)
 Create a periodic timer ("drum beat") that calls func every interval ms.
bool cmlabs::utils::StartDrumBeat (uint32 id)
 Start (or resume) a previously created drum beat.
bool cmlabs::utils::StopDrumBeat (uint32 id)
 Stop a running drum beat without destroying it.
bool cmlabs::utils::EndDrumBeat (uint32 id)
 Destroy a drum beat and release its OS timer.
bool cmlabs::utils::EnterMutex (const char *name, uint32 ms, bool autocreate=true)
 Acquire a named global mutex, creating it on first use.
bool cmlabs::utils::LeaveMutex (const char *name)
 Release a named global mutex previously acquired with EnterMutex().
bool cmlabs::utils::DestroyMutex (const char *name)
 Destroy a named global mutex and remove it from the registry.
Semaphorecmlabs::utils::GetSemaphore (const char *name, bool autocreate=true)
 Look up (and optionally create) a named semaphore in the global registry.
bool cmlabs::utils::WaitForSemaphore (const char *name, uint32 ms, bool autocreate=true)
 Wait on a named global semaphore.
bool cmlabs::utils::SignalSemaphore (const char *name)
 Signal a named global semaphore.
bool cmlabs::utils::DestroySemaphore (const char *name)
 Destroy a named global semaphore.
bool cmlabs::utils::WaitNextEvent (const char *name, uint32 ms, bool autocreate=true)
 Wait for the next signal on a named global event.
bool cmlabs::utils::SignalEvent (const char *name)
 Signal a named global event.
bool cmlabs::utils::DestroyEvent (const char *name)
 Destroy a named global event.

Dynamic libraries and command line

typedef int(* cmlabs::utils::LibraryFunction) ()
 Signature of a plain function exported from a dynamically loaded library.
bool cmlabs::utils::SetCommandLine (int argc, char *argv[])
 Parse and store the process command line for later retrieval by the Get/HasCommandLine* functions.
std::string cmlabs::utils::GetCommandLine ()
 Get the full original command line as one string.
std::string cmlabs::utils::GetCommandLinePath ()
 Get the directory portion of the executable path.
std::string cmlabs::utils::GetCommandLineExecutable ()
 Get the full executable path as invoked.
std::string cmlabs::utils::GetCommandLineExecutableOnly ()
 Get just the executable filename without path.
uint32 cmlabs::utils::GetCommandLineArgCount ()
 Number of positional command line items (excluding the executable).
std::string cmlabs::utils::GetCommandLineArg (uint16 n)
 Get the n-th positional command line item.
std::string cmlabs::utils::GetCommandLineArg (const char *key)
 Get the value of a 'key=value' command line argument.
bool cmlabs::utils::HasCommandLineArg (const char *key, std::string &value)
 Test for a 'key=value' argument without mutating the argument map.
Librarycmlabs::utils::OpenLibrary (const char *libName)
 Load a library by name, applying platform filename conventions.

Detailed Description

Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory, processes, sockets, files, strings, conversions and randomness.

This header collects the OS-abstraction and general-purpose helper layer used throughout the CMSDK/Psyclone codebase. Nearly every subsystem (messaging, catalogs, spaces, network) builds on these primitives. All functions live in the cmlabs::utils namespace (except the logging classes in cmlabs) and are implemented for Windows, Linux and macOS; platform differences are hidden behind the WINDOWS / APPLE preprocessor branches visible below.

Definition in file Utils.h.

Macro Definition Documentation

◆ _strcmpi

#define _strcmpi   strcasecmp

Definition at line 145 of file Utils.h.

◆ _strnicmp

#define _strnicmp   strnicmp

Definition at line 146 of file Utils.h.

◆ abs64

#define abs64   llabs

Definition at line 141 of file Utils.h.

◆ closesocket

◆ DllExport

#define DllExport

Definition at line 147 of file Utils.h.

◆ ERROR16

#define ERROR16   0xFFFF

Definition at line 161 of file Utils.h.

◆ ERROR32

#define ERROR32   0xFFFFFFFF

Definition at line 160 of file Utils.h.

◆ ERROR64

#define ERROR64   0xFFFFFFFFFFFFFFFFL

Definition at line 159 of file Utils.h.

◆ ERROR8

#define ERROR8   0xFF

Definition at line 162 of file Utils.h.

◆ EVENTMEMSIZE

#define EVENTMEMSIZE   256

Definition at line 143 of file Utils.h.

Referenced by cmlabs::utils::Event::Event(), and cmlabs::utils::Event::~Event().

◆ GetCurrentDirEx

#define GetCurrentDirEx   getcwd

Definition at line 79 of file Utils.h.

Referenced by cmlabs::utils::GetCurrentDir().

◆ INVALID_SOCKET

◆ LOG_MAXCOUNT

◆ LOG_MEMORY

◆ LOG_NETWORK

#define LOG_NETWORK   2

Definition at line 198 of file Utils.h.

Referenced by cmlabs::TCPListener::acceptConnection(), cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkConnection::clearBuffer(), cmlabs::SSLConnection::connect(), cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), cmlabs::TCPConnection::connect(), cmlabs::UDPConnection::connect(), cmlabs::NetworkChannel::ConnectionAutodetectRun(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createWebsocketConnection(), cmlabs::NetworkManager::createWebsocketConnection(), cmlabs::SSLConnection::delayedConnect(), cmlabs::TCPConnection::delayedConnect(), cmlabs::NetworkConnection::disconnectInternal(), cmlabs::JSONM::getData(), cmlabs::JSONM::getData(), cmlabs::NetworkChannel::HTTPServerRun(), cmlabs::SSLConnection::init(), cmlabs::TCPListener::init(), cmlabs::UDPConnection::initForOutputOnly(), cmlabs::JSONM::isValid(), cmlabs::WebsocketData::processContent(), cmlabs::NetworkConnection::readIntoBuffer(), cmlabs::SSLConnection::readIntoBuffer(), cmlabs::SSLConnection::receive(), cmlabs::NetworkConnection::receiveAvailable(), cmlabs::SSLConnection::receiveAvailable(), cmlabs::HTTPProtocol::ReceiveHTTPRequest(), cmlabs::RequestGateway::receiveHTTPRequest(), cmlabs::RequestGateway::receiveMessage(), cmlabs::HTTPProtocol::ReceiveWebsocketData(), cmlabs::RequestGateway::receiveWebsocketData(), cmlabs::NetworkConnection::run(), cmlabs::SSLConnection::send(), cmlabs::TCPConnection::send(), cmlabs::UDPConnection::send(), cmlabs::HTTPProtocol::SendHTTPReply(), and cmlabs::RequestClient::sendMessageToGateway().

◆ LOG_NOTOPIC

#define LOG_NOTOPIC   0

Definition at line 196 of file Utils.h.

◆ LOG_PROCESS

#define LOG_PROCESS   4

Definition at line 200 of file Utils.h.

Referenced by cmlabs::ThreadManager::threadMonitoring().

◆ LOG_SYSTEM

◆ LOG_TOPIC10

#define LOG_TOPIC10   10

Definition at line 206 of file Utils.h.

◆ LOG_TOPIC11

#define LOG_TOPIC11   11

Definition at line 207 of file Utils.h.

◆ LOG_TOPIC5

#define LOG_TOPIC5   5

Definition at line 201 of file Utils.h.

◆ LOG_TOPIC6

#define LOG_TOPIC6   6

Definition at line 202 of file Utils.h.

◆ LOG_TOPIC7

#define LOG_TOPIC7   7

Definition at line 203 of file Utils.h.

◆ LOG_TOPIC8

#define LOG_TOPIC8   8

Definition at line 204 of file Utils.h.

◆ LOG_TOPIC9

#define LOG_TOPIC9   9

Definition at line 205 of file Utils.h.

◆ LOGDEBUG

#define LOGDEBUG   2

Definition at line 211 of file Utils.h.

Referenced by cmlabs::LogSystem::LogSystemDebug().

◆ LogDebug

#define LogDebug   LogSystem::LogSystemDebug

Definition at line 314 of file Utils.h.

◆ LOGPRINT

#define LOGPRINT   1

Definition at line 210 of file Utils.h.

Referenced by cmlabs::PsyAPI::logPrint(), and cmlabs::LogSystem::LogSystemPrint().

◆ LogPrint

#define LogPrint   LogSystem::LogSystemPrint

Definition at line 313 of file Utils.h.

Referenced by cmlabs::TCPListener::acceptConnection(), cmlabs::MessagePlayer::addMessage(), cmlabs::RequestGateway::addPort(), cmlabs::RequestGateway::addRequestReplyToRequestQueue(), cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkManager::addTCPConnection(), cmlabs::NetworkConnection::clearBuffer(), cmlabs::MemoryManager::connect(), cmlabs::PsySpace::connect(), cmlabs::SSLConnection::connect(), cmlabs::SSLConnection::connect(), cmlabs::TCPConnection::connect(), cmlabs::TCPConnection::connect(), cmlabs::UDPConnection::connect(), cmlabs::NetworkChannel::ConnectionAutodetectRun(), cmlabs::DataMessage::ConvertDataFromOlderMessageFormat(), cmlabs::MemoryManager::create(), cmlabs::ProcessMemory::create(), cmlabs::ComponentMemory::createComponent(), cmlabs::utils::CreateDrumBeat(), cmlabs::DataMapsMemory::createNewRequest(), cmlabs::utils::CreateSharedMemorySegment(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createTCPConnection(), cmlabs::NetworkManager::createWebsocketConnection(), cmlabs::NetworkManager::createWebsocketConnection(), cmlabs::SSLConnection::delayedConnect(), cmlabs::TCPConnection::delayedConnect(), cmlabs::DataMapsMemory::deleteRequest(), cmlabs::NetworkConnection::disconnectInternal(), cmlabs::PsySpace::emitSignal(), cmlabs::utils::Mutex::enter(), cmlabs::utils::Mutex::enter(), cmlabs::TestRequestClient::finishUp(), cmlabs::TestWebRequestClient::finishUp(), cmlabs::TestWebSocketRequestClient::finishUp(), cmlabs::JSONM::getData(), cmlabs::JSONM::getData(), cmlabs::utils::Library::getFunction(), cmlabs::NetworkChannel::HTTPServerRun(), cmlabs::RequestGateway::init(), cmlabs::SSLConnection::init(), cmlabs::TCPListener::init(), cmlabs::VantagePoints::init(), cmlabs::UDPConnection::initForOutputOnly(), cmlabs::MessagePlayer::initRead(), cmlabs::MessagePlayer::initWrite(), cmlabs::TemporalMemory::insertMessage(), cmlabs::PsySpace::isConnected(), cmlabs::JSONM::isValid(), cmlabs::utils::Library::load(), cmlabs::TemporalMemory::logUsage(), cmlabs::utils::MoveAFile(), cmlabs::utils::NewProcess(), cmlabs::DataMapsMemory::open(), cmlabs::ProcessMemory::open(), cmlabs::utils::OpenSharedMemorySegment(), cmlabs::PsySpace::postMessage(), cmlabs::WebsocketData::processContent(), cmlabs::PsySpace::query(), cmlabs::PsySpace::queryReply(), cmlabs::utils::ReadAFile(), cmlabs::NetworkConnection::readIntoBuffer(), cmlabs::SSLConnection::readIntoBuffer(), cmlabs::SSLConnection::receive(), cmlabs::NetworkConnection::receiveAvailable(), cmlabs::SSLConnection::receiveAvailable(), cmlabs::HTTPProtocol::ReceiveHTTPRequest(), cmlabs::RequestGateway::receiveHTTPRequest(), cmlabs::RequestClient::receiveMessage(), cmlabs::RequestExecutor::receiveMessage(), cmlabs::RequestGateway::receiveMessage(), cmlabs::RequestClient::receiveNetworkEvent(), cmlabs::RequestExecutor::receiveNetworkEvent(), cmlabs::HTTPProtocol::ReceiveWebsocketData(), cmlabs::RequestGateway::receiveWebsocketData(), cmlabs::RequestGateway::replyToClient(), cmlabs::RequestExecutor::replyToGateway(), cmlabs::NetworkConnection::run(), cmlabs::TestRequestClient::run(), cmlabs::TestWebRequestClient::run(), cmlabs::TestWebSocketRequestClient::run(), cmlabs::RequestGateway::runExec(), cmlabs::SSLConnection::send(), cmlabs::TCPConnection::send(), cmlabs::UDPConnection::send(), cmlabs::HTTPProtocol::SendHTTPReply(), cmlabs::RequestClient::sendMessageToGateway(), cmlabs::RequestExecutor::sendMessageToGateway(), cmlabs::RequestClient::sendStatusNow(), cmlabs::RequestExecutor::sendStatusNow(), cmlabs::DataMapsMemory::setRequestStatus(), cmlabs::PsySpace::shutdown(), cmlabs::PsySpace::start(), cmlabs::utils::StartDrumBeat(), cmlabs::Runnable::stop(), cmlabs::utils::StopDrumBeat(), cmlabs::utils::TerminateThread(), cmlabs::NetworkManager::TestHTTP(), cmlabs::RequestClient::TestServerLogin(), cmlabs::ThreadManager::threadMonitoring(), cmlabs::MessagePlayer::waitForNextMessage(), and cmlabs::DataMapsMemory::waitForRequestReply().

◆ MAXCOMMANDLINELEN

#define MAXCOMMANDLINELEN   1024

◆ MAXCONTENTLEN

◆ MAXFILENAMELEN

#define MAXFILENAMELEN   256

Definition at line 89 of file Utils.h.

Referenced by cmlabs::utils::DeleteFilesInADir(), and cmlabs::Internal_BitmapPoster().

◆ MAXKEYNAMELEN

#define MAXKEYNAMELEN   256

Definition at line 85 of file Utils.h.

Referenced by _wrap_ComponentSetup_base_get(), _wrap_ComponentSetup_base_get(), _wrap_ComponentSetup_base_set(), _wrap_ComponentSetup_base_set(), _wrap_ComponentSetup_cmdline_get(), _wrap_ComponentSetup_cmdline_get(), _wrap_ComponentSetup_cmdline_set(), _wrap_ComponentSetup_cmdline_set(), _wrap_ComponentSetup_extension_get(), _wrap_ComponentSetup_extension_get(), _wrap_ComponentSetup_extension_set(), _wrap_ComponentSetup_extension_set(), _wrap_ComponentSetup_function_get(), _wrap_ComponentSetup_function_get(), _wrap_ComponentSetup_function_set(), _wrap_ComponentSetup_function_set(), _wrap_ComponentSetup_logfile_get(), _wrap_ComponentSetup_logfile_get(), _wrap_ComponentSetup_logfile_set(), _wrap_ComponentSetup_logfile_set(), _wrap_ComponentSetup_name_get(), _wrap_ComponentSetup_name_get(), _wrap_ComponentSetup_name_set(), _wrap_ComponentSetup_name_set(), _wrap_ComponentSetup_operation_get(), _wrap_ComponentSetup_operation_get(), _wrap_ComponentSetup_operation_set(), _wrap_ComponentSetup_operation_set(), _wrap_ComponentSetup_root_get(), _wrap_ComponentSetup_root_get(), _wrap_ComponentSetup_root_set(), _wrap_ComponentSetup_root_set(), _wrap_ComponentSetup_subdir_get(), _wrap_ComponentSetup_subdir_get(), _wrap_ComponentSetup_subdir_set(), _wrap_ComponentSetup_subdir_set(), _wrap_CustomView_name_get(), _wrap_CustomView_name_get(), _wrap_CustomView_name_set(), _wrap_CustomView_name_set(), _wrap_CustomView_templateURL_get(), _wrap_CustomView_templateURL_get(), _wrap_CustomView_templateURL_set(), _wrap_CustomView_templateURL_set(), _wrap_FilterSpec_key_get(), _wrap_FilterSpec_key_get(), _wrap_FilterSpec_key_set(), _wrap_FilterSpec_key_set(), _wrap_PostSpec_name_get(), _wrap_PostSpec_name_get(), _wrap_PostSpec_name_set(), _wrap_PostSpec_name_set(), _wrap_QuerySpec_ext_get(), _wrap_QuerySpec_ext_get(), _wrap_QuerySpec_ext_set(), _wrap_QuerySpec_ext_set(), _wrap_QuerySpec_hostName_get(), _wrap_QuerySpec_hostName_get(), _wrap_QuerySpec_hostName_set(), _wrap_QuerySpec_hostName_set(), _wrap_QuerySpec_key_get(), _wrap_QuerySpec_key_get(), _wrap_QuerySpec_key_set(), _wrap_QuerySpec_key_set(), _wrap_QuerySpec_name_get(), _wrap_QuerySpec_name_get(), _wrap_QuerySpec_name_set(), _wrap_QuerySpec_name_set(), _wrap_QuerySpec_operation_get(), _wrap_QuerySpec_operation_get(), _wrap_QuerySpec_operation_set(), _wrap_QuerySpec_operation_set(), _wrap_QuerySpec_sourceName_get(), _wrap_QuerySpec_sourceName_get(), _wrap_QuerySpec_sourceName_set(), _wrap_QuerySpec_sourceName_set(), _wrap_QuerySpec_subdir_get(), _wrap_QuerySpec_subdir_get(), _wrap_QuerySpec_subdir_set(), _wrap_QuerySpec_subdir_set(), _wrap_QuerySpec_type_get(), _wrap_QuerySpec_type_get(), _wrap_QuerySpec_type_set(), _wrap_QuerySpec_type_set(), _wrap_RetrieveSpec_key_get(), _wrap_RetrieveSpec_key_get(), _wrap_RetrieveSpec_key_set(), _wrap_RetrieveSpec_key_set(), _wrap_RetrieveSpec_name_get(), _wrap_RetrieveSpec_name_get(), _wrap_RetrieveSpec_name_set(), _wrap_RetrieveSpec_name_set(), _wrap_SignalSpec_name_get(), _wrap_SignalSpec_name_get(), _wrap_SignalSpec_name_set(), _wrap_SignalSpec_name_set(), _wrap_TriggerSpec_name_get(), _wrap_TriggerSpec_name_get(), _wrap_TriggerSpec_name_set(), _wrap_TriggerSpec_name_set(), cmlabs::MessagePlayer::addMessage(), cmlabs::ProcessMemory::create(), cmlabs::ComponentData::CreateComponent(), cmlabs::ComponentMemory::createComponent(), cmlabs::GenericMemoryMap< T, ID >::CreateEntry(), cmlabs::GenericMemoryMap< T, ID >::CreateFirstFreeEntry(), cmlabs::MemoryMaps::CreateNewCrank(), cmlabs::DataMapsMemory::createNewCrank(), cmlabs::ProcessMemory::createNewProcess(), cmlabs::DataMapsMemory::createNewRequest(), cmlabs::FilterSpec::fromXML(), cmlabs::PostSpec::fromXML(), cmlabs::QuerySpec::fromXML(), cmlabs::RetrieveSpec::fromXML(), cmlabs::SignalSpec::fromXML(), cmlabs::MemoryManager::getComponentName(), cmlabs::utils::GetLocalInterfaces(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1base_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1cmdline_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1extension_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1function_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1logfile_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1name_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1operation_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1root_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_ComponentSetup_1subdir_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_CustomView_1name_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_CustomView_1templateURL_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_FilterSpec_1key_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_PostSpec_1name_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1ext_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1hostName_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1key_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1name_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1operation_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1sourceName_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1subdir_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_QuerySpec_1type_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_RetrieveSpec_1key_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_RetrieveSpec_1name_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_SignalSpec_1name_1set(), Java_com_cmlabs_cmsdk_cmsdkJNI_TriggerSpec_1name_1set(), cmlabs::ComponentData::RecordRemoteComponent(), cmlabs::ComponentData::ReserveComponentID(), cmlabs::utils::Semaphore::Semaphore(), cmlabs::MemoryManager::subContextToText(), cmlabs::MemoryManager::subTypeToText(), cmlabs::MessageIndex::UnitTest(), cmlabs::TriggerSpec::UnitTest(), cmlabs::PsyAPI::waitForNewMessage(), and cmlabs::MessagePlayer::waitForNextMessage().

◆ MAXSCRIPTLEN

#define MAXSCRIPTLEN   10*1024

◆ MAXSHMEMNAMELEN

◆ MAXVALUENAMELEN

◆ MUTEX_INVALID

#define MUTEX_INVALID   0

Definition at line 133 of file Utils.h.

◆ MUTEXMEMSIZE

#define MUTEXMEMSIZE   64

Definition at line 142 of file Utils.h.

Referenced by cmlabs::utils::Mutex::Mutex(), and cmlabs::utils::Mutex::~Mutex().

◆ OSCPU_AMD64

#define OSCPU_AMD64   2

Definition at line 156 of file Utils.h.

Referenced by cmlabs::utils::GetCPUArchitecture(), and cmlabs::utils::GetSystemOSName().

◆ OSCPU_IA64

#define OSCPU_IA64   3

Definition at line 157 of file Utils.h.

Referenced by cmlabs::utils::GetCPUArchitecture(), and cmlabs::utils::GetSystemOSName().

◆ OSCPU_UNKNOWN

#define OSCPU_UNKNOWN   0

Definition at line 154 of file Utils.h.

Referenced by cmlabs::utils::GetCPUArchitecture().

◆ OSCPU_X86

#define OSCPU_X86   1

Definition at line 155 of file Utils.h.

Referenced by cmlabs::utils::GetCPUArchitecture(), and cmlabs::utils::GetSystemOSName().

◆ SD_BOTH

◆ SEMAPHOREMEMSIZE

#define SEMAPHOREMEMSIZE   256

◆ SOCKET

◆ SOCKET_ERROR

◆ SOCKETTRYAGAIN

◆ SOCKETWOULDBLOCK

◆ stricmp

#define stricmp   strcasecmp

Definition at line 132 of file Utils.h.

Referenced by cmlabs::TrackPlayerMessage::addEntry(), cmlabs::RequestClient::addGateway(), cmlabs::MessageIndex::addIndexKey(), cmlabs::RequestGateway::callInternalAPI(), cmlabs::PostSpec::contentFromXML(), cmlabs::ComponentMemory::createComponent(), cmlabs::HTTPRequest::createMultipartRequest(), cmlabs::HTTPRequest::createRequest(), cmlabs::HTTPRequest::createRequest(), cmlabs::Bitmap::DataToBitmapFileFormat(), cmlabs::Bitmap::DataToEncodingFormat(), cmlabs::DataMessage::findKey(), cmlabs::QuerySpec::fromXML(), cmlabs::DataMessage::getAsBool(), cmlabs::DataMessage::getAsString(), cmlabs::ComponentMemory::getComponentID(), cmlabs::DataMessage::GetCSVHeader(), cmlabs::JSONM::getData(), cmlabs::JSONM::getDataType(), cmlabs::GetDataTypeID(), cmlabs::GenericMemoryMap< T, ID >::GetEntryID(), cmlabs::DataMessage::getKeyType(), cmlabs::ComponentMemory::getParameterAsBool(), cmlabs::TriggerSpec::getPostSpec(), cmlabs::TriggerSpec::getPostSpecs(), cmlabs::ProcessMemory::getProcessID(), cmlabs::TriggerSpec::getQuerySpec(), cmlabs::TriggerSpec::getRetrieveSpec(), cmlabs::TriggerSpec::getSignalSpec(), cmlabs::GetTimeFromString(), cmlabs::UnitTestRunner::hasTest(), cmlabs::Bitmap::init(), cmlabs::RESTHTTPCall::init(), cmlabs::Internal_MessageScript(), cmlabs::Internal_MessageToggler(), cmlabs::Internal_Ping(), cmlabs::Internal_RetrieveTest(), cmlabs::Internal_SignalPing(), cmlabs::ObsString::isBetween(), cmlabs::HTTPReply::isWebsocketUpgrade(), cmlabs::HTTPRequest::isWebsocketUpgrade(), cmlabs::utils::laststristr(), cmlabs::ComponentMemory::lookupComponentID(), cmlabs::GenericMemoryMap< T, ID >::LookupEntryID(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::RESTParser::parseRequest(), cmlabs::HTTPReply::processHeader(), cmlabs::HTTPRequest::processHeader(), cmlabs::MessageIndex::queryMessages(), cmlabs::RequestGateway::receiveWebsocketData(), cmlabs::MessageIndex::removeIndexKey(), cmlabs::RunCMSDKTests(), cmlabs::UnitTestRunner::runOne(), cmlabs::ComponentMemory::setParameter(), and cmlabs::ComponentMemory::setPrivateData().

◆ THREAD_ARG

#define THREAD_ARG   void*

Definition at line 130 of file Utils.h.

Referenced by _wrap_PsySpaceContinuousRun(), _wrap_PsySpaceContinuousRun(), _wrap_PsySpacePoolRun(), _wrap_PsySpacePoolRun(), _wrap_PsySpaceRun(), _wrap_PsySpaceRun(), cmlabs::NetworkChannel::ConnectionAutodetectRun(), cmlabs::NetworkChannel::HTTPClientRun(), cmlabs::NetworkChannel::HTTPServerRun(), cmlabs::HTTPServerTest(), Java_com_cmlabs_cmsdk_cmsdkJNI_PsySpaceContinuousRun(), Java_com_cmlabs_cmsdk_cmsdkJNI_PsySpacePoolRun(), Java_com_cmlabs_cmsdk_cmsdkJNI_PsySpaceRun(), cmlabs::TestRequestExecutor::LongExecutorRun, cmlabs::MemoryManager::MemoryManagement, cmlabs::NetworkChannel::MessageConnectionRun(), cmlabs::NetworkManager::NetworkChannel, cmlabs::NetworkChannel::NetworkListenerRun(), cmlabs::NetworkManager::NetworkManagerRun(), cmlabs::ProcessMemoryPerfTest(), cmlabs::PsySpace::PsyAPI, cmlabs::PsySpace::PsySpaceContinuousRun, cmlabs::PsySpace::PsySpacePoolRun, cmlabs::PsySpace::PsySpaceRun, cmlabs::MessageQueue::QueueTest, cmlabs::RequestClient::RequestClientRun, cmlabs::RequestExecutor::RequestExecutorRun, cmlabs::RequestGateway::RequestGatewayClientRun, cmlabs::RequestGateway::RequestGatewayExecRun, cmlabs::TestRequestExecutor::ShortExecutorRun, cmlabs::SSLConnection::SSLConnectionRun, cmlabs::TCPConnection::TCPConnectionRun, cmlabs::TCPListener::TCPListenerRun, cmlabs::NetworkChannel::TelnetServerRun(), cmlabs::TestRequestClient::TestRequestClientRun, cmlabs::TestWebRequestClient::TestWebRequestClientRun, cmlabs::TestWebSocketRequestClient::TestWebSocketRequestClientRun, cmlabs::UDPConnection::UDPConnectionRun, cmlabs::MemoryManagerX::UnitTest(), and cmlabs::MessageQueue::UnitTestQueues().

◆ THREAD_FUNCTION_CALL

◆ THREAD_INIT

#define THREAD_INIT   2

Definition at line 95 of file Utils.h.

Referenced by cmlabs::ThreadManager::createThread().

◆ THREAD_INTERRUPTED

#define THREAD_INTERRUPTED   5

Definition at line 98 of file Utils.h.

Referenced by cmlabs::ThreadManager::interruptThread().

◆ THREAD_NONE

#define THREAD_NONE   0

Definition at line 93 of file Utils.h.

Referenced by cmlabs::ThreadManager::createThread().

◆ THREAD_PAUSED

#define THREAD_PAUSED   4

Definition at line 97 of file Utils.h.

Referenced by cmlabs::ThreadManager::pauseThread().

◆ THREAD_RET

#define THREAD_RET   void *

Definition at line 127 of file Utils.h.

Referenced by _wrap_PsySpaceContinuousRun(), _wrap_PsySpaceContinuousRun(), _wrap_PsySpacePoolRun(), _wrap_PsySpacePoolRun(), _wrap_PsySpaceRun(), _wrap_PsySpaceRun(), cmlabs::NetworkChannel::ConnectionAutodetectRun(), cmlabs::NetworkChannel::HTTPClientRun(), cmlabs::NetworkChannel::HTTPServerRun(), cmlabs::HTTPServerTest(), Java_com_cmlabs_cmsdk_cmsdkJNI_PsySpaceContinuousRun(), Java_com_cmlabs_cmsdk_cmsdkJNI_PsySpacePoolRun(), Java_com_cmlabs_cmsdk_cmsdkJNI_PsySpaceRun(), cmlabs::TestRequestExecutor::LongExecutorRun, cmlabs::MemoryManager::MemoryManagement, cmlabs::NetworkChannel::MessageConnectionRun(), cmlabs::NetworkManager::NetworkChannel, cmlabs::NetworkChannel::NetworkListenerRun(), cmlabs::NetworkManager::NetworkManagerRun(), cmlabs::ProcessMemoryPerfTest(), cmlabs::PsySpace::PsyAPI, cmlabs::PsySpace::PsySpaceContinuousRun, cmlabs::PsySpace::PsySpacePoolRun, cmlabs::PsySpace::PsySpaceRun, cmlabs::MessageQueue::QueueTest, cmlabs::RequestClient::RequestClientRun, cmlabs::RequestExecutor::RequestExecutorRun, cmlabs::RequestGateway::RequestGatewayClientRun, cmlabs::RequestGateway::RequestGatewayExecRun, cmlabs::TestRequestExecutor::ShortExecutorRun, cmlabs::SSLConnection::SSLConnectionRun, cmlabs::TCPConnection::TCPConnectionRun, cmlabs::TCPListener::TCPListenerRun, cmlabs::NetworkChannel::TelnetServerRun(), cmlabs::TestRequestClient::TestRequestClientRun, cmlabs::TestThreadManager(), cmlabs::TestWebRequestClient::TestWebRequestClientRun, cmlabs::TestWebSocketRequestClient::TestWebSocketRequestClientRun, cmlabs::ThreadMonitoring(), cmlabs::UDPConnection::UDPConnectionRun, cmlabs::MemoryManagerX::UnitTest(), and cmlabs::MessageQueue::UnitTestQueues().

◆ thread_ret_val

◆ THREAD_RUNNING

#define THREAD_RUNNING   3

◆ THREAD_STATS_ADHOC

#define THREAD_STATS_ADHOC   2

◆ THREAD_STATS_AUTO

#define THREAD_STATS_AUTO   1

Definition at line 101 of file Utils.h.

Referenced by cmlabs::utils::GetThreadStatColAbility().

◆ THREAD_STATS_OFF

#define THREAD_STATS_OFF   0

◆ THREAD_TERMINATED

◆ ThreadHandle

◆ WINSHMEMSPACE

Typedef Documentation

◆ SOCKADDR

typedef struct sockaddr SOCKADDR

Definition at line 135 of file Utils.h.

◆ THREAD_FUNCTION

typedef THREAD_RET(* THREAD_FUNCTION) (void *)

Definition at line 128 of file Utils.h.