From 6fd72c201790bcd52ab3af5283c8038f71858578 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 5 Oct 2024 00:21:22 -0700 Subject: [PATCH] feat(scheduler): begin to implement task scheduler per #8 Signed-off-by: zontreck --- src/includes/Functions.lsl | 20 ++--- src/includes/Variables.lsl | 25 +++++-- src/preproc/NuScheduler [AC].lsl | 12 +++ .../{settings.lsl => NuSettings [AC].lsl} | 0 src/raw/scheduler.lsl | 74 +++++++++++++++++++ src/raw/{NuSettings [AC].lsl => settings.lsl} | 21 ++++++ 6 files changed, 131 insertions(+), 21 deletions(-) create mode 100644 src/preproc/NuScheduler [AC].lsl rename src/preproc/{settings.lsl => NuSettings [AC].lsl} (100%) create mode 100644 src/raw/scheduler.lsl rename src/raw/{NuSettings [AC].lsl => settings.lsl} (80%) diff --git a/src/includes/Functions.lsl b/src/includes/Functions.lsl index 5ad1579..a173276 100644 --- a/src/includes/Functions.lsl +++ b/src/includes/Functions.lsl @@ -3,22 +3,14 @@ LM(integer iSignal, string sOp, string sJsonArgs) { llMessageLinked(LINK_SET, iSignal, llJsonSetValue(sJson, ["script"], llGetScriptName()), ""); } -WriteSetting(string sKey, string sValue) { - llLinksetDataWrite(sKey, sValue); - SendSetting(sKey, sValue); +ScheduleCallback(string sTimerID, integer iSeconds, string sTarget) { + LM(LINK_SIGNAL_CALLBACKS, OP_CALLBACK_SCHEDULE, llList2Json(JSON_OBJECT, ["timer", iSeconds, "target", sTarget, "id", sTimerID])); } -ReadSetting(string sKey) { - string sVal = llLinksetDataRead(sKey); - if(sVal == "") { - NoSetting(sKey); - }else SendSetting(sKey, sVal); +Callback(string sTarget, string sTimerID) { + LM(LINK_SIGNAL_CALLBACKS, OP_CALLBACK, llList2Json(JSON_OBJECT, ["target", sTarget, "id", sTimerID])); } -SendSetting(string sKey, string sVal) { - LM(LINK_SIGNAL_SETTINGS, OP_SETTINGS_RESPONSE, llList2Json(JSON_OBJECT, ["key", sKey, "value", sVal])); -} - -NoSetting(string sKey) { - LM(LINK_SIGNAL_SETTINGS, OP_SETTINGS_EMPTY, llList2Json(JSON_OBJECT, ["key", sKey])); +CancelCallback(string sTimerID) { + LM(LINK_SIGNAL_CALLBACKS, OP_CALLBACK_CANCEL, llList2Json(JSON_OBJECT, ["id", sTimerID])); } \ No newline at end of file diff --git a/src/includes/Variables.lsl b/src/includes/Variables.lsl index 7a28540..2d0a1a1 100644 --- a/src/includes/Variables.lsl +++ b/src/includes/Variables.lsl @@ -1,11 +1,22 @@ integer LINK_SIGNAL_SETTINGS = 0904241; integer LINK_SIGNAL_REBOOT = 0904242; +integer LINK_SIGNAL_CALLBACKS = 0904243; -string OP_SETTINGS_WRITE = "settings_write"; -string OP_SETTINGS_READ = "settings_read"; -string OP_SETTINGS_REQUEST = "settings_req"; -string OP_SETTINGS_RESPONSE = "settings_resp"; -string OP_SETTINGS_RESPONSE = "settings_empty"; -string OP_SETTINGS_DELETE = "settings_del"; -string OP_SETTINGS_RESET = "settings_reset"; \ No newline at end of file +string OP_SETTINGS_WRITE = "1"; +string OP_SETTINGS_READ = "2"; +string OP_SETTINGS_REQUEST = "3"; +string OP_SETTINGS_RESPONSE = "4"; +string OP_SETTINGS_RESPONSE = "5"; +string OP_SETTINGS_DELETE = "6"; +string OP_SETTINGS_RESET = "7"; + +string OP_CALLBACK_SCHEDULE = "1"; +string OP_CALLBACK_CANCEL = "2"; +string OP_CALLBACK_CHK_STATUS = "3"; +string OP_CALLBACK_READY = "4"; +string OP_CALLBACK = "5"; + + + +string EMPTY_JSON = "{}"; \ No newline at end of file diff --git a/src/preproc/NuScheduler [AC].lsl b/src/preproc/NuScheduler [AC].lsl new file mode 100644 index 0000000..c114387 --- /dev/null +++ b/src/preproc/NuScheduler [AC].lsl @@ -0,0 +1,12 @@ +/* + +This file is a part of NuSystem (https://git.zontreck.com/AriasCreations/NuSystem) + +NuSystem is licensed under the GPL. +Please see the Git Source Tree for structured information on changes to indivudual files + +Initial Author: Aria (aria@zontreck.com) + +*/ + +#include "../raw/scheduler.lsl" \ No newline at end of file diff --git a/src/preproc/settings.lsl b/src/preproc/NuSettings [AC].lsl similarity index 100% rename from src/preproc/settings.lsl rename to src/preproc/NuSettings [AC].lsl diff --git a/src/raw/scheduler.lsl b/src/raw/scheduler.lsl new file mode 100644 index 0000000..56126ce --- /dev/null +++ b/src/raw/scheduler.lsl @@ -0,0 +1,74 @@ +#include "Variables.lsl" +#include "Functions.lsl" +#include "Version.lsl" +#include "../external/AriasCreations/Common.lsl" +#include "../external/AriasCreations/Helpers.lsl" + + +list g_lCallbacks = []; // TimerID, Timer, DestScript +integer g_iStride = 3; + +default +{ + state_entry() + { + g_lCallbacks = []; + + LM(LINK_SIGNAL_CALLBACKS, OP_CALLBACK_READY, EMPTY_JSON); + llSetTimerEvent(0.5); + } + + timer () { + integer i =0; + integer end = llGetListLength(g_lCallbacks); + + for(i=0;i iExpires) { + // Send the callback signal + } + } + } + + link_message(integer iSender, integer iNum, string sMsg, key kID) + { + DEBUG_FUNC(true, "link_message", [iNum, sMsg, kID]); + if(iNum == LINK_SIGNAL_CALLBACKS) { + string sOp = llJsonGetValue(sMsg, ["op"]); + switch(sOp) { + case OP_CALLBACK_SCHEDULE: { + DEBUG_FUNC(true, "OP_CALLBACK_SCHEDULE", []); + + g_lCallbacks += [llJsonGetValue(sMsg, ["id"]), llGetUnixTime() + (integer)llJsonGetValue(sMsg, ["timer"]), llJsonGetValue(sMsg, ["target"])]; + + DEBUG_FUNC(false, "OP_CALLBACK_SCHEDULE", []); + break; + } + case OP_CALLBACK_CANCEL: { + DEBUG_FUNC(true, "OP_CALLBACK_CANCEL", []); + + // Cancel the callback if it exists + integer iIndex = llListFindList(g_lCallbacks, [llJsonGetValue(sMsg, ["id"])]); + if(iIndex!=-1) { + // Cancel it + g_lCallbacks = llDeleteSubList(g_lCallbacks, iIndex, iIndex+g_iStride); + } + + DEBUG_FUNC(false, "OP_CALLBACK_CANCEL", []); + break; + } + case OP_CALLBACK_CHK_STATUS: { + DEBUG_FUNC(true, "OP_CALLBACK_CHECK_STATUS", []); + + LM(LINK_SIGNAL_CALLBACKS, OP_CALLBACK_READY, EMPTY_JSON); + + DEBUG_FUNC(false, "OP_CALLBACK_CHECK_STATUS", []); + break; + } + } + } + + DEBUG_FUNC(false, "link_message", []); + } +} \ No newline at end of file diff --git a/src/raw/NuSettings [AC].lsl b/src/raw/settings.lsl similarity index 80% rename from src/raw/NuSettings [AC].lsl rename to src/raw/settings.lsl index 1aac763..f61d53f 100644 --- a/src/raw/NuSettings [AC].lsl +++ b/src/raw/settings.lsl @@ -19,6 +19,27 @@ reqAllSettings(){ DEBUG_FUNC(false, "req_all_settings", []); } + +WriteSetting(string sKey, string sValue) { + llLinksetDataWrite("nusetting." + sKey, sValue); + SendSetting(sKey, sValue); +} + +ReadSetting(string sKey) { + string sVal = llLinksetDataRead("nusetting." + sKey); + if(sVal == "") { + NoSetting(sKey); + }else SendSetting(sKey, sVal); +} + +SendSetting(string sKey, string sVal) { + LM(LINK_SIGNAL_SETTINGS, OP_SETTINGS_RESPONSE, llList2Json(JSON_OBJECT, ["key", sKey, "value", sVal])); +} + +NoSetting(string sKey) { + LM(LINK_SIGNAL_SETTINGS, OP_SETTINGS_EMPTY, llList2Json(JSON_OBJECT, ["key", sKey])); +} + default { state_entry() {