R: compromises between process_server_command and callbacks

This commit is contained in:
2026-03-24 12:56:10 +02:00
parent 7755fa0a81
commit dc6a25acac
4 changed files with 18 additions and 9 deletions
+1
View File
@@ -35,6 +35,7 @@ enum state {
S_ASK_LOGIN_USER, S_ASK_LOGIN_USER,
S_ASK_REGISTER, S_ASK_REGISTER,
S_WAIT_SERVER, S_WAIT_SERVER,
S_PREP_SERVER_MESSAGE,
S_PRINT_SERVER_MESSAGE, S_PRINT_SERVER_MESSAGE,
S_FILE_LIST, S_FILE_LIST,
S_WAIT_PASS, S_WAIT_PASS,
+10 -8
View File
@@ -32,7 +32,7 @@
#include "server.h" #include "server.h"
#include "types.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); void user_request_description(query_args_t *q_args);
int process_query(app_t *app); int process_query(app_t *app);
int32_t process_user_input(app_t *app, callback_args_t *d_args); 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)) { if (ERR == process_query(app)) {
EXIT_APP("*** error while processing query ***", app, 1) EXIT_APP("*** error while processing query ***", app, 1)
} }
query_args->state = S_WAIT_SERVER;
continue; continue;
} else { } else {
sr = select(maxfd + 1, &readfds, NULL, NULL, NULL); sr = select(maxfd + 1, &readfds, NULL, NULL, NULL);
@@ -153,13 +154,14 @@ int process_query(app_t *app) {
case WAIT_CLIENT: case WAIT_CLIENT:
case WAIT_REGISTER_CONFIRMATION: case WAIT_REGISTER_CONFIRMATION:
case S_WAIT_PASS: case S_WAIT_PASS:
wait_side(app, NULL); case S_WAIT_SERVER:
process_command(app, NULL);
break; break;
case S_NEXT_ACTION: case S_NEXT_ACTION:
wait_side(app, NULL); process_command(app, NULL);
break; break;
case S_WAIT_REGISTER_CONFIRMATION: case S_WAIT_REGISTER_CONFIRMATION:
wait_side(app, server_wait_reg_confirm_cb); process_command(app, server_wait_reg_confirm_cb);
break; break;
case S_ERR: case S_ERR:
break; break;
@@ -186,7 +188,7 @@ int process_query(app_t *app) {
} }
break; break;
case S_UPLOAD_SERVER_FINISHES: case S_UPLOAD_SERVER_FINISHES:
wait_side(app, upload_confirm_cb); process_command(app, upload_confirm_cb);
/* user_request_description(query_args); */ /* user_request_description(query_args); */
break; break;
case S_ASK_USER_BEFORE_LOGIN: case S_ASK_USER_BEFORE_LOGIN:
@@ -194,8 +196,8 @@ int process_query(app_t *app) {
case WAIT_REGISTER: case WAIT_REGISTER:
wait_register(query_args); wait_register(query_args);
break; break;
case S_WAIT_SERVER: case S_PREP_SERVER_MESSAGE:
wait_side(app, server_print_message_cb); process_command(app, server_print_message_cb);
break; break;
default: default:
break; break;
@@ -249,7 +251,7 @@ void query_return_to_buf(char *buf, int *buf_used, char *input_line) {
buf[*buf_used] = 0; 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; query_args_t *q_args = app->query_args;
int qlen; int qlen;
char *query = NULL; char *query = NULL;
+3 -1
View File
@@ -92,7 +92,6 @@ int server_print_message_cb(app_t *app, char *line, int l_len) {
return 0; return 0;
} }
/* TODO: refactor to process callbacks */
int process_server_command(char *line, int l_len, app_t *app) { int process_server_command(char *line, int l_len, app_t *app) {
int ws_pos = l_len; int ws_pos = l_len;
query_args_t *q_args = app->query_args; 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; return 0;
} }
q_args->state = S_PREP_SERVER_MESSAGE;
server_print_message_cb(app, line, l_len);
return -1; return -1;
} }
+4
View File
@@ -2,6 +2,7 @@
/* Copyright (c) 2026 Oleksandr Zhylin */ /* Copyright (c) 2026 Oleksandr Zhylin */
#include "app.h" #include "app.h"
#include "file_list.h"
#include <locale.h> #include <locale.h>
#include <ncursesw/ncurses.h> #include <ncursesw/ncurses.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -45,6 +46,9 @@ app_t *init_app() {
/* default win */ /* default win */
_app->active_win_type = aw_left; _app->active_win_type = aw_left;
/* default callback */
_app->active_callback = file_list_cb;
/* print decorative bars */ /* print decorative bars */
print_bars(_app); print_bars(_app);