Reworking ui & server initializing

This commit is contained in:
max 2025-02-03 02:23:00 +01:00
parent 3075902140
commit 282d93a97e
10 changed files with 96 additions and 35 deletions

View File

@ -1,6 +1,9 @@
{
"task.problemMatchers.neverPrompt": true,
"files.associations": {
"log.h": "c"
"log.h": "c",
"netex.h": "c",
"nx_curses.h": "c",
"server.h": "c"
}
}

View File

@ -13,7 +13,7 @@ typedef enum log_severity
struct log_info
{
LogSeverity serverity;
size_t message_length;
char* message;
};

View File

@ -11,8 +11,7 @@
#define CHAT_PREFIX_COLOR 4
int setup_curses(void);
void shutdown_curses(void);
int execute_ncurses(void);
typedef struct scr_size
{

View File

@ -7,4 +7,28 @@ void initialize_logger(void)
// Create log queue
// Create log thread
// Start log thread
}
}
//void log(char* msg, LogSeverity severity)
//{
// switch (severity)
// {
// case Verbose:
// /* code */
// break;
// case Debug:
// break;
// case Info:
// break;
// case Warning:
// break;
// case Error:
// break;
// case Fatal:
// break;
// default:
// break;
// }
//
//
//}

View File

@ -14,14 +14,10 @@
#define PORT_NUM_LENGHT 6
void handle_exit(int c);
void handle_term_resize(int c);
void netex_init(void)
{
signal(SIGINT, handle_exit);
signal(SIGWINCH, handle_term_resize);
setup_curses();
// OpenSSL
SSL_load_error_strings();
@ -31,7 +27,6 @@ void netex_init(void)
void netex_shutdown(void)
{
shutdown_curses();
// OpenSSL
ERR_free_strings();
EVP_cleanup();
@ -198,9 +193,4 @@ void handle_exit(int c)
(void)c;
netex_shutdown();
exit(OK);
}
void handle_term_resize(int c)
{
(void)c;
//TODO: Set parameter for ncurses code to check if window is resized.
}

View File

@ -1,7 +1,9 @@
#include "netex.h"
#include "nx_curses.h"
int setup_curses(void)
bool running;
int execute_ncurses(void)
{
initscr();
noecho(); // Stop printing key presses
@ -13,10 +15,28 @@ int setup_curses(void)
init_pair(DEF_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK);
init_pair(DEF_WIN_COLOR, COLOR_GREEN, COLOR_BLACK);
}
return 0;
}
void shutdown_curses(void)
{
halfdelay(10);
running = true;
while (running)
{
int key = getch();
switch (key)
{
case KEY_RESIZE:
// Resize function
break;
case 'q':
// Exit?
running = false;
break;
default:
// Default rendering
break;
}
}
endwin();
return 0;
}

View File

@ -10,20 +10,28 @@
int main(int argc, char *argv[])
{
netex_init();
if (!setup_srv_curses())
{
PRINT_LINE("Failed to setup srv windows!");
getch();
return 0;
}
getch(); // For debuging!
const int init_result = initialize_server(argc, argv);
if (init_result)
{
WARN("Failed to initialize server. Exiting...");
return init_result;
}
const int srv_exec_result = server_execute();
const int srv_start_result = server_start(); // Is now holding
if (!srv_start_result)
{
netex_shutdown();
return srv_start_result;
}
if (!execute_ui())
{
PRINT_LINE("Failed to setup srv windows!");
getch();
return 0;
}
netex_shutdown();
return srv_exec_result;
return 0;
}

View File

@ -62,19 +62,22 @@ int initialize_server(int argc, char* argv[])
return 0;
}
int server_execute(void)
int server_start(void)
{
const int thread_create_result = pthread_create(&listen_thread, NULL, server_listen, NULL);
if (thread_create_result != 0)
{
ERROR("Failed to create main listening thread, pthread error: %i", thread_create_result);
return -1;
return 0;
}
int listen_thread_result;
const int join_result = pthread_join(listen_thread, (void**)&listen_thread_result);
if (join_result == 0)
{
WARN("Listen thread has exited with errors!");
return 0;
return 0;
}
return 1;
}
void* server_listen(void* args)

View File

@ -3,9 +3,9 @@
#include "nx_curses.h"
int initialize_server(int argc, char* argv[]);
int server_execute(void);
int server_start(void);
/* Curses */
bool setup_srv_curses();
bool execute_ui();
#endif //SERVER_H

View File

@ -1,3 +1,5 @@
#include <signal.h>
#include "netex.h"
#include "server.h"
@ -9,8 +11,10 @@ bool write_info(const char* conn, int port, const char* ipv);
bool setup_log_window(void);
void calculate_window_sizes(void);
bool setup_srv_curses(void)
bool execute_ui(void)
{
// setup_curses(resize_func, keypressed_func, onexit_func);
execute_ncurses();
calculate_window_sizes();
if (!setup_info_window())
return false;
@ -78,4 +82,14 @@ void calculate_window_sizes(void)
log_win_size.y = scr_size.y-16;
log_win_size.x = GET_PERC(scr_size.x, 50);
}
void handle_term_resize(int c)
{
(void)c;
calculate_window_sizes();
refresh();
wrefresh(info_win);
wrefresh(log_win);
wrefresh(log_win_content);
}