ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
Shutdown System

Clean shutdown detection without library accessing application state. More...

Files

file  shutdown.h
 Shutdown check system for clean library/application separation.
 

Typedefs

typedef bool(* shutdown_check_fn) (void)
 Shutdown check callback function type.
 

Functions

void shutdown_register_callback (shutdown_check_fn callback)
 Register application's shutdown check function.
 
bool shutdown_is_requested (void)
 Check if shutdown has been requested.
 

Detailed Description

Clean shutdown detection without library accessing application state.

Provides clean separation between library and application for shutdown detection. Library code should never directly access application state.

Usage: Application (server.c/client.c): shutdown_register_callback(my_shutdown_check_fn);

Library code (logging.c, debug/lock.c, etc.): if (shutdown_is_requested()) { return; }

Typedef Documentation

◆ shutdown_check_fn

typedef bool(* shutdown_check_fn) (void)

#include <shutdown.h>

Shutdown check callback function type.

Returns
true if shutdown has been requested, false otherwise

Definition at line 32 of file shutdown.h.

Function Documentation

◆ shutdown_is_requested()

bool shutdown_is_requested ( void  )

#include <shutdown.h>

Check if shutdown has been requested.

Returns
true if shutdown has been requested, false otherwise
Note
Use this in library code to check for shutdown requests without accessing application state directly. The callback must be registered first with shutdown_register_callback().

Definition at line 45 of file common.c.

45 {
46 shutdown_check_fn callback = atomic_load(&g_shutdown_callback);
47 if (callback == NULL) {
48 return false; // No callback registered, assume not shutting down
49 }
50 return callback();
51}
bool(* shutdown_check_fn)(void)
Shutdown check callback function type.
Definition shutdown.h:32

Referenced by log_plain_msg(), log_plain_stderr_msg(), and log_plain_stderr_nonewline_msg().

◆ shutdown_register_callback()

void shutdown_register_callback ( shutdown_check_fn  callback)

#include <shutdown.h>

Register application's shutdown check function.

Parameters
callbackFunction to call to check if shutdown has been requested
Note
Call this from main() to register the application's shutdown detection function. Library code should use shutdown_is_requested() instead of accessing application state directly.

Referenced by server_main().