|
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::ProcessData |
| POSIX capture bookkeeping for children started via NewProcessEx(captureOutput). 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... | |
| struct | cmlabs::utils::ProcessWaitInfo |
| Snapshot from ProbeProcessWait(): is the child (group) alive, is it blocked reading stdin, and how much CPU has the group burned so far (caller diffs successive samples). 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 |
| typedef std::pair< uint32, ProcessData * > | cmlabs::utils::Proc_Pair |
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 |
| static std::map< uint32, ProcessData * > * | cmlabs::utils::ProcessInformationMap = 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. | |
Threading and CPU statistics | |
| typedef void(* | cmlabs::utils::ShutdownSignalCallback) (int sig, int count) |
| Callback invoked (on the dedicated signal thread) when a graceful-shutdown signal is caught. | |
| 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::BlockShutdownSignals () |
| Block the graceful-shutdown signals (SIGINT, SIGTERM, SIGHUP) on the CALLING thread. | |
| bool | cmlabs::utils::StartSignalThread (ShutdownSignalCallback cb) |
| Start the dedicated signal-handling thread (POSIX only). | |
| bool | cmlabs::utils::StopSignalThread () |
| Stop the dedicated signal thread and join it. | |
| 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). | |
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. | |
| bool | cmlabs::utils::UnitTest_ProbeProcessWait () |
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. | |
| void | cmlabs::utils::ClearStaleSharedSegments (uint16 port) |
| Remove stale OS shared-memory/semaphore objects left by a crashed node on this port. | |
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. | |
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, int posixParentDeathSig=0, bool posixUseShell=false) |
| 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::WriteProcessInput (uint32 proc, const char *data, uint32 len) |
| Write to the stdin of a child launched with captureOutput=true (T1.1 step 2.7c). | |
| bool | cmlabs::utils::CloseProcessInput (uint32 proc) |
| Close a child's stdin, delivering EOF (T1.1 step 2.7c). | |
| void | cmlabs::utils::ReleaseProcessCapture (uint32 proc) |
| POSIX only: release the captured stdout/stderr read-pipes recorded for a child by NewProcessEx(captureOutput=true), WITHOUT signalling or reaping the child. | |
| 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. | |
| bool | cmlabs::utils::ProbeProcessWait (uint32 pid, ProcessWaitInfo &out) |
| Probe whether a child process (group) appears blocked reading stdin (fd 0). | |
Terminal-mode child launch (T1.1 step 2.7d, POSIX PTY; Windows ConPTY lands in 2.7e) | |
A child launched here runs with a real controlling terminal (isatty()==true): stdout+stderr are MERGED into one terminal stream (inherent to terminals) and libc line-buffers instead of fully-buffering, so output appears promptly. Lifecycle (reap/kill) is via GetProcessStatus()/WaitForProcess()/EndProcess() on the returned pid, exactly like NewProcessEx children; only the master-side terminal fd is bookkept here. NOTE: on child exit a PTY master read reports EIO rather than a clean EOF - ReadProcessTerminal treats that as normal end-of-stream, never as an error. | |
| uint32 | cmlabs::utils::NewProcessTerminal (const char *cmdline, const char *initdir, const std::map< std::string, std::string > *env, uint16 cols=0, uint16 rows=0) |
| Launch a child on a new pseudo-terminal (POSIX: posix_openpt + fork; child setsid() + TIOCSCTTY so it owns the terminal and leads its own process group for group kill). | |
| bool | cmlabs::utils::ReadProcessTerminal (uint32 proc, std::string &out, bool &eofOut) |
| Non-blocking read of the merged terminal stream. | |
| bool | cmlabs::utils::WriteProcessTerminal (uint32 proc, const char *data, uint32 len) |
| Write bytes to the child's terminal input (its stdin). | |
| bool | cmlabs::utils::ResizeProcessTerminal (uint32 proc, uint16 cols, uint16 rows) |
| Resize the pseudo-terminal (TIOCSWINSZ + SIGWINCH to the child's group). | |
| void | cmlabs::utils::CloseProcessTerminal (uint32 proc) |
| Close the master side (terminal hangup: the child's foreground group gets SIGHUP and any blocked terminal read ends). | |
| #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 1278 of file Utils.h.
Referenced by cmlabs::utils::GetProcessStatus(), and cmlabs::utils::WaitForProcess().
| #define PROC_TERMINATED 1 |
Definition at line 1276 of file Utils.h.
Referenced by cmlabs::ConcRunCrossProcess(), cmlabs::utils::GetProcessStatus(), and cmlabs::utils::WaitForProcess().
| #define PROC_TIMEOUT 4 |
Definition at line 1279 of file Utils.h.
Referenced by cmlabs::utils::WaitForProcess().
| #define PROCBUFSIZE 4096 |
Definition at line 1293 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<uint32, ProcessData*> cmlabs::utils::Proc_Pair |
| 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 |
| typedef void(* cmlabs::utils::ShutdownSignalCallback) (int sig, int count) |
Callback invoked (on the dedicated signal thread) when a graceful-shutdown signal is caught.
| sig | Signal number received (SIGINT/SIGTERM/SIGHUP). |
| count | 1-based count of graceful-shutdown signals seen so far this run, so the app can escalate (e.g. hard-exit after repeated CTRL+C). Runs in ordinary thread context (NOT an async-signal handler), so it may call normal library code. Keep it quick and non-blocking: record intent (set a flag / post an event) and return; the actual teardown runs on the main thread. |
| int32 cmlabs::utils::AtomicDecrement32 | ( | int32 volatile & | v | ) |
Atomically decrement a 32-bit value.
| v | Value to modify. |
Definition at line 3101 of file Utils.cpp.
Referenced by _wrap_AtomicDecrement32().
| int64 cmlabs::utils::AtomicDecrement64 | ( | int64 volatile & | v | ) |
Atomically decrement a 64-bit value.
| v | Value to modify. |
Definition at line 3111 of file Utils.cpp.
Referenced by _wrap_AtomicDecrement64().
| int32 cmlabs::utils::AtomicIncrement32 | ( | int32 volatile & | v | ) |
Atomically increment a 32-bit value.
| v | Value to modify. |
Definition at line 3081 of file Utils.cpp.
Referenced by _wrap_AtomicIncrement32().
| int64 cmlabs::utils::AtomicIncrement64 | ( | int64 volatile & | v | ) |
Atomically increment a 64-bit value.
| v | Value to modify. |
Definition at line 3091 of file Utils.cpp.
Referenced by _wrap_AtomicIncrement64().
| bool cmlabs::utils::BlockShutdownSignals | ( | ) |
Block the graceful-shutdown signals (SIGINT, SIGTERM, SIGHUP) on the CALLING thread.
Definition at line 3433 of file Utils.cpp.
References SignalShutdownSigset().
Referenced by _wrap_BlockShutdownSignals().
| 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 2723 of file Utils.cpp.
Referenced by _wrap_Calc32BitFieldSize(), 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 3233 of file Utils.cpp.
References ThreadHandle.
| void cmlabs::utils::ClearStaleSharedSegments | ( | uint16 | port | ) |
Remove stale OS shared-memory/semaphore objects left by a crashed node on this port.
Linux: unlinks /dev/shm entries (Shmem_*, sem.Semaphore_*) containing the delimited port token. macOS: unlinks /tmp/Psyclone_Shmem_* files containing the delimited port token. Windows: no-op.
| port | The node port; only segments whose name contains the port as a delimited token are removed. |
Definition at line 2678 of file Utils.cpp.
References ClearSegmentsIn(), LOG_SYSTEM, and LogPrint.
Referenced by _wrap_ClearStaleSharedSegments(), and cmlabs::MemoryManager::create().
| bool cmlabs::utils::CloseProcessInput | ( | uint32 | proc | ) |
Close a child's stdin, delivering EOF (T1.1 step 2.7c).
| proc | Process id. |
Definition at line 5331 of file Utils.cpp.
References ProcessInformationMap.
Referenced by _wrap_CloseProcessInput().
| void cmlabs::utils::CloseProcessTerminal | ( | uint32 | proc | ) |
Close the master side (terminal hangup: the child's foreground group gets SIGHUP and any blocked terminal read ends).
Does NOT reap the child - callers still waitpid via GetProcessStatus()/WaitForProcess(). No-op if unknown.
Definition at line 5538 of file Utils.cpp.
References TerminalMasterMap.
Referenced by _wrap_CloseProcessTerminal().
| 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 2604 of file Utils.cpp.
References SharedMemoryFileHandleMap.
Referenced by _wrap_CloseSharedMemorySegment(), 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 3493 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 495 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 2368 of file Utils.cpp.
References GetLastOSErrorMessage(), LOG_SYSTEM, LogPrint, MAXSHMEMNAMELEN, SharedMemoryFileHandleMap, SharedMemoryFileHandleMapType, and WINSHMEMSPACE.
Referenced by _wrap_CreateSharedMemorySegment__SWIG_0(), _wrap_CreateSharedMemorySegment__SWIG_1(), 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 3187 of file Utils.cpp.
References CreateThread(), Sleep(), and ThreadHandle.
Referenced by CreateThread(), cmlabs::ThreadManager::createThread(), and SubmitLaunchRequest().
| bool cmlabs::utils::DestroyEvent | ( | const char * | name | ) |
Destroy a named global event.
| name | Event name. |
Definition at line 939 of file Utils.cpp.
References SharedMemoryEventMap, and SharedMemoryEventMapMutex.
Referenced by _wrap_DestroyEvent().
| bool cmlabs::utils::DestroyMutex | ( | const char * | name | ) |
Destroy a named global mutex and remove it from the registry.
| name | Mutex name. |
Definition at line 724 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 858 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 627 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(). |
Definition at line 4602 of file Utils.cpp.
References ProcessInformationMap, and ReleaseProcessCapture().
Referenced by _wrap_EndProcess(), cmlabs::ConcRunCrossProcess(), and UnitTest_ProbeProcessWait().
| 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 671 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 4066 of file Utils.cpp.
Referenced by _wrap_FromOSPriority(), and 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 2983 of file Utils.cpp.
Referenced by _wrap_GetBit(), and 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 3033 of file Utils.cpp.
Referenced by _wrap_GetBitFieldAsString(), and 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 3596 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 3647 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 3544 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 3524 of file Utils.cpp.
Referenced by _wrap_GetCurrentThreadOSID(), 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 3504 of file Utils.cpp.
Referenced by _wrap_GetCurrentThreadUniqueID(), and cmlabs::ThreadManager::getLocalThreadID().
| bool cmlabs::utils::GetDesktopSize | ( | uint32 & | width, |
| uint32 & | height ) |
Get the primary desktop resolution.
| [out] | width | Pixels. |
| [out] | height | Pixels. |
Definition at line 4106 of file Utils.cpp.
Referenced by _wrap_GetDesktopSize().
| 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 2733 of file Utils.cpp.
Referenced by _wrap_GetFirstFreeBitLoc(), 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 2765 of file Utils.cpp.
References BITFREE, MAXVALUINT16, and MAXVALUINT32.
Referenced by _wrap_GetFirstFreeBitLocN(), 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 3008 of file Utils.cpp.
Referenced by _wrap_GetLastOccupiedBitLoc(), and UnitTest_Utils().
| uint32 cmlabs::utils::GetLocalProcessID | ( | ) |
Get the OS process id of the current process.
Definition at line 4185 of file Utils.cpp.
Referenced by _wrap_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 7515 of file Utils.cpp.
Referenced by _wrap_GetNextLineEnd(), cmlabs::HTTPReply::processHeader(), and cmlabs::HTTPRequest::processHeader().
| bool cmlabs::utils::GetOSCPUUsage | ( | double & | percentUse | ) |
Get the instantaneous total OS CPU usage.
| [out] | percentUse | Usage in percent. |
Definition at line 3919 of file Utils.cpp.
Referenced by _wrap_GetOSCPUUsage().
| 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 3801 of file Utils.cpp.
References GetProcAndOSCPUUsage().
Referenced by _wrap_GetProcAndOSCPUUsage__SWIG_0(), _wrap_GetProcAndOSCPUUsage__SWIG_1(), and 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 3810 of file Utils.cpp.
References FALSE, and StringFormat().
| bool cmlabs::utils::GetProcessCPUTicks | ( | uint32 | osProcID, |
| uint64 & | ticks ) |
| bool cmlabs::utils::GetProcessCPUTicks | ( | uint64 & | ticks | ) |
Get accumulated CPU time of the current process.
| [out] | ticks | Receives CPU time in microseconds. |
Definition at line 3754 of file Utils.cpp.
Referenced by _wrap_GetProcessCPUTicks__SWIG_0(), and _wrap_GetProcessCPUTicks__SWIG_1().
| 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 4519 of file Utils.cpp.
References PROC_ERROR, PROC_RUNNING, PROC_TERMINATED, and ProcessInformationMap.
Referenced by _wrap_GetProcessStatus(), cmlabs::ConcRunCrossProcess(), and WaitForProcess().
| std::list< std::string > cmlabs::utils::GetProgramTrace | ( | ) |
Capture the current call stack.
Definition at line 3146 of file Utils.cpp.
Referenced by _wrap_GetProgramTrace(), and 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 748 of file Utils.cpp.
References SharedMemorySemaphoreMap, and SharedMemorySemaphoreMapMutex.
| uint32 cmlabs::utils::GetSharedSystemInstance | ( | ) |
Get the current shared-system instance number.
Definition at line 965 of file Utils.cpp.
References SharedSystemInstance.
Referenced by _wrap_GetSharedSystemInstance().
| 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 3976 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 3584 of file Utils.cpp.
References THREAD_STATS_ADHOC, THREAD_STATS_AUTO, and THREAD_STATS_OFF.
Referenced by _wrap_GetThreadStatColAbility(), and 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.
Referenced by _wrap_hton64().
| bool cmlabs::utils::IsThreadRunning | ( | ThreadHandle | hThread | ) |
Check whether a thread is still alive.
| hThread | Thread handle. |
Definition at line 3554 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 8649 of file Utils.cpp.
References stricmp, and strnicmp.
Referenced by _wrap_laststristr(), and TextEndsWith().
| const char * cmlabs::utils::laststrstr | ( | const char * | str1, |
| const char * | str2 ) |
Find the last occurrence of str2 in str1.
Definition at line 8624 of file Utils.cpp.
Referenced by _wrap_laststrstr(), 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 711 of file Utils.cpp.
References SharedMemoryMutexMap, and SharedMemoryMutexMapMutex.
| bool cmlabs::utils::MoveConsoleWindow | ( | int32 | x = -1, |
| int32 | y = -1, | ||
| int32 | w = -1, | ||
| int32 | h = -1 ) |
Move/resize the console window.
| x,y | Position (-1 = keep). |
| w,h | Size (-1 = keep). |
Definition at line 4148 of file Utils.cpp.
Referenced by _wrap_MoveConsoleWindow__SWIG_0(), _wrap_MoveConsoleWindow__SWIG_1(), _wrap_MoveConsoleWindow__SWIG_2(), _wrap_MoveConsoleWindow__SWIG_3(), and _wrap_MoveConsoleWindow__SWIG_4().
| 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 4387 of file Utils.cpp.
References DeleteCommandline(), LOG_SYSTEM, LogPrint, ProcessInformationMap, SplitCommandline(), and TRUE.
Referenced by _wrap_NewProcess__SWIG_0(), _wrap_NewProcess__SWIG_1(), _wrap_NewProcess__SWIG_2(), _wrap_NewProcess__SWIG_3(), _wrap_NewProcess__SWIG_4(), _wrap_NewProcess__SWIG_5(), _wrap_NewProcess__SWIG_6(), and cmlabs::ConcRunCrossProcess().
| 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, | ||
| int | posixParentDeathSig = 0, | ||
| bool | posixUseShell = false ) |
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). |
| posixParentDeathSig | POSIX only: if non-zero, the child dies with the parent PROCESS. Linux: PR_SET_PDEATHSIG(sig), armed from a persistent internal launcher thread so it is safe to call from transient threads (PDEATHSIG binds to the launching thread, not process). macOS: emulated via a kqueue nanny + own process group (whole tree gets SIGKILL when the parent exits). 0 = no parent-death signal. Ignored on Windows (use Job Objects). |
| posixUseShell | POSIX only: if true, the child is run as "/bin/sh -c <cmdline>" so shell semantics (redirects, builtins like exit, $VAR expansion, quoting) apply, instead of the default tokenize-and-execvp launch. Ignored on Windows (cmd/CreateProcess already parse the command line). |
Definition at line 5052 of file Utils.cpp.
References cmlabs::utils::PosixLaunchRequest::argv, cmlabs::utils::PosixLaunchRequest::captureOutput, cmlabs::utils::PosixLaunchRequest::cmdline, DeleteCommandline(), cmlabs::utils::PosixLaunchRequest::done, DoPosixForkExec(), cmlabs::utils::PosixLaunchRequest::env, cmlabs::utils::ProcessData::errFD, cmlabs::utils::PosixLaunchRequest::errPipe0, cmlabs::utils::PosixLaunchRequest::errPipe1, cmlabs::utils::PosixLaunchRequest::ignoreOutput, cmlabs::utils::PosixLaunchRequest::initdir, LOG_SYSTEM, LogPrint, cmlabs::utils::PosixLaunchRequest::newProcessGroup, cmlabs::utils::ProcessData::outFD, cmlabs::utils::PosixLaunchRequest::outPipe0, cmlabs::utils::PosixLaunchRequest::outPipe1, cmlabs::utils::PosixLaunchRequest::pid, cmlabs::utils::PosixLaunchRequest::posixParentDeathSig, cmlabs::utils::PosixLaunchRequest::posixUseShell, ProcessInformationMap, SplitCommandline(), SubmitLaunchRequest(), and TRUE.
Referenced by _wrap_NewProcessEx(), _wrap_NewProcessEx__SWIG_0(), _wrap_NewProcessEx__SWIG_1(), _wrap_NewProcessEx__SWIG_2(), and UnitTest_ProbeProcessWait().
| uint32 cmlabs::utils::NewProcessTerminal | ( | const char * | cmdline, |
| const char * | initdir, | ||
| const std::map< std::string, std::string > * | env, | ||
| uint16 | cols = 0, | ||
| uint16 | rows = 0 ) |
Launch a child on a new pseudo-terminal (POSIX: posix_openpt + fork; child setsid() + TIOCSCTTY so it owns the terminal and leads its own process group for group kill).
The command runs via "/bin/sh -c <cmdline>" (shell semantics, matching the CLISession interactive path). Windows: stub returning 0 until ConPTY lands in step 2.7e.
| cmdline | Command line. |
| initdir | Working directory (NULL/"" = inherit). |
| env | Extra environment variables merged over the parent's (NULL = none). |
| cols,rows | Initial terminal size (0,0 = 80x25). |
Definition at line 5405 of file Utils.cpp.
References LOG_SYSTEM, LogPrint, and TerminalMasterMap.
Referenced by _wrap_NewProcessTerminal__SWIG_0(), _wrap_NewProcessTerminal__SWIG_1(), and _wrap_NewProcessTerminal__SWIG_2().
| 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 2702 of file Utils.cpp.
Referenced by _wrap_ntoh64(), 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 2489 of file Utils.cpp.
References FALSE, GetLastOSErrorMessage(), LOG_SYSTEM, LogPrint, MAXSHMEMNAMELEN, SharedMemoryFileHandleMap, SharedMemoryFileHandleMapType, and WINSHMEMSPACE.
Referenced by _wrap_OpenSharedMemorySegment(), 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 3484 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::pauseThread().
| void cmlabs::utils::PrintBinary | ( | void * | p, |
| uint32 | size, | ||
| bool | asInt, | ||
| const char * | title ) |
Hex/decimal dump a memory region to stdout for debugging.
| p | Data. |
| size | Bytes. |
| asInt | Print as integers instead of hex bytes. |
| title | Heading. |
Definition at line 7441 of file Utils.cpp.
Referenced by _wrap_PrintBinary().
| 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 3052 of file Utils.cpp.
References GetBitFieldAsString(), and StringFormat().
Referenced by _wrap_PrintBitFieldString(), and 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 3131 of file Utils.cpp.
References GetProgramTrace().
Referenced by _wrap_PrintProgramTrace__SWIG_0(), _wrap_PrintProgramTrace__SWIG_1(), and _wrap_PrintProgramTrace__SWIG_2().
| bool cmlabs::utils::ProbeProcessWait | ( | uint32 | pid, |
| ProcessWaitInfo & | out ) |
Probe whether a child process (group) appears blocked reading stdin (fd 0).
waitExact is Linux-only: only Linux can name the exact blocking syscall via /proc/<pid>/syscall. On macOS/Windows waitExact is always false and waitingStdin is a heuristic (all threads waiting, fd 0 is a pipe): a network wait or a sleep() is indistinguishable from an stdin wait without waitExact. Windows is a stub until step 2.7c (alive + cpuTimeMs only; waitingStdin always false). Graceful degradation: if OS introspection is unavailable, returns true with waitExact=false.
| pid | Child process id (as returned by NewProcessEx). | |
| [out] | out | Filled snapshot. |
Definition at line 4847 of file Utils.cpp.
References cmlabs::utils::ProcessWaitInfo::alive, cmlabs::closedir(), cmlabs::utils::ProcessWaitInfo::cpuTimeMs, cmlabs::dirent::d_name, cmlabs::opendir(), cmlabs::readdir(), cmlabs::utils::ProcessWaitInfo::waitExact, and cmlabs::utils::ProcessWaitInfo::waitingStdin.
Referenced by _wrap_ProbeProcessWait(), and UnitTest_ProbeProcessWait().
| 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. |
Definition at line 5347 of file Utils.cpp.
References cmlabs::utils::ProcessData::errFD, cmlabs::utils::ProcessData::outFD, and ProcessInformationMap.
Referenced by _wrap_ReadProcessOutput().
| bool cmlabs::utils::ReadProcessTerminal | ( | uint32 | proc, |
| std::string & | out, | ||
| bool & | eofOut ) |
Non-blocking read of the merged terminal stream.
Appends raw bytes to 'out'.
| proc | Process id from NewProcessTerminal(). | |
| [out] | out | Appended terminal bytes. |
| [out] | eofOut | Set true when the stream has ended (child exited/hung up; EIO == normal EOF). |
Definition at line 5474 of file Utils.cpp.
References TerminalMasterFind().
Referenced by _wrap_ReadProcessTerminal().
| bool cmlabs::utils::ReapThread | ( | ThreadHandle & | hThread | ) |
Definition at line 3267 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::joinThread().
| void cmlabs::utils::ReleaseProcessCapture | ( | uint32 | proc | ) |
POSIX only: release the captured stdout/stderr read-pipes recorded for a child by NewProcessEx(captureOutput=true), WITHOUT signalling or reaping the child.
Safe to call after the child has already been reaped (e.g. by GetProcessStatus()/WaitForProcess()), where EndProcess() would risk SIGKILL to a recycled pid. No-op if the pid has no capture entry. Ignored on Windows.
| proc | Process id. |
Definition at line 4584 of file Utils.cpp.
References cmlabs::utils::ProcessData::errFD, cmlabs::utils::ProcessData::outFD, and ProcessInformationMap.
Referenced by _wrap_ReleaseProcessCapture(), and EndProcess().
| 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 4126 of file Utils.cpp.
References StringFormat().
Referenced by _wrap_RenameConsoleWindow__SWIG_0(), and _wrap_RenameConsoleWindow__SWIG_1().
| 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 2727 of file Utils.cpp.
Referenced by _wrap_Reset32BitField(), and UnitTest_Utils().
| bool cmlabs::utils::ResizeProcessTerminal | ( | uint32 | proc, |
| uint16 | cols, | ||
| uint16 | rows ) |
Resize the pseudo-terminal (TIOCSWINSZ + SIGWINCH to the child's group).
Definition at line 5521 of file Utils.cpp.
References TerminalMasterFind().
Referenced by _wrap_ResizeProcessTerminal().
| 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 4194 of file Utils.cpp.
References FALSE, cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), PROCBUFSIZE, StringFormat(), and TRUE.
Referenced by _wrap_RunOSCommand(), and 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). |
Definition at line 5550 of file Utils.cpp.
Referenced by _wrap_SendProcessBreak().
| 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 2888 of file Utils.cpp.
Referenced by _wrap_SetBit(), 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::ThreadManager::finaliseSlot(), 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 2920 of file Utils.cpp.
References MAXVALUINT16, and MAXVALUINT32.
Referenced by _wrap_SetBitN(), 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 960 of file Utils.cpp.
References SharedSystemInstance.
Referenced by _wrap_SetSharedSystemInstance().
| 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 3999 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 926 of file Utils.cpp.
References SharedMemoryEventMap, and SharedMemoryEventMapMutex.
Referenced by _wrap_SignalEvent().
| bool cmlabs::utils::SignalSemaphore | ( | const char * | name | ) |
Signal a named global semaphore.
| name | Semaphore name. |
Definition at line 826 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 4090 of file Utils.cpp.
References ThreadHandle.
| bool cmlabs::utils::Sleep | ( | uint32 | ms | ) |
Suspend the calling thread.
| ms | Sleep duration in milliseconds. |
Definition at line 3121 of file Utils.cpp.
References Sleep().
Referenced by _wrap_Sleep(), cmlabs::ConcResizer(), cmlabs::ConcRunCrossProcess(), cmlabs::ConcRunThreaded(), cmlabs::ConcWriter(), 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(), UnitTest_ProbeProcessWait(), cmlabs::RequestClient::waitForConnection(), cmlabs::MessagePlayer::waitForNextMessage(), WaitForProcess(), WaitForThreadToFinish(), WriteProcessTerminal(), 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 548 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::StartSignalThread | ( | ShutdownSignalCallback | cb | ) |
Start the dedicated signal-handling thread (POSIX only).
| cb | Callback invoked synchronously on the signal thread for each caught graceful-shutdown signal; see ShutdownSignalCallback. |
Definition at line 3445 of file Utils.cpp.
References g_shutdownCallback, g_shutdownSignalCount, g_signalThread, g_signalThreadRunning, g_signalThreadStop, SignalShutdownSigset(), and SignalThreadMain().
Referenced by _wrap_StartSignalThread().
| bool cmlabs::utils::StopDrumBeat | ( | uint32 | id | ) |
Stop a running drum beat without destroying it.
| id | Beat id. |
Definition at line 594 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().
| bool cmlabs::utils::StopSignalThread | ( | ) |
Stop the dedicated signal thread and join it.
Definition at line 3468 of file Utils.cpp.
References g_shutdownCallback, g_signalThread, g_signalThreadRunning, and g_signalThreadStop.
Referenced by _wrap_StopSignalThread().
| 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 7497 of file Utils.cpp.
Referenced by _wrap_strcpyavail(), 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 7476 of file Utils.cpp.
Referenced by _wrap_stristr__SWIG_0(), _wrap_stristr__SWIG_1(), 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 3359 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 8674 of file Utils.cpp.
References laststristr(), and laststrstr().
Referenced by _wrap_TextEndsWith__SWIG_0(), _wrap_TextEndsWith__SWIG_1(), 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 ) |
Replace every occurrence of a character, in place.
| str | Buffer. |
| size | Bytes to scan. |
| find | Character to replace. |
| replace | Replacement. |
Definition at line 8613 of file Utils.cpp.
Referenced by _wrap_TextReplaceCharsInPlace().
| 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 8681 of file Utils.cpp.
References stristr().
Referenced by _wrap_TextStartsWith__SWIG_0(), _wrap_TextStartsWith__SWIG_1(), 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 1996 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 4018 of file Utils.cpp.
Referenced by _wrap_ToOSPriority(), and SetThreadPriority().
| bool cmlabs::utils::TryReapThread | ( | ThreadHandle & | hThread | ) |
Definition at line 3283 of file Utils.cpp.
References ThreadHandle.
Referenced by cmlabs::ThreadManager::shutdown(), cmlabs::ThreadManager::terminateThread(), and cmlabs::ThreadManager::threadMonitoring().
| bool cmlabs::utils::UnitTest_ProbeProcessWait | ( | ) |
Definition at line 2076 of file Utils.cpp.
References cmlabs::utils::ProcessWaitInfo::alive, cmlabs::utils::ProcessWaitInfo::cpuTimeMs, cmlabs::unittest::detail(), EndProcess(), cmlabs::unittest::fail(), NewProcessEx(), ProbeProcessWait(), cmlabs::unittest::progress(), Sleep(), cmlabs::utils::ProcessWaitInfo::waitExact, WaitForProcess(), and cmlabs::utils::ProcessWaitInfo::waitingStdin.
Referenced by _wrap_UnitTest_ProbeProcessWait(), and cmlabs::Test_ProbeProcessWait().
| bool cmlabs::utils::UnitTest_Timer | ( | ) |
Self test for the Timer class.
Definition at line 2009 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 2133 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 _wrap_UnitTest_Utils(), and 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 7399 of file Utils.cpp.
References GetLocalHostname(), GetLocalInterfaces(), GetLocalIPAddress(), GetLocalIPAddresses(), and LOCALHOSTIP.
Referenced by _wrap_UtilsTest().
| 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 5561 of file Utils.cpp.
References GetProcessStatus(), cmlabs::GetTimeAgeMS(), cmlabs::GetTimeNow(), PROC_ERROR, PROC_RUNNING, PROC_TERMINATED, PROC_TIMEOUT, ProcessInformationMap, and Sleep().
Referenced by _wrap_WaitForProcess(), and UnitTest_ProbeProcessWait().
| 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 787 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 3309 of file Utils.cpp.
References CalcTimeout(), Sleep(), and ThreadHandle.
Referenced by cmlabs::ThreadManager::joinThread().
| 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. |
| bool cmlabs::utils::WriteProcessInput | ( | uint32 | proc, |
| const char * | data, | ||
| uint32 | len ) |
Write to the stdin of a child launched with captureOutput=true (T1.1 step 2.7c).
Windows only has a stdin pipe to write to since 2.7c; before that the child inherited the parent's STD_INPUT_HANDLE and there was no handle here at all.
| proc | Process id. |
| data | Bytes to write (not NUL-terminated). |
| len | Byte count. |
Definition at line 5301 of file Utils.cpp.
References ProcessInformationMap.
Referenced by _wrap_WriteProcessInput().
| bool cmlabs::utils::WriteProcessTerminal | ( | uint32 | proc, |
| const char * | data, | ||
| uint32 | len ) |
Write bytes to the child's terminal input (its stdin).
May block briefly if the child is not reading.
Definition at line 5499 of file Utils.cpp.
References Sleep(), and TerminalMasterFind().
Referenced by _wrap_WriteProcessTerminal().
|
static |
Definition at line 441 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), CreateDrumBeat(), EndDrumBeat(), StartDrumBeat(), and StopDrumBeat().
|
static |
Definition at line 649 of file Utils.h.
Referenced by CloseProcessInput(), EndProcess(), GetProcessStatus(), NewProcess(), NewProcessEx(), ReadProcessOutput(), ReleaseProcessCapture(), WaitForProcess(), and WriteProcessInput().
|
static |
Definition at line 611 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyEvent(), SignalEvent(), and WaitForNextEvent().
|
static |
Definition at line 610 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 605 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyMutex(), EnterMutex(), and LeaveMutex().
|
static |
Definition at line 604 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroyMutex(), EnterMutex(), and LeaveMutex().
|
static |
Definition at line 608 of file Utils.h.
Referenced by cmlabs::ClearUtilsMaps(), DestroySemaphore(), GetSemaphore(), SignalSemaphore(), and WaitForSemaphore().
|
static |
Definition at line 607 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(), SetSharedSystemInstance(), Swig_var_SharedSystemInstance_get(), and Swig_var_SharedSystemInstance_set().