ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
server_status.c File Reference

Server status screen display with live log feed at FPS rate. More...

Go to the source code of this file.

Functions

void server_status_log_init (void)
 
void server_status_log_destroy (void)
 
void server_status_log_clear (void)
 
void server_status_log_append (const char *message)
 
asciichat_error_t server_status_gather (tcp_server_t *server, const char *session_string, const char *ipv4_address, const char *ipv6_address, uint16_t port, time_t start_time, const char *mode_name, bool session_is_mdns_only, server_status_t *out_status)
 
void server_status_display (const server_status_t *status)
 
bool server_status_display_interactive (const server_status_t *status)
 Display status screen with keyboard input support Returns true if status screen should continue, false if Escape was pressed to exit.
 
void server_status_update (tcp_server_t *server, const char *session_string, const char *ipv4_address, const char *ipv6_address, uint16_t port, time_t start_time, const char *mode_name, bool session_is_mdns_only, uint64_t *last_update_ns)
 

Detailed Description

Server status screen display with live log feed at FPS rate.

Definition in file server_status.c.

Function Documentation

◆ server_status_display()

void server_status_display ( const server_status_t *  status)

Definition at line 237 of file server_status.c.

237 {
238 if (!status) {
239 return;
240 }
241
242 // Only render the status screen in interactive mode
243 // In non-interactive mode, logs flow to stdout/stderr normally
245 return;
246 }
247
248 // If --grep pattern was provided, enter interactive grep mode with it pre-populated
249 // Only do this once (check if not already entering)
250 static bool grep_mode_entered = false;
251 if (!grep_mode_entered && grep_get_last_pattern() && grep_get_last_pattern()[0] != '\0') {
253 grep_mode_entered = true;
254 }
255
256 // Use terminal_screen abstraction for rendering
257 terminal_screen_config_t config = {
258 .fixed_header_lines = 4,
259 .render_header = render_server_status_header,
260 .user_data = (void *)status,
261 .show_logs = true,
262 };
263
264 terminal_screen_render(&config);
265}
const char * grep_get_last_pattern(void)
Definition grep.c:1389
void interactive_grep_enter_mode(void)
bool terminal_is_interactive(void)
void terminal_screen_render(const terminal_screen_config_t *config)

References grep_get_last_pattern(), interactive_grep_enter_mode(), terminal_is_interactive(), and terminal_screen_render().

Referenced by server_status_update().

◆ server_status_display_interactive()

bool server_status_display_interactive ( const server_status_t *  status)

Display status screen with keyboard input support Returns true if status screen should continue, false if Escape was pressed to exit.

Definition at line 271 of file server_status.c.

271 {
272 if (!status) {
273 return true;
274 }
275
276 // Only render the status screen in interactive mode
278 return true;
279 }
280
281 // If --grep pattern was provided, enter interactive grep mode with it pre-populated
282 static bool grep_mode_entered = false;
283 if (!grep_mode_entered && grep_get_last_pattern() && grep_get_last_pattern()[0] != '\0') {
285 grep_mode_entered = true;
286 }
287
288 // Initialize keyboard for interactive grep
289 bool keyboard_enabled = false;
290 if (keyboard_init() == ASCIICHAT_OK) {
291 keyboard_enabled = true;
292 }
293
294 // Use terminal_screen abstraction for rendering
295 terminal_screen_config_t config = {
296 .fixed_header_lines = 4,
297 .render_header = render_server_status_header,
298 .user_data = (void *)status,
299 .show_logs = true,
300 };
301
302 terminal_screen_render(&config);
303
304 // Poll keyboard for Escape to exit or for interactive grep
305 bool should_exit_status = false;
306 if (keyboard_enabled) {
307 keyboard_key_t key = keyboard_read_nonblocking();
308 if (key == KEY_ESCAPE) {
309 // Escape key: cancel grep if active, otherwise exit status screen
311 interactive_grep_exit_mode(false); // Cancel grep without applying
312 } else {
313 should_exit_status = true; // Exit status screen
314 }
315 } else if (key != KEY_NONE && interactive_grep_should_handle(key)) {
317 }
318 }
319
320 // Cleanup keyboard
321 if (keyboard_enabled) {
322 keyboard_destroy();
323 }
324
325 return !should_exit_status; // Return false if user wants to exit
326}
void interactive_grep_exit_mode(bool accept)
bool interactive_grep_is_active(void)
asciichat_error_t interactive_grep_handle_key(keyboard_key_t key)
bool interactive_grep_should_handle(int key)

References grep_get_last_pattern(), interactive_grep_enter_mode(), interactive_grep_exit_mode(), interactive_grep_handle_key(), interactive_grep_is_active(), interactive_grep_should_handle(), terminal_is_interactive(), and terminal_screen_render().

