|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Cross-platform helper layer of the CMSDK: synchronization primitives, threads and processes, shared memory, timers, bit fields, sockets and name lookup, registry access (Windows), file I/O, rich string/text manipulation, numeric parsing/formatting and random numbers. More...
Cross-platform helper layer of the CMSDK: synchronization primitives, threads and processes, shared memory, timers, bit fields, sockets and name lookup, registry access (Windows), file I/O, rich string/text manipulation, numeric parsing/formatting and random numbers.
Functions are grouped below by theme. All of them are plain free functions in cmlabs::utils unless noted otherwise.
Classes | |
| 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... | |
Macros | |
| #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 |
Typedefs | |
| 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 | |
| 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. | |
Variables | |
| static SharedMemoryFileHandleMapType * | cmlabs::utils::SharedMemoryFileHandleMap = NULL |
| static uint16 | cmlabs::utils::SharedSystemInstance = 0 |
| static Mutex * | cmlabs::utils::SharedMemoryMutexMapMutex = NULL |
| static std::map< std::string, Mutex * > * | cmlabs::utils::SharedMemoryMutexMap = NULL |
| static Mutex * | cmlabs::utils::SharedMemorySemaphoreMapMutex = NULL |
| static std::map< std::string, Semaphore * > * | cmlabs::utils::SharedMemorySemaphoreMap = NULL |
| static Mutex * | cmlabs::utils::SharedMemoryEventMapMutex = NULL |
| static std::map< std::string, Event * > * | cmlabs::utils::SharedMemoryEventMap = NULL |
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. | |
| Semaphore * | cmlabs::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. | |
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::ReapThread (ThreadHandle &hThread) |
| bool | cmlabs::utils::TryReapThread (ThreadHandle &hThread) |
| 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. | |
Managed child launch (T1.4 external-executable support) | |
Extended launch/lifecycle helpers used by ExternalExecManager. On POSIX these are thin conveniences; on Windows they carry the env block, working directory, optional stdout/stderr capture pipes and console-group/graceful-stop plumbing that plain NewProcess() does not. | |
| uint32 | cmlabs::utils::NewProcessEx (const char *cmdline, const char *initdir, const char *title, const std::map< std::string, std::string > *env, bool captureOutput, bool ignoreOutput, bool newProcessGroup) |
| Launch a child with environment overrides and optional output capture. | |
| bool | cmlabs::utils::ReadProcessOutput (uint32 proc, std::string &out, std::string &err) |
| Read any pending captured stdout/stderr from a child launched with captureOutput=true. | |
| bool | cmlabs::utils::SendProcessBreak (uint32 proc, int sig) |
| Attempt a graceful stop: POSIX sends the given signal; Windows posts a CTRL_BREAK to the child's process group (requires newProcessGroup=true at launch) and falls back to nothing if unsupported. | |
| #define CHILD_READ_FD ( (*pipes)[PARENT_WRITE_PIPE][READ_FD] ) |
| #define CHILD_WRITE_FD ( (*pipes)[PARENT_READ_PIPE][WRITE_FD] ) |
| #define PARENT_READ_FD ( (*pipes)[PARENT_READ_PIPE][READ_FD] ) |
| #define PARENT_WRITE_FD ( (*pipes)[PARENT_WRITE_PIPE][WRITE_FD] ) |
| #define PROC_RUNNING 3 |
Definition at line 1194 of file Utils.h.
Referenced by cmlabs::utils::GetProcessStatus(), and cmlabs::utils::WaitForProcess().
| #define PROC_TERMINATED 1 |
Definition at line 1192 of file Utils.h.
Referenced by cmlabs::utils::GetProcessStatus(), and cmlabs::utils::WaitForProcess().
| #define PROC_TIMEOUT 4 |
Definition at line 1195 of file Utils.h.
Referenced by cmlabs::utils::WaitForProcess().
| #define PROCBUFSIZE 4096 |
Definition at line 1209 of file Utils.h.
Referenced by cmlabs::utils::RunOSCommand().
| #define SharedMemoryFileHandleMapType std::map<void*, std::string> |
Definition at line 393 of file Utils.h.
Referenced by cmlabs::utils::CreateSharedMemorySegment(), and cmlabs::utils::OpenSharedMemorySegment().
| typedef bool(* cmlabs::utils::DrumBeatFunc) (uint32 id, uint32 count) |
| typedef std::pair<std::string, Event*> cmlabs::utils::SharedMemoryEventMapPair |
| typedef std::pair<std::string, Mutex*> cmlabs::utils::SharedMemoryMutexMapPair |
| typedef std::pair<std::string, Semaphore*> cmlabs::utils::SharedMemorySemaphoreMapPair |
| int32 cmlabs::utils::AtomicDecrement32 | ( | int32 volatile & | v | ) |
| int64 cmlabs::utils::AtomicDecrement64 | ( | int64 volatile & | v | ) |
| int32 cmlabs::utils::AtomicIncrement32 | ( | int32 volatile & | v | ) |
| int64 cmlabs::utils::AtomicIncrement64 | ( | int64 volatile & | v | ) |
| uint32 cmlabs::utils::Calc32BitFieldSize | ( | uint32 | bitsize | ) |
Compute the byte size needed for a bitfield of bitsize bits, rounded up to a 32-bit boundary.
| bitsize | Number of bits. |
Definition at line 2463 of file Utils.cpp.
Referenced by cmlabs::TemporalMemory::create(), cmlabs::MemoryRequestQueues::InitRequestMap(), cmlabs::ThreadManager::resizeThreadStorage(), and UnitTest_Utils().
| bool cmlabs::utils::CheckForThreadFinished | ( | ThreadHandle | hThread | ) |
Non-blocking check whether a thread has terminated.
| hThread | Thread handle. |
Definition at line 2942 of file Utils.cpp.
References ThreadHandle.
| bool cmlabs::utils::CloseSharedMemorySegment | ( | char * | data, |
| uint64 | size ) |
Unmap a segment previously created/opened here.
| data | Pointer returned by Create/OpenSharedMemorySegment(). |
| size | Segment size in bytes. |
Definition at line 2402 of file Utils.cpp.
References SharedMemoryFileHandleMap.
Referenced by cmlabs::ComponentMemory::open(), cmlabs::DataMapsMemory::open(), cmlabs::MasterMemory::open(), cmlabs::ProcessMemory::open(), cmlabs::TemporalMemory::open(), cmlabs::MemoryRequestConnection::shutdown(), cmlabs::MemoryRequestServer::shutdown(), cmlabs::ComponentMemory::~ComponentMemory(), cmlabs::DataMapsMemory::~DataMapsMemory(), cmlabs::utils::Event::~Event(), cmlabs::MasterMemory::~MasterMemory(), cmlabs::utils::Mutex::~Mutex(), cmlabs::ProcessMemory::~ProcessMemory(), cmlabs::PsycloneIndex::~PsycloneIndex(), cmlabs::utils::Semaphore::~Semaphore(), and cmlabs::TemporalMemory::~TemporalMemory().
| bool cmlabs::utils::ContinueThread | ( | ThreadHandle | hThread | ) |
Resume a thread paused with PauseThread().
| hThread | Thread handle. |
Definition at line 3107 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::continueThread().
| 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.
| id | Caller-chosen unique id for the beat. |
| interval | Period in milliseconds. |
| func | Callback to invoke on each tick. |
| autostart | Start immediately when true; otherwise call StartDrumBeat(). |
Definition at line 482 of file Utils.cpp.
References cmlabs::utils::DrumBeatInfo::count, cmlabs::utils::DrumBeatInfo::createdTime, DrumBeatCallback(), DrumBeatMap, cmlabs::utils::DrumBeatInfo::func, cmlabs::GetTimeNow(), cmlabs::utils::DrumBeatInfo::handle, cmlabs::utils::DrumBeatInfo::id, cmlabs::utils::DrumBeatInfo::interval, LOG_SYSTEM, LogPrint, and StartDrumBeat().
| char * cmlabs::utils::CreateSharedMemorySegment | ( | const char * | name, |
| uint64 | size, | ||
| bool | force = false ) |
Create a named shared memory segment and map it into this process.
| name | Global segment name. |
| size | Size in bytes. |
| force | Recreate the segment even if one with this name already exists. |
Definition at line 2166 of file Utils.cpp.
References GetLastOSErrorMessage(), LOG_SYSTEM, LogPrint, MAXSHMEMNAMELEN, SharedMemoryFileHandleMap, SharedMemoryFileHandleMapType, and WINSHMEMSPACE.
Referenced by cmlabs::ComponentMemory::create(), cmlabs::MasterMemory::create(), cmlabs::ProcessMemory::create(), cmlabs::TemporalMemory::create(), cmlabs::utils::Event::Event(), cmlabs::MemoryRequestServer::init(), cmlabs::PsycloneIndex::init(), cmlabs::utils::Mutex::Mutex(), and cmlabs::utils::Semaphore::Semaphore().
| bool cmlabs::utils::CreateThread | ( | THREAD_FUNCTION | func, |
| void * | args, | ||
| ThreadHandle & | thread, | ||
| uint32 & | osID ) |
Start a new OS thread.
| func | Entry point (THREAD_FUNCTION signature; platform calling convention hidden by the macros above). | |
| args | Opaque pointer passed to func. | |
| [out] | thread | Receives the thread handle. |
| [out] | osID | Receives the OS thread id. |
Definition at line 2896 of file Utils.cpp.
References CreateThread(), Sleep(), and ThreadHandle.
Referenced by CreateThread(), and cmlabs::ThreadManager::createThread().
| bool cmlabs::utils::DestroyEvent | ( | const char * | name | ) |
Destroy a named global event.
| name | Event name. |
Definition at line 917 of file Utils.cpp.
References SharedMemoryEventMap, and SharedMemoryEventMapMutex.
| bool cmlabs::utils::DestroyMutex | ( | const char * | name | ) |
Destroy a named global mutex and remove it from the registry.
| name | Mutex name. |
Definition at line 702 of file Utils.cpp.
References SharedMemoryMutexMap, and SharedMemoryMutexMapMutex.
| bool cmlabs::utils::DestroySemaphore | ( | const char * | name | ) |
Destroy a named global semaphore.
| name | Semaphore name. |
Definition at line 836 of file Utils.cpp.
References SharedMemorySemaphoreMap, and SharedMemorySemaphoreMapMutex.
| bool cmlabs::utils::EndDrumBeat | ( | uint32 | id | ) |
Destroy a drum beat and release its OS timer.
| id | Beat id. |
Definition at line 614 of file Utils.cpp.
References cmlabs::utils::DrumBeatInfo::count, cmlabs::utils::DrumBeatInfo::createdTime, DrumBeatMap, cmlabs::utils::DrumBeatInfo::func, cmlabs::utils::DrumBeatInfo::handle, cmlabs::utils::DrumBeatInfo::id, cmlabs::utils::DrumBeatInfo::interval, cmlabs::utils::DrumBeatInfo::started, and StopDrumBeat().
| bool cmlabs::utils::EndProcess | ( | uint32 | proc | ) |
Forcibly terminate a child process.
| proc | Process id from NewProcess(). |
| bool cmlabs::utils::EnterMutex | ( | const char * | name, |
| uint32 | ms, | ||
| bool | autocreate = true ) |
Acquire a named global mutex, creating it on first use.
| name | Mutex name. |
| ms | Timeout in milliseconds. |
| autocreate | Create the mutex if it does not yet exist. |
Definition at line 649 of file Utils.cpp.
References cmlabs::utils::Mutex::enter(), SharedMemoryMutexMap, and SharedMemoryMutexMapMutex.
| int cmlabs::utils::FromOSPriority | ( | int | pri | ) |
Map a native OS priority back to the CMSDK priority scale.
| pri | OS priority. |
Definition at line 3680 of file Utils.cpp.
Referenced by GetThreadPriority().
| bool cmlabs::utils::GetBit | ( | uint32 | loc, |
| const char * | bitfield, | ||
| uint32 | bytesize, | ||
| bit & | val ) |
Read bit loc.
| loc | Bit index. | |
| bitfield | Field data. | |
| bytesize | Field size in bytes. | |
| [out] | val | Receives the bit. |
Definition at line 2692 of file Utils.cpp.
Referenced by cmlabs::GenericMemoryMap< T, ID >::CreateEntry().
| std::string cmlabs::utils::GetBitFieldAsString | ( | const char * | bitfield, |
| uint32 | bytesize, | ||
| uint32 | size ) |
Render the first size bits as a '0'/'1' string, for debugging.
| bitfield | Field data. |
| bytesize | Field size in bytes. |
| size | Number of bits to render. |
Definition at line 2742 of file Utils.cpp.
Referenced by PrintBitFieldString().
| bool cmlabs::utils::GetCPUTicks | ( | ThreadHandle | hThread, |
| uint64 & | ticks ) |
Get accumulated CPU time of a specific thread.
| hThread | Thread handle. | |
| [out] | ticks | Receives CPU time in microseconds. |
Definition at line 3210 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::addLocalThreadStats(), cmlabs::PsyAPI::postOutputMessage(), cmlabs::ThreadManager::threadMonitoring(), and cmlabs::PsyAPI::waitForNewMessage().
| bool cmlabs::utils::GetCPUTicks | ( | uint64 & | ticks | ) |
Get accumulated CPU time of the calling thread.
| [out] | ticks | Receives CPU time in microseconds. |
Definition at line 3261 of file Utils.cpp.
References GetCurrentThread().
| bool cmlabs::utils::GetCurrentThread | ( | ThreadHandle & | thread | ) |
Get the handle of the calling thread.
| [out] | thread | Receives the handle. |
Definition at line 3158 of file Utils.cpp.
References GetCurrentThread(), and ThreadHandle.
Referenced by GetCPUTicks(), and GetCurrentThread().
| bool cmlabs::utils::GetCurrentThreadOSID | ( | uint32 & | tid | ) |
Get the OS-level id of the calling thread (gettid / GetCurrentThreadId).
| [out] | tid | Receives the id. |
Definition at line 3138 of file Utils.cpp.
Referenced by cmlabs::utils::Mutex::enter(), and cmlabs::utils::Mutex::enter().
| bool cmlabs::utils::GetCurrentThreadUniqueID | ( | uint32 & | tid | ) |
Get a process-unique id for the calling thread.
| [out] | tid | Receives the id. |
Definition at line 3118 of file Utils.cpp.
Referenced by cmlabs::ThreadManager::getLocalThreadID().
| bool cmlabs::utils::GetDesktopSize | ( | uint32 & | width, |
| uint32 & | height ) |
| bool cmlabs::utils::GetFirstFreeBitLoc | ( | const char * | bitfield, |
| uint32 | bytesize, | ||
| uint32 & | loc ) |
Find the first 0 (free) bit.
| bitfield | Field data. | |
| bytesize | Field size in bytes. | |
| [out] | loc | Receives the bit index. |
Definition at line 2473 of file Utils.cpp.
Referenced by cmlabs::MemoryRequestQueues::AddNewRequest(), cmlabs::GenericMemoryMap< T, ID >::CreateFirstFreeEntry(), cmlabs::ThreadManager::createThread(), cmlabs::TemporalMemory::insertMessage(), and UnitTest_Utils().
| bool cmlabs::utils::GetFirstFreeBitLocN | ( | const char * | bitfield, |
| uint32 | bytesize, | ||
| uint32 | num, | ||
| uint32 & | loc ) |
Find the first run of num consecutive 0 bits.
| bitfield | Field data. | |
| bytesize | Field size in bytes. | |
| num | Run length required. | |
| [out] | loc | Receives the start bit index. |
Definition at line 2496 of file Utils.cpp.
References BITFREE, MAXVALUINT16, and MAXVALUINT32.
Referenced by cmlabs::TemporalMemory::insertMessage(), and UnitTest_Utils().
| bool cmlabs::utils::GetLastOccupiedBitLoc | ( | const char * | bitfield, |
| uint32 | bytesize, | ||
| uint32 & | loc ) |
Find the highest set (occupied) bit.
| bitfield | Field data. | |
| bytesize | Field size in bytes. | |
| [out] | loc | Receives the bit index. |
Definition at line 2717 of file Utils.cpp.
Referenced by UnitTest_Utils().
| uint32 cmlabs::utils::GetLocalProcessID | ( | ) |
| bool cmlabs::utils::GetNextLineEnd | ( | const char * | str, |
| uint32 | size, | ||
| uint32 & | len, | ||
| uint32 & | crSize ) |
Find the end of the current line.
| str | Text. | |
| size | Bytes available. | |
| [out] | len | Line length excluding the terminator. |
| [out] | crSize | Terminator size (1 for \n, 2 for \r\n). |
Definition at line 6332 of file Utils.cpp.
Referenced by cmlabs::HTTPReply::processHeader(), and cmlabs::HTTPRequest::processHeader().
| bool cmlabs::utils::GetOSCPUUsage | ( | double & | percentUse | ) |
| 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.
| [out] | procPercentUse | Process CPU usage in percent. |
| [out] | osPercentUse | Total OS CPU usage in percent. |
| [in,out] | prevOSTicks | Caller-kept previous total-OS tick counter. |
| [in,out] | prevOSIdleTicks | Caller-kept previous idle tick counter. |
| [in,out] | prevProcTicks | Caller-kept previous process tick counter. |
Definition at line 3415 of file Utils.cpp.
References GetProcAndOSCPUUsage().
Referenced by GetProcAndOSCPUUsage().
| bool cmlabs::utils::GetProcAndOSCPUUsage | ( | uint32 | osProcID, |
| double & | procPercentUse, | ||
| double & | osPercentUse, | ||
| uint64 & | prevOSTicks, | ||
| uint64 & | prevOSIdleTicks, | ||
| uint64 & | prevProcTicks ) |
As GetProcAndOSCPUUsage() above, but for an arbitrary process.
| osProcID | OS process id. | |
| [out] | procPercentUse | Process CPU usage in percent. |
| [out] | osPercentUse | Total OS CPU usage in percent. |
| [in,out] | prevOSTicks | Caller-kept previous total-OS tick counter. |
| [in,out] | prevOSIdleTicks | Caller-kept previous idle tick counter. |
| [in,out] | prevProcTicks | Caller-kept previous process tick counter. |
Definition at line 3424 of file Utils.cpp.
References FALSE, and StringFormat().
| bool cmlabs::utils::GetProcessCPUTicks | ( | uint32 | osProcID, |
| uint64 & | ticks ) |
| bool cmlabs::utils::GetProcessCPUTicks | ( | uint64 & | ticks | ) |
| uint8 cmlabs::utils::GetProcessStatus | ( | uint32 | proc, |
| int & | returncode ) |
Poll a child started with NewProcess().
| proc | Process id from NewProcess(). | |
| [out] | returncode | Exit code when terminated. |
Definition at line 4128 of file Utils.cpp.
References PROC_ERROR, PROC_RUNNING, and PROC_TERMINATED.
Referenced by WaitForProcess().
| std::list< std::string > cmlabs::utils::GetProgramTrace | ( | ) |
Capture the current call stack.
Definition at line 2855 of file Utils.cpp.
Referenced by PrintProgramTrace().
| Semaphore * cmlabs::utils::GetSemaphore | ( | const char * | name, |
| bool | autocreate = true ) |
Look up (and optionally create) a named semaphore in the global registry.
| name | Semaphore name. |
| autocreate | Create when missing. |
Definition at line 726 of file Utils.cpp.
References SharedMemorySemaphoreMap, and SharedMemorySemaphoreMapMutex.
| uint32 cmlabs::utils::GetSharedSystemInstance | ( | ) |
Get the current shared-system instance number.
Definition at line 943 of file Utils.cpp.
References SharedSystemInstance.
| bool cmlabs::utils::GetThreadPriority | ( | ThreadHandle | hThread, |
| uint16 | priority ) |
Query a thread's scheduling priority.
| hThread | Thread handle. |
| priority | Receives/compares the CMSDK priority value. |
Definition at line 3590 of file Utils.cpp.
References FromOSPriority(), GetThreadPriority(), and ThreadHandle.
Referenced by GetThreadPriority().
| uint32 cmlabs::utils::GetThreadStatColAbility | ( | ) |
Report this platform's capability for per-thread CPU statistics collection.
Definition at line 3198 of file Utils.cpp.
References THREAD_STATS_ADHOC, THREAD_STATS_AUTO, and THREAD_STATS_OFF.
Referenced by cmlabs::ThreadManager::resizeThreadStorage().
| uint64 cmlabs::utils::hton64 | ( | const uint64_t * | input | ) |
Convert a 64-bit value from host to network byte order.
| input | Host-order value. |
References ThreadHandle.
| bool cmlabs::utils::IsThreadRunning | ( | ThreadHandle | hThread | ) |
Check whether a thread is still alive.
| hThread | Thread handle. |
Definition at line 3168 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::isThreadRunning().
| const char * cmlabs::utils::laststristr | ( | const char * | str1, |
| const char * | str2 ) |
Case-insensitive laststrstr().
Definition at line 7466 of file Utils.cpp.
References stricmp, and strnicmp.
Referenced by TextEndsWith().
| const char * cmlabs::utils::laststrstr | ( | const char * | str1, |
| const char * | str2 ) |
Find the last occurrence of str2 in str1.
Definition at line 7441 of file Utils.cpp.
Referenced by AddToJSONRoot(), cmlabs::JSONM::getJSON(), cmlabs::JSONM::isValid(), and TextEndsWith().
| bool cmlabs::utils::LeaveMutex | ( | const char * | name | ) |
Release a named global mutex previously acquired with EnterMutex().
| name | Mutex name. |
Definition at line 689 of file Utils.cpp.
References SharedMemoryMutexMap, and SharedMemoryMutexMapMutex.
| bool cmlabs::utils::MoveConsoleWindow | ( | int32 | x = -1, |
| int32 | y = -1, | ||
| int32 | w = -1, | ||
| int32 | h = -1 ) |
| 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.
| cmdline | Command line. |
| initdir | Working directory (NULL = inherit). |
| title | Console title (Windows). |
| x,y,w,h | Initial console window geometry (-1 = default; Windows only). |
Definition at line 4001 of file Utils.cpp.
References DeleteCommandline(), LOG_SYSTEM, LogPrint, SplitCommandline(), StringFormat(), and TRUE.
Referenced by NewProcessEx().
| uint32 cmlabs::utils::NewProcessEx | ( | const char * | cmdline, |
| const char * | initdir, | ||
| const char * | title, | ||
| const std::map< std::string, std::string > * | env, | ||
| bool | captureOutput, | ||
| bool | ignoreOutput, | ||
| bool | newProcessGroup ) |
Launch a child with environment overrides and optional output capture.
| cmdline | Command line (already substituted). |
| initdir | Working directory (NULL/"" = inherit). |
| title | Console/space title. |
| env | Extra environment variables merged over the parent's (NULL = none). |
| captureOutput | true to redirect the child's stdout/stderr into pipes readable via ReadProcessOutput(). |
| ignoreOutput | true to send the child's stdout/stderr to the null device (ignored unless captureOutput is false). |
| newProcessGroup | true to start the child in its own process group so it can be sent a graceful console break via SendProcessBreak() independently of the parent (recommended for graceful stop). |
Definition at line 4222 of file Utils.cpp.
References LOG_SYSTEM, LogPrint, NewProcess(), StringFormat(), and TRUE.
| uint64 cmlabs::utils::ntoh64 | ( | const uint64 * | input | ) |
Convert a 64-bit value from network to host byte order.
| input | Big-endian value. |
Definition at line 2442 of file Utils.cpp.
Referenced by hton64(), cmlabs::WebsocketData::processHeader(), and cmlabs::WebsocketData::setData().
| char * cmlabs::utils::OpenSharedMemorySegment | ( | const char * | name, |
| uint64 | size ) |
Open and map an existing named shared memory segment.
| name | Global segment name. |
| size | Expected size in bytes. |
Definition at line 2287 of file Utils.cpp.
References FALSE, GetLastOSErrorMessage(), LOG_SYSTEM, LogPrint, MAXSHMEMNAMELEN, SharedMemoryFileHandleMap, SharedMemoryFileHandleMapType, and WINSHMEMSPACE.
Referenced by cmlabs::MemoryRequestConnection::connect(), cmlabs::utils::Event::Event(), cmlabs::PsycloneIndex::GetStatus(), cmlabs::PsycloneIndex::init(), cmlabs::utils::Mutex::Mutex(), cmlabs::ComponentMemory::open(), cmlabs::DataMapsMemory::open(), cmlabs::MasterMemory::open(), cmlabs::ProcessMemory::open(), cmlabs::TemporalMemory::open(), and cmlabs::utils::Semaphore::Semaphore().
| bool cmlabs::utils::PauseThread | ( | ThreadHandle | hThread | ) |
Suspend a thread's execution.
| hThread | Thread handle. |
Definition at line 3098 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::pauseThread().
| void cmlabs::utils::PrintBinary | ( | void * | p, |
| uint32 | size, | ||
| bool | asInt, | ||
| const char * | title ) |
| 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.
| bitfield | Field data. |
| bytesize | Field size in bytes. |
| size | Number of bits. |
| title | Heading text. |
Definition at line 2761 of file Utils.cpp.
References GetBitFieldAsString(), and StringFormat().
Referenced by UnitTest_Utils().
| std::string cmlabs::utils::PrintProgramTrace | ( | uint32 | startLine = 0, |
| uint32 | endLine = 0 ) |
Format the current call stack as printable text.
| startLine | First stack frame to include (0 = top). |
| endLine | Last frame (0 = all). |
Definition at line 2840 of file Utils.cpp.
References GetProgramTrace().
| bool cmlabs::utils::ReadProcessOutput | ( | uint32 | proc, |
| std::string & | out, | ||
| std::string & | err ) |
Read any pending captured stdout/stderr from a child launched with captureOutput=true.
Non-blocking. Appends raw bytes (may be partial lines) to the supplied strings.
| proc | Process id. | |
| [out] | out | Appended stdout bytes. |
| [out] | err | Appended stderr bytes. |
| bool cmlabs::utils::ReapThread | ( | ThreadHandle & | hThread | ) |
Definition at line 2976 of file Utils.cpp.
References ThreadHandle.
| bool cmlabs::utils::RenameConsoleWindow | ( | const char * | name, |
| bool | prepend = false ) |
Set the console window title.
| name | New title. |
| prepend | Prepend to the existing title instead of replacing it. |
Definition at line 3740 of file Utils.cpp.
References StringFormat().
| bool cmlabs::utils::Reset32BitField | ( | char * | bitfield, |
| uint32 | bytesize ) |
Zero the whole bitfield, marking every bit as free.
| bitfield | Field data. |
| bytesize | Field size in bytes. |
Definition at line 2467 of file Utils.cpp.
Referenced by UnitTest_Utils().
| 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.
| cmdline | Command line to execute. | |
| initdir | Working directory (NULL = inherit). | |
| timeout | Max run time in milliseconds before the child is killed. | |
| [out] | stdoutString | Captured standard output. |
| [out] | stderrString | Captured standard error. |
Definition at line 3808 of file Utils.cpp.
References FALSE, cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), PROCBUFSIZE, StringFormat(), and TRUE.
Referenced by GetComputerName().
| bool cmlabs::utils::SendProcessBreak | ( | uint32 | proc, |
| int | sig ) |
Attempt a graceful stop: POSIX sends the given signal; Windows posts a CTRL_BREAK to the child's process group (requires newProcessGroup=true at launch) and falls back to nothing if unsupported.
Callers should wait, then EndProcess() as the forceful fallback.
| proc | Process id. |
| sig | POSIX signal number (ignored on Windows). |
| bool cmlabs::utils::SetBit | ( | uint32 | loc, |
| bit | value, | ||
| char * | bitfield, | ||
| uint32 | bytesize ) |
Set bit loc to value.
| loc | Bit index. |
| value | 0 or 1. |
| bitfield | Field data. |
| bytesize | Field size in bytes. |
Definition at line 2597 of file Utils.cpp.
Referenced by cmlabs::MemoryRequestQueues::AddNewRequest(), cmlabs::MemoryRequestQueues::CloseRequest(), cmlabs::GenericMemoryMap< T, ID >::CreateEntry(), cmlabs::GenericMemoryMap< T, ID >::CreateFirstFreeEntry(), cmlabs::ThreadManager::createThread(), cmlabs::GenericMemoryMap< T, ID >::DeleteEntry(), cmlabs::MemoryRequestQueues::InitRequestMap(), cmlabs::TemporalMemory::insertMessage(), and UnitTest_Utils().
| bool cmlabs::utils::SetBitN | ( | uint32 | loc, |
| uint32 | num, | ||
| bit | value, | ||
| char * | bitfield, | ||
| uint32 | bytesize ) |
Set num consecutive bits starting at loc to value.
| loc | First bit index. |
| num | Run length. |
| value | 0 or 1. |
| bitfield | Field data. |
| bytesize | Field size in bytes. |
Definition at line 2629 of file Utils.cpp.
References MAXVALUINT16, and MAXVALUINT32.
Referenced by cmlabs::TemporalMemory::insertMessage(), and UnitTest_Utils().
| bool cmlabs::utils::SetSharedSystemInstance | ( | uint32 | inst | ) |
Set the instance number used to namespace shared OS objects, allowing several independent CMSDK systems on one host.
| inst | Instance number (0 = default namespace). |
Definition at line 938 of file Utils.cpp.
References SharedSystemInstance.
| bool cmlabs::utils::SetThreadPriority | ( | ThreadHandle | hThread, |
| uint16 | priority ) |
Set a thread's scheduling priority.
| hThread | Thread handle. |
| priority | CMSDK priority value (converted via ToOSPriority()). |
Definition at line 3613 of file Utils.cpp.
References SetThreadPriority(), ThreadHandle, and ToOSPriority().
Referenced by SetThreadPriority().
| bool cmlabs::utils::SignalEvent | ( | const char * | name | ) |
Signal a named global event.
| name | Event name. |
Definition at line 904 of file Utils.cpp.
References SharedMemoryEventMap, and SharedMemoryEventMapMutex.
| bool cmlabs::utils::SignalSemaphore | ( | const char * | name | ) |
Signal a named global semaphore.
| name | Semaphore name. |
Definition at line 804 of file Utils.cpp.
References SharedMemorySemaphoreMap, SharedMemorySemaphoreMapMutex, and cmlabs::utils::Semaphore::signal().
Referenced by cmlabs::MemoryRequestConnection::makeRequest(), cmlabs::MemoryRequestConnection::replyToRequest(), cmlabs::DataMapsMemory::setRequestStatus(), and cmlabs::DataMapsMemory::setRequestStatus().
| bool cmlabs::utils::SignalThread | ( | ThreadHandle | hThread, |
| int32 | signal ) |
Send a signal to a thread (POSIX pthread_kill; limited emulation on Windows).
| hThread | Thread handle. |
| signal | Signal number. |
Definition at line 3704 of file Utils.cpp.
References ThreadHandle.
| bool cmlabs::utils::Sleep | ( | uint32 | ms | ) |
Suspend the calling thread.
| ms | Sleep duration in milliseconds. |
Definition at line 2830 of file Utils.cpp.
References Sleep().
Referenced by cmlabs::TCPConnection::connect(), CreateThread(), cmlabs::NetworkChannel::endConnection(), cmlabs::NetworkChannel::HTTPClientRun(), cmlabs::Internal_RetrieveTest(), cmlabs::Internal_SignalPing(), cmlabs::Internal_SignalPong(), cmlabs::NetworkChannel::MessageConnectionRun(), cmlabs::PsyTime_UnitTest(), cmlabs::HTTPProtocol::ReceiveHTTPRequest(), cmlabs::HTTPProtocol::ReceiveWebsocketData(), cmlabs::TestRequestClient::run(), cmlabs::TestWebRequestClient::run(), cmlabs::TestWebSocketRequestClient::run(), cmlabs::NetworkChannel::shutdown(), cmlabs::PsySpace::shutdown(), cmlabs::ThreadManager::shutdown(), Sleep(), cmlabs::Runnable::stop(), cmlabs::NetworkChannel::stopListener(), cmlabs::StopProcessTestThread(), cmlabs::NetworkChannel::TelnetServerRun(), cmlabs::ThreadManager::terminateThread(), cmlabs::NetworkManager::TestHTTP(), cmlabs::ThreadManager::threadMonitoring(), cmlabs::MessageIndex::UnitTest(), cmlabs::NetworkManager::UnitTest(), cmlabs::ProcessMemory::UnitTest(), cmlabs::RequestGateway::UnitTest(), cmlabs::TemporalMemory::UnitTest(), cmlabs::ThreadManager::UnitTest(), cmlabs::RequestClient::waitForConnection(), cmlabs::MessagePlayer::waitForNextMessage(), WaitForProcess(), WaitForThreadToFinish(), cmlabs::MemoryManager::~MemoryManager(), and cmlabs::RequestGateway::~RequestGateway().
| bool cmlabs::utils::StartDrumBeat | ( | uint32 | id | ) |
Start (or resume) a previously created drum beat.
| id | Beat id. |
Definition at line 535 of file Utils.cpp.
References cmlabs::utils::DrumBeatInfo::createdTime, DrumBeatCallback(), DrumBeatMap, cmlabs::utils::DrumBeatInfo::handle, cmlabs::utils::DrumBeatInfo::id, cmlabs::utils::DrumBeatInfo::interval, LOG_SYSTEM, LogPrint, and cmlabs::utils::DrumBeatInfo::started.
Referenced by CreateDrumBeat().
| bool cmlabs::utils::StopDrumBeat | ( | uint32 | id | ) |
Stop a running drum beat without destroying it.
| id | Beat id. |
Definition at line 581 of file Utils.cpp.
References cmlabs::utils::DrumBeatInfo::createdTime, DrumBeatMap, cmlabs::utils::DrumBeatInfo::handle, cmlabs::utils::DrumBeatInfo::id, LOG_SYSTEM, LogPrint, and cmlabs::utils::DrumBeatInfo::started.
Referenced by DrumBeatCallback(), and EndDrumBeat().
| uint32 cmlabs::utils::strcpyavail | ( | char * | dst, |
| const char * | src, | ||
| uint32 | maxlen, | ||
| bool | copyAvailable ) |
Bounded strcpy that always NUL-terminates.
| dst | Destination buffer. |
| src | Source. |
| maxlen | Destination capacity. |
| copyAvailable | When true, copy as much as fits; when false, copy nothing unless the whole string fits. |
Definition at line 6314 of file Utils.cpp.
Referenced by cmlabs::MessagePlayer::addMessage(), BytifySizes(), cmlabs::PostSpec::contentFromXML(), 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::ComponentMemory::createParameter(), cmlabs::ObsString::extractDataFromMessage(), cmlabs::ObsString::extractRangeFrom(), cmlabs::ObsString::extractRangeTo(), cmlabs::FilterSpec::fromXML(), cmlabs::PostSpec::fromXML(), cmlabs::QuerySpec::fromXML(), cmlabs::RetrieveSpec::fromXML(), cmlabs::SignalSpec::fromXML(), cmlabs::ComponentMemory::getComponentName(), GetComputerName(), cmlabs::MemoryMaps::GetCrankFunction(), cmlabs::DataMapsMemory::getCrankFunction(), cmlabs::DataMapsMemory::getCrankLanguage(), cmlabs::MemoryMaps::GetCrankLibraryFilename(), cmlabs::DataMapsMemory::getCrankLibraryFilename(), cmlabs::MemoryMaps::GetCrankScript(), cmlabs::DataMapsMemory::getCrankScript(), cmlabs::GetDateAndTime(), cmlabs::GenericMemoryMap< T, ID >::GetEntryName(), GetFileList(), GetLocalInterfaces(), cmlabs::html::GetMimeType(), cmlabs::ComponentMemory::getParameter(), cmlabs::ProcessMemory::getProcessCommandLine(), cmlabs::ProcessMemory::getProcessName(), GetSocketError(), GetSystemArchitecture(), GetSystemOSName(), GetSystemOSVersion(), cmlabs::GetTimeFromString(), cmlabs::MemoryRequestServer::init(), LookupHostname(), cmlabs::opendir(), cmlabs::PrintTimeDif(), cmlabs::ComponentData::RecordRemoteComponent(), cmlabs::ComponentData::ReserveComponentID(), cmlabs::PsyAPI::retrieveStringParam(), cmlabs::utils::Semaphore::Semaphore(), cmlabs::PsyAPI::setCommandlineBasedir(), cmlabs::MemoryMaps::SetCrankScript(), cmlabs::LogSystem::SetLogFileOutput(), cmlabs::ComponentMemory::setParameter(), cmlabs::ProcessMemory::setProcessCommandLine(), cmlabs::DataMessage::setRawData(), StringFormatInto(), cmlabs::ComponentMemory::UnitTest(), cmlabs::MessageIndex::UnitTest(), cmlabs::TriggerSpec::UnitTest(), cmlabs::PsyAPI::waitForNewMessage(), and cmlabs::MessagePlayer::waitForNextMessage().
| const char * cmlabs::utils::stristr | ( | const char * | str, |
| const char * | substr, | ||
| uint32 | len = 0 ) |
Case-insensitive strstr.
| str | Haystack. |
| substr | Needle. |
| len | Max haystack bytes to scan (0 = until NUL). |
str, or NULL. Definition at line 6293 of file Utils.cpp.
Referenced by cmlabs::AESCheckBufferForCompatibility(), cmlabs::RequestGateway::callInternalAPI(), cmlabs::HTTPProtocol::CheckBufferForCompatibility(), cmlabs::HTTPRequest::convertToMessage(), cmlabs::RESTParser::extractArrayParameters(), cmlabs::RESTParser::extractArrayParameters(), cmlabs::RESTParser::extractParameters(), cmlabs::RESTParser::extractParameters(), cmlabs::RequestGateway::getBestExecutorID(), cmlabs::html::IsMimeBinary(), cmlabs::RESTParser::parseRequest(), cmlabs::RESTParser::parseRequest(), cmlabs::MessagePlayer::printAllString(), cmlabs::HTTPRequest::processHeader(), cmlabs::RequestExecutor::receiveMessage(), cmlabs::RequestGateway::replyToClient(), cmlabs::SSLCheckBufferForCompatibility(), and TextStartsWith().
| bool cmlabs::utils::TerminateThread | ( | ThreadHandle | hThread | ) |
Forcibly kill a thread.
| hThread | Thread handle. |
Definition at line 3068 of file Utils.cpp.
References LOG_SYSTEM, LogPrint, TerminateThread(), and ThreadHandle.
Referenced by cmlabs::ThreadManager::interruptThread(), TerminateThread(), and cmlabs::ThreadManager::terminateThread().
| bool cmlabs::utils::TextEndsWith | ( | const char * | str, |
| const char * | end, | ||
| bool | caseSensitive = true ) |
Test whether str ends with end.
| str | Text. |
| end | Suffix. |
| caseSensitive | Compare case-sensitively when true. |
Definition at line 7491 of file Utils.cpp.
References laststristr(), and laststrstr().
Referenced by GetFileList(), cmlabs::DataMessage::getKeyType(), cmlabs::html::GetMimeType(), cmlabs::MessagePlayer::initRead(), cmlabs::MessagePlayer::initWrite(), cmlabs::DataMessage::isArrayContent(), cmlabs::DataMessage::isMapContent(), and cmlabs::utils::Library::patchLibraryFilename().
| uint32 cmlabs::utils::TextReplaceCharsInPlace | ( | char * | str, |
| uint32 | size, | ||
| char | find, | ||
| char | replace ) |
| bool cmlabs::utils::TextStartsWith | ( | const char * | str, |
| const char * | start, | ||
| bool | caseSensitive = true ) |
Test whether str starts with start.
| str | Text. |
| start | Prefix. |
| caseSensitive | Compare case-sensitively when true. |
Definition at line 7498 of file Utils.cpp.
References stristr().
Referenced by cmlabs::RequestGateway::callInternalAPI(), cmlabs::HTTPRequest::createWebsocketRequest(), cmlabs::DataMessage::getArraySize(), cmlabs::DataMessage::getAsFloatArray(), cmlabs::DataMessage::getAsFloatMap(), cmlabs::DataMessage::getAsIntArray(), cmlabs::DataMessage::getAsIntMap(), cmlabs::DataMessage::getAsStringArray(), cmlabs::DataMessage::getAsStringMap(), cmlabs::DataMessage::getAttachedMessageArray(), cmlabs::DataMessage::getAttachedMessageMap(), cmlabs::HTTPRequest::getBasicAuthorization(), cmlabs::DataMessage::getDoubleArray(), cmlabs::DataMessage::getDoubleMap(), cmlabs::DataMessage::getFloatArray(), cmlabs::DataMessage::getFloatMap(), cmlabs::DataMessage::getIntArray(), cmlabs::DataMessage::getIntMap(), cmlabs::DataMessage::getKeyType(), cmlabs::DataMessage::getMapSize(), cmlabs::DataMessage::getStringArray(), cmlabs::DataMessage::getStringMap(), cmlabs::DataMessage::getTimeArray(), cmlabs::DataMessage::getTimeMap(), cmlabs::Internal_MessageScript(), cmlabs::DataMessage::isArrayContent(), cmlabs::DataMessage::isMapContent(), cmlabs::HTTPRequest::parseContentChunk(), and cmlabs::utils::Library::patchLibraryFilename().
|
static |
POSIX signal-based timer callback trampoline (SIGEV_SIGNAL); routes the expiry into the owning Timer's trigger queue.
Definition at line 1854 of file Utils.cpp.
References cmlabs::utils::TimerSchedule::globalID, cmlabs::utils::TimerSchedule::id, cmlabs::utils::Timer::timers, and cmlabs::utils::Timer::triggerTimer().
Referenced by cmlabs::utils::Timer::addTimer().
| int cmlabs::utils::ToOSPriority | ( | int | pri | ) |
Map a CMSDK priority value to the platform's native priority scale.
| pri | CMSDK priority. |
Definition at line 3632 of file Utils.cpp.
Referenced by SetThreadPriority().
| bool cmlabs::utils::TryReapThread | ( | ThreadHandle & | hThread | ) |
Definition at line 2992 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::shutdown(), cmlabs::ThreadManager::terminateThread(), and cmlabs::ThreadManager::threadMonitoring().
| bool cmlabs::utils::UnitTest_Timer | ( | ) |
Self test for the Timer class.
Definition at line 1867 of file Utils.cpp.
References cmlabs::utils::Timer::addTimer(), cmlabs::unittest::detail(), cmlabs::unittest::fail(), cmlabs::GetTimeNow(), cmlabs::unittest::metric(), cmlabs::unittest::progress(), and cmlabs::utils::Timer::waitForTimer().
Referenced by cmlabs::Test_Timer().
| bool cmlabs::utils::UnitTest_Utils | ( | ) |
Aggregate self test for miscellaneous utils functionality.
Definition at line 1931 of file Utils.cpp.
References BITFREE, BITOCCUPIED, Calc32BitFieldSize(), cmlabs::unittest::detail(), cmlabs::unittest::fail(), GetFirstFreeBitLoc(), GetFirstFreeBitLocN(), GetLastOccupiedBitLoc(), PrintBitFieldString(), cmlabs::unittest::progress(), Reset32BitField(), SetBit(), and SetBitN().
Referenced by cmlabs::Test_Utils().
| bool cmlabs::utils::UtilsTest | ( | ) |
Run the built-in self test of the utils module.
Run the built-in self test of the utils module (duplicate declaration).
Definition at line 6216 of file Utils.cpp.
References GetLocalHostname(), GetLocalInterfaces(), GetLocalIPAddress(), GetLocalIPAddresses(), and LOCALHOSTIP.
| uint8 cmlabs::utils::WaitForProcess | ( | uint32 | proc, |
| uint32 | timeout, | ||
| int & | returncode ) |
Wait for a child to exit.
| proc | Process id. | |
| timeout | Max wait in ms. | |
| [out] | returncode | Exit code. |
Definition at line 4395 of file Utils.cpp.
References GetProcessStatus(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), PROC_ERROR, PROC_RUNNING, PROC_TERMINATED, PROC_TIMEOUT, and Sleep().
| bool cmlabs::utils::WaitForSemaphore | ( | const char * | name, |
| uint32 | ms, | ||
| bool | autocreate = true ) |
Wait on a named global semaphore.
| name | Semaphore name. |
| ms | Timeout in ms. |
| autocreate | Create when missing. |
Definition at line 765 of file Utils.cpp.
References SharedMemorySemaphoreMap, SharedMemorySemaphoreMapMutex, and cmlabs::utils::Semaphore::wait().
Referenced by cmlabs::DataMapsMemory::waitForRequestReply().
| bool cmlabs::utils::WaitForThreadToFinish | ( | ThreadHandle | hThread, |
| uint32 | timeoutMS = 0 ) |
Join a thread.
| hThread | Thread handle. |
| timeoutMS | Max wait in ms (0 = wait forever). |
Definition at line 3018 of file Utils.cpp.
References CalcTimeout(), Sleep(), and ThreadHandle.
| bool cmlabs::utils::WaitNextEvent | ( | const char * | name, |
| uint32 | ms, | ||
| bool | autocreate = true ) |
Wait for the next signal on a named global event.
| name | Event name. |
| ms | Timeout in ms. |
| autocreate | Create when missing. |
|
static |
Definition at line 441 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), CreateDrumBeat(), EndDrumBeat(), StartDrumBeat(), and StopDrumBeat().
|
static |
Definition at line 594 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyEvent(), SignalEvent(), and WaitForNextEvent().
|
static |
Definition at line 593 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyEvent(), SignalEvent(), and WaitForNextEvent().
|
static |
Definition at line 395 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), CloseSharedMemorySegment(), CreateSharedMemorySegment(), and OpenSharedMemorySegment().
|
static |
Definition at line 588 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyMutex(), EnterMutex(), and LeaveMutex().
|
static |
Definition at line 587 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyMutex(), EnterMutex(), and LeaveMutex().
|
static |
Definition at line 591 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroySemaphore(), GetSemaphore(), SignalSemaphore(), and WaitForSemaphore().
|
static |
Definition at line 590 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroySemaphore(), GetSemaphore(), SignalSemaphore(), and WaitForSemaphore().
|
static |
Definition at line 397 of file Utils.h.
Referenced by GetSharedSystemInstance(), and SetSharedSystemInstance().