ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
abstraction.h File Reference

Platform abstraction layer umbrella header providing unified cross-platform API. More...

Go to the source code of this file.

Macros

Platform Detection Macros
#define PLATFORM_WINDOWS   0
 Platform detection: 1 on Windows, 0 on POSIX.
 
#define PLATFORM_POSIX   1
 Platform detection: 1 on POSIX, 0 on Windows.
 
Compiler Attribute Macros
#define PACKED_STRUCT_BEGIN
 Begin a packed structure (POSIX: no-op, uses attribute)
 
#define PACKED_STRUCT_END
 End a packed structure (POSIX: no-op, uses attribute)
 
#define PACKED_ATTR   __attribute__((packed))
 Packed structure attribute (POSIX: attribute((packed)))
 
#define ALIGNED_ATTR(x)   __attribute__((aligned(x)))
 Memory alignment attribute (POSIX: attribute((aligned)))
 
Utility Macros
#define PLATFORM_BINARY_NAME   "ascii-chat"
 Suppress unused parameter warnings.
 
#define PLATFORM_SHELL_NULL_REDIRECT   "2>/dev/null"
 Shell null device/error redirect for platform.
 

Functions

Cross-Platform Utility Functions
void platform_sleep_us (unsigned int usec)
 High-precision sleep function with microsecond precision.
 
void platform_sleep_ns (uint64_t ns)
 Platform-safe sleep function with nanosecond precision.
 

Detailed Description

Platform abstraction layer umbrella header providing unified cross-platform API.

This is the main entry point for the platform abstraction layer. All code in the project uses the types and functions declared here (and in the component headers it includes) rather than calling OS APIs directly. This allows the same application code to compile and run on five targets:

Target Implementation directory Notes
Linux lib/platform/posix/ + linux/ Full feature set, V4L2 webcam, ALSA
macOS lib/platform/posix/ + macos/ Full feature set, AVFoundation webcam
Windows lib/platform/windows/ Win32 APIs, WinSock2 sockets
WASM lib/platform/wasm/ Emscripten, browser environment

POSIX platforms (Linux, macOS) share a common implementation in lib/platform/posix/ with OS-specific extensions in lib/platform/linux/ and lib/platform/macos/.

The WASM target (lib/platform/wasm/) compiles the core C code to WebAssembly via Emscripten for use in the browser-based web client (web.ascii-chat.com). It provides real implementations for video processing, ASCII conversion, terminal capabilities, and timing, while stubbing out functionality unavailable in a browser context (networking, audio capture, filesystem, process management) in lib/platform/wasm/stubs/.

Component headers included by this file:

  • thread.h - Thread creation, joining, and identification
  • mutex.h - Mutual exclusion locks
  • rwlock.h - Reader-writer locks
  • cond.h - Condition variables
  • socket.h - TCP/UDP socket operations and address helpers
  • terminal.h - Terminal I/O, capabilities detection, ANSI sequences, render modes
  • system.h - Timers, environment variables, signal handling, platform info
  • string.h - Safe string functions (snprintf wrappers, UTF-8 helpers)
  • memory.h - Safe memory allocation with leak tracking (SAFE_MALLOC, SAFE_FREE)
  • process.h - Process spawning, pipes, and PID management
  • filesystem.h - File operations, path manipulation, directory traversal
  • pipe.h - Named and anonymous pipe abstractions

This header also defines:

  • Platform detection macros (PLATFORM_WINDOWS, PLATFORM_POSIX)
  • Compiler attribute macros (PACKED_ATTR, ALIGNED_ATTR, THREAD_LOCAL)
  • Windows POSIX compatibility shims (aligned_alloc, clock_gettime, gmtime_r, etc.)
  • Cross-platform sleep functions (platform_sleep_us, platform_sleep_ns)
  • Utility macros (UNUSED, PLATFORM_BINARY_NAME)

Definition in file abstraction.h.