alive_ack_queue implemented

This commit is contained in:
2026-04-11 16:10:39 +02:00
parent 52aa0cac10
commit e9e295c3bc
2 changed files with 33 additions and 5 deletions

View File

@@ -38,6 +38,7 @@ class Alive : public QThread
public: public:
Handler *handler; Handler *handler;
ShmQueue *alive_queue; ShmQueue *alive_queue;
ShmQueue *alive_ack_queue;
bool alive_timeout; bool alive_timeout;
protected: protected:
@@ -71,7 +72,7 @@ int main(int argc, char *argv[])
INFO1("Starting at %s", ctime(&my_time)); INFO1("Starting at %s", ctime(&my_time));
} }
if (argc < 7) { if (argc < 8) {
ERROR1("%s: wrong number of arguments\n", me); ERROR1("%s: wrong number of arguments\n", me);
exit(1); exit(1);
} }
@@ -82,17 +83,21 @@ int main(int argc, char *argv[])
const char *res_slot_str = argv[4]; const char *res_slot_str = argv[4];
const char *evt_slot_str = argv[5]; const char *evt_slot_str = argv[5];
const char *alive_slot_str = argv[6]; const char *alive_slot_str = argv[6];
const char *alive_ack_slot_str = argv[7];
size_t shm_size = atoi(shm_size_str); size_t shm_size = atoi(shm_size_str);
int cmd_slot = atoi(cmd_slot_str); int cmd_slot = atoi(cmd_slot_str);
int res_slot = atoi(res_slot_str); int res_slot = atoi(res_slot_str);
int evt_slot = atoi(evt_slot_str); int evt_slot = atoi(evt_slot_str);
int alive_slot = atoi(alive_slot_str); int alive_slot = atoi(alive_slot_str);
int alive_ack_slot = atoi(alive_ack_slot_str);
MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %s %s %s %s %s\n", me, shm_name, shm_size_str, cmd_slot_str, res_slot_str, evt_slot_str, alive_slot_str)); MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %s %s %s %s %s %s\n", me, shm_name, shm_size_str,
MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %ld %d %d %d %d\n", me, shm_name, shm_size, cmd_slot, res_slot, evt_slot, alive_slot)); cmd_slot_str, res_slot_str, evt_slot_str, alive_slot_str, alive_ack_slot_str));
MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %lld %d %d %d %d %d\n", me, shm_name, shm_size,
cmd_slot, res_slot, evt_slot, alive_slot, alive_ack_slot));
if (!(shm_size > 0 && cmd_slot > 0 && res_slot > 0 && evt_slot > 0)) { if (!(shm_size > 0 && cmd_slot > 0 && res_slot > 0 && evt_slot > 0 && alive_slot > 0 && alive_ack_slot > 0)) {
ERROR1("%s: Invalid shm size or slots\n", me); ERROR1("%s: Invalid shm size or slots\n", me);
exit(2); exit(2);
} }
@@ -111,6 +116,7 @@ int main(int argc, char *argv[])
alive->handler = handler; alive->handler = handler;
alive->alive_timeout = false; alive->alive_timeout = false;
alive->alive_queue = new ShmQueue(handler->shm, alive_slot, false); alive->alive_queue = new ShmQueue(handler->shm, alive_slot, false);
alive->alive_ack_queue = new ShmQueue(handler->shm, alive_ack_slot, false);
alive->start(); alive->start();
handler->webview_handler->initApp(); handler->webview_handler->initApp();
@@ -131,6 +137,7 @@ int main(int argc, char *argv[])
handler->event_queue->takeOwnership(); handler->event_queue->takeOwnership();
handler->shm->takeOwnership(); handler->shm->takeOwnership();
alive->alive_queue->takeOwnership(); alive->alive_queue->takeOwnership();
alive->alive_ack_queue->takeOwnership();
} }
INFO0("cleaning up shm\n"); INFO0("cleaning up shm\n");
@@ -417,6 +424,7 @@ void Alive::run()
go_on = false; go_on = false;
} else { } else {
DEBUG1("Got alive ping: %d\n", ping_no); DEBUG1("Got alive ping: %d\n", ping_no);
alive_ack_queue->enqueue(ping_no);
} }
} }
} }

View File