◆ server_status_gather()

asciichat_error_t server_status_gather ( tcp_server_t *  server,
const char *  session_string,
const char *  ipv4_address,
const char *  ipv6_address,
uint16_t  port,
time_t  start_time,
const char *  mode_name,
bool  session_is_mdns_only,
server_status_t *  out_status 
)

Definition at line 49 of file server_status.c.

51 {
52 if (!server || !out_status || !mode_name) {
53 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters for server_status_gather");
54 }
55
56 memset(out_status, 0, sizeof(*out_status));
57
58 // Copy session string
59 if (session_string) {
60 SAFE_STRNCPY(out_status->session_string, session_string, sizeof(out_status->session_string));
61 }
62
63 // Format IPv4 address
64 out_status->ipv4_bound = (ipv4_address && ipv4_address[0] != '\0');
65 if (out_status->ipv4_bound) {
66 snprintf(out_status->ipv4_address, sizeof(out_status->ipv4_address), "%s:%u", ipv4_address, port);
67 }
68
69 // Format IPv6 address
70 out_status->ipv6_bound = (ipv6_address && ipv6_address[0] != '\0');
71 if (out_status->ipv6_bound) {
72 snprintf(out_status->ipv6_address, sizeof(out_status->ipv6_address), "[%s]:%u", ipv6_address, port);
73 }
74
75 out_status->port = port;
76 out_status->start_time = start_time;
77 out_status->mode_name = mode_name;
78 out_status->session_is_mdns_only = session_is_mdns_only;
79 out_status->connected_count = tcp_server_get_client_count(server);
80
81 return ASCIICHAT_OK;
82}
size_t tcp_server_get_client_count(tcp_server_t *server)

References tcp_server_get_client_count().

Referenced by server_status_update().

◆ server_status_log_append()

void server_status_log_append ( const char *  message)

Definition at line 40 of file server_status.c.

40 {
41 // Delegate to shared session log buffer
43}
void session_log_buffer_append(const char *message)

References session_log_buffer_append().

◆ server_status_log_clear()

void server_status_log_clear ( void  )

Definition at line 35 of file server_status.c.

35 {
36 // Delegate to shared session log buffer
38}
void session_log_buffer_clear(void)

References session_log_buffer_clear().

Referenced by server_main().

◆ server_status_log_destroy()

void server_status_log_destroy ( void  )

Definition at line 30 of file server_status.c.

30 {
31 // Delegate to shared session log buffer
33}
void session_log_buffer_destroy(void)

References session_log_buffer_destroy().

Referenced by server_main().

◆ server_status_log_init()

void server_status_log_init ( void  )

Definition at line 25 of file server_status.c.

25 {
26 // Delegate to shared session log buffer
28}
bool session_log_buffer_init(void)

References session_log_buffer_init().

Referenced by server_main().

◆ server_status_update()

void server_status_update ( tcp_server_t *  server,
const char *  session_string,
const char *  ipv4_address,
const char *  ipv6_address,
uint16_t  port,
time_t  start_time,
const char *  mode_name,
bool  session_is_mdns_only,
uint64_t *  last_update_ns 
)

Definition at line 328 of file server_status.c.

330 {
331 if (!server || !last_update_ns) {
332 return;
333 }
334
335 // Update at FPS rate (60 Hz = 16.67ms by default)
336 uint32_t fps = GET_OPTION(fps);
337 if (fps == 0) {
338 fps = 60; // Default
339 }
340
341 // Calculate frame interval in microseconds
342 uint64_t frame_interval_us = US_PER_SEC_INT / fps;
343
344 // Get current time in microseconds using platform abstraction
345 uint64_t now_us = platform_get_monotonic_time_us();
346
347 // Check if enough time has passed
348 if ((now_us - *last_update_ns) < frame_interval_us) {
349 return; // Too soon, skip frame
350 }
351
352 server_status_t status;
353 if (server_status_gather(server, session_string, ipv4_address, ipv6_address, port, start_time, mode_name,
354 session_is_mdns_only, &status) == ASCIICHAT_OK) {
355 server_status_display(&status);
356 *last_update_ns = now_us;
357 }
358}
uint64_t platform_get_monotonic_time_us(void)
asciichat_error_t server_status_gather(tcp_server_t *server, const char *session_string, const char *ipv4_address, const char *ipv6_address, uint16_t port, time_t start_time, const char *mode_name, bool session_is_mdns_only, server_status_t *out_status)
void server_status_display(const server_status_t *status)

References platform_get_monotonic_time_us(), server_status_display(), and server_status_gather().