From dc6a25acac694da2afca54e7fa2fc5a7364dbc66 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Tue, 24 Mar 2026 12:56:10 +0200 Subject: [PATCH] R: compromises between process_server_command and callbacks --- src/main.h | 1 + src/query.c | 18 ++++++++++-------- src/server.c | 4 +++- src/widget/app.c | 4 ++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main.h b/src/main.h index b5ef1b9..0a2d0ed 100644 --- a/src/main.h +++ b/src/main.h @@ -35,6 +35,7 @@ enum state { S_ASK_LOGIN_USER, S_ASK_REGISTER, S_WAIT_SERVER, + S_PREP_SERVER_MESSAGE, S_PRINT_SERVER_MESSAGE, S_FILE_LIST, S_WAIT_PASS, diff --git a/src/query.c b/src/query.c index e561708..430e31d 100644 --- a/src/query.c +++ b/src/query.c @@ -32,7 +32,7 @@ #include "server.h" #include "types.h" -static int wait_side(app_t *app, wait_server_cb *cb); +static int process_command(app_t *app, wait_server_cb *cb); void user_request_description(query_args_t *q_args); int process_query(app_t *app); int32_t process_user_input(app_t *app, callback_args_t *d_args); @@ -79,6 +79,7 @@ void query_loop(app_t *app) { if (ERR == process_query(app)) { EXIT_APP("*** error while processing query ***", app, 1) } + query_args->state = S_WAIT_SERVER; continue; } else { sr = select(maxfd + 1, &readfds, NULL, NULL, NULL); @@ -153,13 +154,14 @@ int process_query(app_t *app) { case WAIT_CLIENT: case WAIT_REGISTER_CONFIRMATION: case S_WAIT_PASS: - wait_side(app, NULL); + case S_WAIT_SERVER: + process_command(app, NULL); break; case S_NEXT_ACTION: - wait_side(app, NULL); + process_command(app, NULL); break; case S_WAIT_REGISTER_CONFIRMATION: - wait_side(app, server_wait_reg_confirm_cb); + process_command(app, server_wait_reg_confirm_cb); break; case S_ERR: break; @@ -186,7 +188,7 @@ int process_query(app_t *app) { } break; case S_UPLOAD_SERVER_FINISHES: - wait_side(app, upload_confirm_cb); + process_command(app, upload_confirm_cb); /* user_request_description(query_args); */ break; case S_ASK_USER_BEFORE_LOGIN: @@ -194,8 +196,8 @@ int process_query(app_t *app) { case WAIT_REGISTER: wait_register(query_args); break; - case S_WAIT_SERVER: - wait_side(app, server_print_message_cb); + case S_PREP_SERVER_MESSAGE: + process_command(app, server_print_message_cb); break; default: break; @@ -249,7 +251,7 @@ void query_return_to_buf(char *buf, int *buf_used, char *input_line) { buf[*buf_used] = 0; } -static int wait_side(app_t *app, wait_server_cb *callback) { +static int process_command(app_t *app, wait_server_cb *callback) { query_args_t *q_args = app->query_args; int qlen; char *query = NULL; diff --git a/src/server.c b/src/server.c index ec0ebf5..5619d3b 100644 --- a/src/server.c +++ b/src/server.c @@ -92,7 +92,6 @@ int server_print_message_cb(app_t *app, char *line, int l_len) { return 0; } -/* TODO: refactor to process callbacks */ int process_server_command(char *line, int l_len, app_t *app) { int ws_pos = l_len; query_args_t *q_args = app->query_args; @@ -146,6 +145,9 @@ int process_server_command(char *line, int l_len, app_t *app) { return 0; } + q_args->state = S_PREP_SERVER_MESSAGE; + server_print_message_cb(app, line, l_len); + return -1; } diff --git a/src/widget/app.c b/src/widget/app.c index e98c34c..ab93920 100644 --- a/src/widget/app.c +++ b/src/widget/app.c @@ -2,6 +2,7 @@ /* Copyright (c) 2026 Oleksandr Zhylin */ #include "app.h" +#include "file_list.h" #include #include #include @@ -45,6 +46,9 @@ app_t *init_app() { /* default win */ _app->active_win_type = aw_left; + /* default callback */ + _app->active_callback = file_list_cb; + /* print decorative bars */ print_bars(_app);