mirror of
https://github.com/hmaxnl/netex.git
synced 2025-02-22 21:55:02 +01:00
Reworking ui & server initializing
This commit is contained in:
parent
3075902140
commit
282d93a97e
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -1,6 +1,9 @@
|
||||||
{
|
{
|
||||||
"task.problemMatchers.neverPrompt": true,
|
"task.problemMatchers.neverPrompt": true,
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"log.h": "c"
|
"log.h": "c",
|
||||||
|
"netex.h": "c",
|
||||||
|
"nx_curses.h": "c",
|
||||||
|
"server.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,7 +13,7 @@ typedef enum log_severity
|
||||||
|
|
||||||
struct log_info
|
struct log_info
|
||||||
{
|
{
|
||||||
LogSeverity serverity;
|
size_t message_length;
|
||||||
char* message;
|
char* message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
#define CHAT_PREFIX_COLOR 4
|
#define CHAT_PREFIX_COLOR 4
|
||||||
|
|
||||||
|
|
||||||
int setup_curses(void);
|
int execute_ncurses(void);
|
||||||
void shutdown_curses(void);
|
|
||||||
|
|
||||||
typedef struct scr_size
|
typedef struct scr_size
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,4 +7,28 @@ void initialize_logger(void)
|
||||||
// Create log queue
|
// Create log queue
|
||||||
// Create log thread
|
// Create log thread
|
||||||
// Start 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;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
|
@ -14,14 +14,10 @@
|
||||||
#define PORT_NUM_LENGHT 6
|
#define PORT_NUM_LENGHT 6
|
||||||
|
|
||||||
void handle_exit(int c);
|
void handle_exit(int c);
|
||||||
void handle_term_resize(int c);
|
|
||||||
|
|
||||||
void netex_init(void)
|
void netex_init(void)
|
||||||
{
|
{
|
||||||
signal(SIGINT, handle_exit);
|
signal(SIGINT, handle_exit);
|
||||||
signal(SIGWINCH, handle_term_resize);
|
|
||||||
|
|
||||||
setup_curses();
|
|
||||||
|
|
||||||
// OpenSSL
|
// OpenSSL
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
|
@ -31,7 +27,6 @@ void netex_init(void)
|
||||||
|
|
||||||
void netex_shutdown(void)
|
void netex_shutdown(void)
|
||||||
{
|
{
|
||||||
shutdown_curses();
|
|
||||||
// OpenSSL
|
// OpenSSL
|
||||||
ERR_free_strings();
|
ERR_free_strings();
|
||||||
EVP_cleanup();
|
EVP_cleanup();
|
||||||
|
@ -198,9 +193,4 @@ void handle_exit(int c)
|
||||||
(void)c;
|
(void)c;
|
||||||
netex_shutdown();
|
netex_shutdown();
|
||||||
exit(OK);
|
exit(OK);
|
||||||
}
|
|
||||||
void handle_term_resize(int c)
|
|
||||||
{
|
|
||||||
(void)c;
|
|
||||||
//TODO: Set parameter for ncurses code to check if window is resized.
|
|
||||||
}
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
#include "netex.h"
|
#include "netex.h"
|
||||||
#include "nx_curses.h"
|
#include "nx_curses.h"
|
||||||
|
|
||||||
int setup_curses(void)
|
bool running;
|
||||||
|
|
||||||
|
int execute_ncurses(void)
|
||||||
{
|
{
|
||||||
initscr();
|
initscr();
|
||||||
noecho(); // Stop printing key presses
|
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_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK);
|
||||||
init_pair(DEF_WIN_COLOR, COLOR_GREEN, 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();
|
endwin();
|
||||||
|
return 0;
|
||||||
}
|
}
|
|
@ -10,20 +10,28 @@
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
netex_init();
|
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);
|
const int init_result = initialize_server(argc, argv);
|
||||||
if (init_result)
|
if (init_result)
|
||||||
{
|
{
|
||||||
WARN("Failed to initialize server. Exiting...");
|
WARN("Failed to initialize server. Exiting...");
|
||||||
return init_result;
|
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();
|
netex_shutdown();
|
||||||
return srv_exec_result;
|
return 0;
|
||||||
}
|
}
|
|
@ -62,19 +62,22 @@ int initialize_server(int argc, char* argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int server_execute(void)
|
int server_start(void)
|
||||||
{
|
{
|
||||||
const int thread_create_result = pthread_create(&listen_thread, NULL, server_listen, NULL);
|
const int thread_create_result = pthread_create(&listen_thread, NULL, server_listen, NULL);
|
||||||
if (thread_create_result != 0)
|
if (thread_create_result != 0)
|
||||||
{
|
{
|
||||||
ERROR("Failed to create main listening thread, pthread error: %i", thread_create_result);
|
ERROR("Failed to create main listening thread, pthread error: %i", thread_create_result);
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
int listen_thread_result;
|
int listen_thread_result;
|
||||||
const int join_result = pthread_join(listen_thread, (void**)&listen_thread_result);
|
const int join_result = pthread_join(listen_thread, (void**)&listen_thread_result);
|
||||||
if (join_result == 0)
|
if (join_result == 0)
|
||||||
|
{
|
||||||
WARN("Listen thread has exited with errors!");
|
WARN("Listen thread has exited with errors!");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* server_listen(void* args)
|
void* server_listen(void* args)
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
#include "nx_curses.h"
|
#include "nx_curses.h"
|
||||||
|
|
||||||
int initialize_server(int argc, char* argv[]);
|
int initialize_server(int argc, char* argv[]);
|
||||||
int server_execute(void);
|
int server_start(void);
|
||||||
|
|
||||||
/* Curses */
|
/* Curses */
|
||||||
bool setup_srv_curses();
|
bool execute_ui();
|
||||||
|
|
||||||
#endif //SERVER_H
|
#endif //SERVER_H
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "netex.h"
|
#include "netex.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
@ -9,8 +11,10 @@ bool write_info(const char* conn, int port, const char* ipv);
|
||||||
bool setup_log_window(void);
|
bool setup_log_window(void);
|
||||||
void calculate_window_sizes(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();
|
calculate_window_sizes();
|
||||||
if (!setup_info_window())
|
if (!setup_info_window())
|
||||||
return false;
|
return false;
|
||||||
|
@ -78,4 +82,14 @@ void calculate_window_sizes(void)
|
||||||
|
|
||||||
log_win_size.y = scr_size.y-16;
|
log_win_size.y = scr_size.y-16;
|
||||||
log_win_size.x = GET_PERC(scr_size.x, 50);
|
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);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user