BSB Developer Docs
Loading...
Searching...
No Matches
js_runner_types.h
1#pragma once
2
3#include "js_runner.h"
4#include <m-dict.h>
5#include <m-array.h>
6#include <m-list.h>
7#include <stdatomic.h>
8#include <furi/furi.h>
9#include <toolbox/api_lock.h>
10#include <gui/gui.h>
11
12#pragma GCC diagnostic push
13#pragma GCC diagnostic ignored "-Wattributes"
14#include <jerryscript.h>
15#pragma GCC diagnostic pop
16
17typedef enum ChildStatus {
18 ChildStatusNotYet,
19 ChildStatusRunning,
20 ChildStatusDone
21} ChildStatus;
22
23#define JS_RUNNER_MAX_SCRIPT_SIZE (250 * 1024)
24
25typedef struct IntervalContext {
26 bool once;
27 FuriEventLoopTimer* timer;
28 jerry_value_t callback;
30
31M_DICT_DEF2(IntervalDict, uint32_t, M_DEFAULT_OPLIST, IntervalContext, M_POD_OPLIST);
32ARRAY_DEF(ByteArray, uint8_t);
33
34typedef struct JsRunnerAppConsole {
35 JsRunnerConsoleOutCallback callback;
36 void* callback_context;
38
39typedef struct JsRunnerAppInterval {
40 IntervalDict_t intervals;
41 uint32_t last_id;
43
44typedef struct JsRunnerAppInput {
45 Gui* gui;
46 bool subscribed;
47 jerry_value_t listen_handler;
48 FuriMessageQueue* input_queue;
50
51typedef struct JsFetch JsFetch;
52ARRAY_DEF(FetchArray, JsFetch*, M_PTR_OPLIST);
53typedef struct JsRunnerAppFetch {
54 FetchArray_t fetches;
55 FuriMessageQueue* event_queue;
57
58typedef enum JsRunnerAppCommandType {
59 JsRunnerAppCommandTypeInvalid,
60 JsRunnerAppCommandTypeAbort,
61 JsRunnerAppCommandTypeRunFile,
62 JsRunnerAppCommandTypeQuit,
63 JsRunnerAppCommandTypeRunSnippet,
64
65 JsRunnerAppCommandTypeMax,
66} JsRunnerAppCommandType;
67
68typedef struct JsRunnerAppCommandRun {
69 const char* path;
70 JsRunnerContextHandle* context_handle;
72
74 const char* code;
75 bool print_result;
76 JsRunnerContextHandle* context_handle;
78
79typedef struct JsRunnerAppCommand {
80 JsRunnerAppCommandType type;
81 FuriApiLock lock;
82 JsRunnerError* result;
83
84 union {
87 };
89
90typedef void (*JsRunnerDeferredCallback)(void* context);
91
92typedef struct JsRunnerDeferred {
93 JsRunnerDeferredCallback callback;
94 void* context;
96
97ARRAY_DEF(DeferredList, JsRunnerDeferred, M_POD_OPLIST);
98
99typedef struct JsRunnerApp {
100 const FuriString* app_id;
101 FuriThread* thread;
102
103 size_t heap_size;
104 void* jrs_context;
105 FuriString* root_path;
106
107 FuriEventFlag* is_idle;
108
109 FuriEventLoop* event_loop;
110 FuriMessageQueue* command_queue;
111
113 _Atomic bool should_terminate;
114 atomic_flag is_execution_handle_taken;
115 JsRunnerExecutionHandle* execution_handle;
116
117 JsRunnerAppConsole console;
118 JsRunnerAppInterval interval;
119 JsRunnerAppFetch fetch;
120 JsRunnerAppInput input;
121
122 DeferredList_t deferred;
124
125typedef struct JsRunner {
126 FuriEventLoop* event_loop;
127 FuriMessageQueue* message_queue;
128 FuriPubSub* fatal_pubsub;
129} JsRunner;
130
131typedef struct JsRunnerContextHandle {
132 JsRunner* instance;
133 JsRunnerApp* app;
134 FuriThread* thread;
135 FuriMessageQueue* command_queue;
137
139 JsRunnerContextHandle* context_handle;
140 JsRunnerApp* app;
141 JsRunnerEventCallback event_callback;
142 void* event_callback_context;
144
145typedef struct JsRunnerStaticContext {
146 atomic_flag is_running;
147 JsRunnerApp* volatile app;
149
150typedef void (*JsRunnerExternalDataDestructor)(void* object, void* user_p);
151
152typedef void (*JsRunnerArrayBufferDestructor)(void* data);
153
154typedef struct {
155 void* data;
156 JsRunnerArrayBufferDestructor destructor;
GUI system APIs.
Javascript app runner.
Definition gui_i.h:48
Definition js_runner_types.h:25
Definition js_fetch.h:78
Definition js_runner_types.h:79
Definition js_runner_types.h:68
Definition js_runner_types.h:73
Definition js_runner_types.h:34
Definition js_runner_types.h:53
Definition js_runner_types.h:99
FuriEventFlag * is_idle
This flag is set if no script is being run.
Definition js_runner_types.h:107
_Atomic bool should_terminate
Flag to terminate JS busy loops.
Definition js_runner_types.h:113
bool script_evaluation_done
Indicates that the initial evaluation of the script has completed.
Definition js_runner_types.h:112
Definition js_runner_types.h:44
Definition js_runner_types.h:39
Definition js_runner_types.h:154
Definition js_runner_types.h:131
Definition js_runner_types.h:92
Definition js_runner_types.h:138
Definition js_runner_types.h:125
Definition js_runner_types.h:145