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

@@ -29,6 +29,7 @@
#define COMMAND_RESULT_SLOT 2
#define EVENT_SLOT 3
#define ALIVE_SLOT 4
#define ALIVE_ACK_SLOT 5
//#define DEBUG
@@ -44,6 +45,7 @@ typedef struct {
ShmQueue *command_result_queue;
ShmQueue *event_queue;
ShmQueue *alive_queue;
ShmQueue *alive_ack_queue;
#ifdef _WIN32
HANDLE rkt_webview_prg_pid;
#else
@@ -63,6 +65,7 @@ typedef struct {
bool alive_go_on;
std::thread *alive_thread;
bool alive_error;
} Handle_t;
Handle_t *handler = nullptr;
@@ -101,12 +104,14 @@ bool runRktWebview(Handle_t *handler)
char command_result_slot[10];
char event_slot[10];
char alive_slot[10];
char alive_ack_slot[10];
sprintf(shm_size_str, "%d", static_cast<int>(handler->shm_size));
sprintf(command_slot, "%d", COMMAND_SLOT);
sprintf(command_result_slot, "%d", COMMAND_RESULT_SLOT);
sprintf(event_slot, "%d", EVENT_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
@@ -144,7 +149,9 @@ bool runRktWebview(Handle_t *handler)
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 dir = basedir(exe);
@@ -185,9 +192,11 @@ bool runRktWebview(Handle_t *handler)
/////////////////////////////////////////////////////////////////////
#define EVT_GUARD_STOP -93273
#define EVT_ALIVE_ERROR -94328
#define WAIT_ON_EVENT_MS (10 * 1000)
#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_ALIVE_ACK_TIME (10 * 1000)
void rkt_evt_guard(void)
{
@@ -219,6 +228,14 @@ void queue_alive_message()
DEBUG1("Pinging with %d\n", ping);
handler->alive_queue->enqueue(ping);
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);
@@ -271,6 +288,7 @@ void rkt_webview_cleanup()
delete handler->command_result_queue;
delete handler->command_queue;
delete handler->alive_queue;
delete handler->alive_ack_queue;
delete handler->shm;
// Cleanup Memory Queue
@@ -315,6 +333,7 @@ void rkt_webview_init()
handler->event_queue = new ShmQueue(handler->shm, EVENT_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
#ifndef DEBUG
@@ -327,6 +346,7 @@ void rkt_webview_init()
handler->guard_go_on = false;
handler->alive_go_on = true;
handler->alive_error = false;
handler->alive_thread = new std::thread(queue_alive_message);
} else {