@@ -29,6 +29,7 @@
#define COMMAND_RESULT_SLOT 2 #define COMMAND_RESULT_SLOT 2
#define EVENT_SLOT 3 #define EVENT_SLOT 3
#define ALIVE_SLOT 4 #define ALIVE_SLOT 4
#define ALIVE_ACK_SLOT 5
//#define DEBUG //#define DEBUG
@@ -44,6 +45,7 @@ typedef struct {
ShmQueue *command_result_queue; ShmQueue *command_result_queue;
ShmQueue *event_queue; ShmQueue *event_queue;
ShmQueue *alive_queue; ShmQueue *alive_queue;
ShmQueue *alive_ack_queue;
#ifdef _WIN32 #ifdef _WIN32
HANDLE rkt_webview_prg_pid; HANDLE rkt_webview_prg_pid;
#else #else
@@ -63,6 +65,7 @@ typedef struct {
bool alive_go_on; bool alive_go_on;
std::thread *alive_thread; std::thread *alive_thread;
bool alive_error;
} Handle_t; } Handle_t;
Handle_t *handler = nullptr; Handle_t *handler = nullptr;
@@ -101,12 +104,14 @@ bool runRktWebview(Handle_t *handler)
char command_result_slot[10]; char command_result_slot[10];
char event_slot[10]; char event_slot[10];
char alive_slot[10]; char alive_slot[10];
char alive_ack_slot[10];
sprintf(shm_size_str, "%d", static_cast<int>(handler->shm_size)); sprintf(shm_size_str, "%d", static_cast<int>(handler->shm_size));
sprintf(command_slot, "%d", COMMAND_SLOT); sprintf(command_slot, "%d", COMMAND_SLOT);
sprintf(command_result_slot, "%d", COMMAND_RESULT_SLOT); sprintf(command_result_slot, "%d", COMMAND_RESULT_SLOT);
sprintf(event_slot, "%d", EVENT_SLOT); sprintf(event_slot, "%d", EVENT_SLOT);
sprintf(alive_slot, "%d", ALIVE_SLOT); sprintf(alive_slot, "%d", ALIVE_SLOT);
sprintf(alive_ack_slot, "%d", ALIVE_ACK_SLOT);
// run rktwebview_prg using the environment variable RKT_WEBVIEW_PRG // run rktwebview_prg using the environment variable RKT_WEBVIEW_PRG
@@ -144,7 +149,9 @@ bool runRktWebview(Handle_t *handler)
DWORD flags = CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS; DWORD flags = CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS;
std::string cmdargs = std::string("") + handler->name + " " + shm_size_str + " " + command_slot + " " + command_result_slot + " " + event_slot + " " + alive_slot; std::string cmdargs = std::string("") + handler->name + " " + shm_size_str + " " +
command_slot + " " + command_result_slot + " " + event_slot +
" " + alive_slot + " " + alive_ack_slot;
std::string exe = std::string(rkt_webview_prg_path); std::string exe = std::string(rkt_webview_prg_path);
std::string dir = basedir(exe); std::string dir = basedir(exe);
@@ -185,9 +192,11 @@ bool runRktWebview(Handle_t *handler)
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
#define EVT_GUARD_STOP -93273 #define EVT_GUARD_STOP -93273
#define EVT_ALIVE_ERROR -94328
#define WAIT_ON_EVENT_MS (10 * 1000) #define WAIT_ON_EVENT_MS (10 * 1000)
#define ALIVE_MESSAGE_INTERVAL_S 5 // Should be smaller than 10 seconds #define ALIVE_MESSAGE_INTERVAL_S 5 // Should be smaller than 10 seconds
#define MAX_WAIT_RESULT (10 * 1000) // Maximum wait in milliseconds for a result #define MAX_WAIT_RESULT (10 * 1000) // Maximum wait in milliseconds for a result
#define MAX_ALIVE_ACK_TIME (10 * 1000)
void rkt_evt_guard(void) void rkt_evt_guard(void)
{ {
@@ -219,6 +228,14 @@ void queue_alive_message()
DEBUG1("Pinging with %d\n", ping); DEBUG1("Pinging with %d\n", ping);
handler->alive_queue->enqueue(ping); handler->alive_queue->enqueue(ping);
if (ping > 1000000000) { ping = 0; } if (ping > 1000000000) { ping = 0; }
int ping_ack;
std::string ping_ack_str;
if (!handler->alive_ack_queue->dequeue(ping_ack, ping_ack_str, MAX_ALIVE_ACK_TIME)) {
ERROR0("No acknowledgement on alive ping from backend\n");
handler->event_queue->enqueue(EVT_ALIVE_ERROR);
handler->alive_go_on = false;
handler->alive_error = true;
}
} }
} }
handler->alive_queue->enqueue(CMD_ALIVE_QUIT); handler->alive_queue->enqueue(CMD_ALIVE_QUIT);
@@ -271,6 +288,7 @@ void rkt_webview_cleanup()
delete handler->command_result_queue; delete handler->command_result_queue;
delete handler->command_queue; delete handler->command_queue;
delete handler->alive_queue; delete handler->alive_queue;
delete handler->alive_ack_queue;
delete handler->shm; delete handler->shm;
// Cleanup Memory Queue // Cleanup Memory Queue
@@ -315,6 +333,7 @@ void rkt_webview_init()
handler->event_queue = new ShmQueue(handler->shm, EVENT_SLOT, true); handler->event_queue = new ShmQueue(handler->shm, EVENT_SLOT, true);
handler->alive_queue = new ShmQueue(handler->shm, ALIVE_SLOT, true); handler->alive_queue = new ShmQueue(handler->shm, ALIVE_SLOT, true);
handler->alive_ack_queue = new ShmQueue(handler->shm, ALIVE_ACK_SLOT, true);
// Start rktwebview_prg application with the right information // Start rktwebview_prg application with the right information
#ifndef DEBUG #ifndef DEBUG
@@ -327,6 +346,7 @@ void rkt_webview_init()
handler->guard_go_on = false; handler->guard_go_on = false;
handler->alive_go_on = true; handler->alive_go_on = true;
handler->alive_error = false;
handler->alive_thread = new std::thread(queue_alive_message); handler->alive_thread = new std::thread(queue_alive_message);
} else { } else {