CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
test_console.c File Reference

This file contains utility functions for outputting data on the console. In addition to standard console output, it supports a multi-window console using the ncurses libary on linux and the PDCurses libary on windows. More...

#include "test_console.h"
#include <stdio.h>
#include <stdlib.h>
#include "cdi_logger_api.h"
#include "cdi_test.h"
#include "curses.h"
#include "utilities_api.h"

Macros

#define MAX_MESSAGE_SIZE   (1024)
 Maximum length of a single line from stderr output. The text wraps if the value is exceeded.
 

Functions

static void SaveWindowToBuffer (WINDOW *window_ptr, chtype *buffer_ptr, int height, int width)
 
static void DumpSavedWindowToStdout (chtype *buffer_ptr, int height, int width)
 
static int vprintf_line (const char *prefix_str, const char *format_str, va_list vars)
 
static CDI_THREAD TestConsoleThread (void *arg_ptr)
 
bool TestConsoleCreate (bool multi_window_mode, int num_stats_lines)
 
void TestConsoleDestroy (bool abnormal_termination)
 
void TestConsoleLogMessageCallback (const CdiLogMessageCbData *cb_data_ptr)
 
void TestConsoleStats (int x, int y, int attribute, const char *format_str,...)
 
void TestConsoleStatsHorzLine (int x, int y, int width)
 
void TestConsoleStatsRefresh (void)
 
void TestConsoleLog (CdiLogLevel log_level, const char *format_str,...)
 

Variables

static bool screen_initialized = false
 Multi-window screen has been successfully initialized.
 
static int console_height = 0
 Height of console.
 
static int console_width = 0
 Width of console.
 
static WINDOW * stats_window_ptr = NULL
 If multi-window mode is enabled, this pointer is used by the stats window.
 
static int stats_window_height = 0
 Height of stats window.
 
static chtype * stats_window_buffer_ptr = NULL
 Pointer to buffer used to hold a copy of the stats window.
 
static WINDOW * log_window_ptr = NULL
 If multi-window mode is enabled, this pointer is used by the scrolling log message window.
 
static int log_window_height = 0
 Height of log window.
 
static chtype * log_window_buffer_ptr = NULL
 Pointer to buffer used to hold a copy of the log window.
 
static CdiCsID log_window_lock = NULL
 Critical section used to protect access to the log window.
 
static int pipe_fd_array [2] = { CDI_INVALID_HANDLE_VALUE, CDI_INVALID_HANDLE_VALUE }
 File descriptor for pipe. [0]= read fd, [1]= write fd.
 
static int original_stdout_fd = CDI_INVALID_HANDLE_VALUE
 File descriptor for stdout.
 
CdiThreadID console_thread_id
 Thread ID for this connection.
 
static bool abnormal_termination_enabled = false
 

Detailed Description

This file contains utility functions for outputting data on the console. In addition to standard console output, it supports a multi-window console using the ncurses libary on linux and the PDCurses libary on windows.

Function Documentation

◆ DumpSavedWindowToStdout()

static void DumpSavedWindowToStdout ( chtype * buffer_ptr,
int height,
int width )
static

Dump the text in a window to stdout.

Parameters
buffer_ptrPointer to window buffer.
heightHeight of window.
widthWidth of window.

◆ SaveWindowToBuffer()

static void SaveWindowToBuffer ( WINDOW * window_ptr,
chtype * buffer_ptr,
int height,
int width )
static

Allocate a buffer and save the contents of a window to it.

Parameters
window_ptrPointer to window handle.
buffer_ptrPointer to where to store the window data.
heightHeight of window.
widthWidth of window.

◆ TestConsoleCreate()

bool TestConsoleCreate ( bool multi_window_mode,
int num_stats_lines )

Initialize the console for either multi-window mode or stdout mode.

Parameters
multi_window_modeTrue to enable mutli-window mode, otherwise use stdout mode.
num_stats_linesNumber of lines to dedicate to statistics window.
Returns
Returns true if success, otherwise false is returned and the stdout console will be used.

◆ TestConsoleDestroy()

void TestConsoleDestroy ( bool abnormal_termination)

Destroy the resources used by the console. Doesn't do much unless multi-window mode is enabled.

Parameters
abnormal_terminationTrue if being terminated abnormally (ie. from a signal event handler). This will cause all console log API functions to be disabled to prevent other threads from generating erroneous log error messages.

◆ TestConsoleLog()

void TestConsoleLog ( CdiLogLevel log_level,
const char * format_str,
... )

Add a message to the console log window, if multi-window mode is enabled (no need to use TestConsoleStatsRefresh()). Otherwise just writes to stdout.

Parameters
log_levelThe log level for this message.
format_strFormat string specifier.
...The remaining parameters contain a variable length list of arguments.

◆ TestConsoleLogMessageCallback()

void TestConsoleLogMessageCallback ( const CdiLogMessageCbData * cb_data_ptr)

Callback function used by the log message callback feature.

Parameters
cb_data_ptrPointer to log message callback data.

◆ TestConsoleStats()

void TestConsoleStats ( int x,
int y,
int attribute,
const char * format_str,
... )

Put a message in the console log window if using mult-window mode, otherwise just write to stdout. NOTE: When in multi-window mode, must use TestConsoleStatsRefresh() to update the window.

Parameters
xConsole window X position.
yConsole window Y position.
attributeCharacter attribute. Use A_NORMAL for normal console output.
format_strPointer to format string.
...Variable list of string arguments.

◆ TestConsoleStatsHorzLine()

void TestConsoleStatsHorzLine ( int x,
int y,
int width )

Render a horizontal line on the stats console. NOTE: When in multi-window mode, must use TestConsoleStatsRefresh() to update the window.

Parameters
xConsole window X position.
yConsole window Y position.
widthColumn width of line to draw. Use 0 for full width of console.

◆ TestConsoleStatsRefresh()

void TestConsoleStatsRefresh ( void )

Refresh the status console window. Only used in multi-window mode.

◆ TestConsoleThread()

static CDI_THREAD TestConsoleThread ( void * arg_ptr)
static

This function monitors the stderr pipe, and sends any data to the console log window.

Parameters
arg_ptrPointer to parameter for use by the thread (not used here).
Returns
Always returns 0 (not used).

◆ vprintf_line()

static int vprintf_line ( const char * prefix_str,
const char * format_str,
va_list vars )
static

Behaves like vprintf but adds a prefix and a newline to the format string.

Parameters
prefix_strPrefix string.
format_strFormat string.
varsArgument list (see vprintf).
Returns

Variable Documentation

◆ abnormal_termination_enabled

bool abnormal_termination_enabled = false
static

When true, the console is being destroyed. This is used to prevent threads from using the console output functions while TestConsoleDestroy() is executing.