CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
|
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 |
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.
|
static |
Dump the text in a window to stdout.
buffer_ptr | Pointer to window buffer. |
height | Height of window. |
width | Width of window. |
|
static |
Allocate a buffer and save the contents of a window to it.
window_ptr | Pointer to window handle. |
buffer_ptr | Pointer to where to store the window data. |
height | Height of window. |
width | Width of window. |
bool TestConsoleCreate | ( | bool | multi_window_mode, |
int | num_stats_lines ) |
Initialize the console for either multi-window mode or stdout mode.
multi_window_mode | True to enable mutli-window mode, otherwise use stdout mode. |
num_stats_lines | Number of lines to dedicate to statistics window. |
void TestConsoleDestroy | ( | bool | abnormal_termination | ) |
Destroy the resources used by the console. Doesn't do much unless multi-window mode is enabled.
abnormal_termination | True 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. |
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.
log_level | The log level for this message. |
format_str | Format string specifier. |
... | The remaining parameters contain a variable length list of arguments. |
void TestConsoleLogMessageCallback | ( | const CdiLogMessageCbData * | cb_data_ptr | ) |
Callback function used by the log message callback feature.
cb_data_ptr | Pointer to log message callback data. |
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.
x | Console window X position. |
y | Console window Y position. |
attribute | Character attribute. Use A_NORMAL for normal console output. |
format_str | Pointer to format string. |
... | Variable list of string arguments. |
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.
x | Console window X position. |
y | Console window Y position. |
width | Column width of line to draw. Use 0 for full width of console. |
void TestConsoleStatsRefresh | ( | void | ) |
Refresh the status console window. Only used in multi-window mode.
|
static |
This function monitors the stderr pipe, and sends any data to the console log window.
arg_ptr | Pointer to parameter for use by the thread (not used here). |
|
static |
Behaves like vprintf but adds a prefix and a newline to the format string.
prefix_str | Prefix string. |
format_str | Format string. |
vars | Argument list (see vprintf). |
|
static |
When true, the console is being destroyed. This is used to prevent threads from using the console output functions while TestConsoleDestroy() is executing.