Commit b13c2c85 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

keep memory of the last string in the queue

parent 75c4c3e1
......@@ -265,7 +265,7 @@ static JSValue js_drone_init(JSContext *ctx, JSValueConst thisVal,
return JS_UNDEFINED;
}
static JSValue readDroneDataStr(JSContext *ctx, StrQueue *pQueue)
static JSValue readDroneDataStr(JSContext *ctx, StrQueue *pQueue, bool keepAtLeastAnElement)
{
JSValue res;
struct strNode *current;
......@@ -273,8 +273,15 @@ static JSValue readDroneDataStr(JSContext *ctx, StrQueue *pQueue)
current = pQueue->head;
if (current != NULL) {
res = JS_NewString(ctx, current->str);
pQueue->head = current->next == NULL ? (pQueue->tail = NULL) : current->next;
delete_str_node(current);
if (current->next != NULL) {
pQueue->head = current->next;
delete_str_node(current);
} else {
if (!keepAtLeastAnElement) {
pQueue->head = (pQueue->tail = NULL);
delete_str_node(current);
}
}
} else {
res = JS_NewString(ctx, "");
}
......@@ -304,9 +311,9 @@ static JSValue js_drone_get(JSContext *ctx, JSValueConst thisVal, int magic)
case 7:
return JS_NewFloat64(ctx, s->climbRate);
case 8:
return readDroneDataStr(ctx, &(s->receiveMessageQueue));
return readDroneDataStr(ctx, &(s->receiveMessageQueue), true);
case 9:
return readDroneDataStr(ctx, &(s->receiveLogQueue));
return readDroneDataStr(ctx, &(s->receiveLogQueue), false);
case 10:
return JS_NewInt64(ctx, s->timestamp);
default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment