44 explicit JSEngine(
const std::string& jsfile,
45 std::vector<std::string>& searchPaths,
46 std::shared_ptr<UInterface>& ui,
50 inline std::shared_ptr<DebugStream> log()
noexcept
55 inline std::shared_ptr<DebugStream> js_log()
noexcept
60 inline std::shared_ptr<DebugStream> http_log()
noexcept
62 return httpserv->log();
70 void askSensors( UniversalIO::UIOCommand cmd );
78 void initGlobal( JSContext* ctx );
79 void exportAllFunctionsFromTimerModule();
80 void createUInterfaceObject();
81 void createUnisetObject();
82 void createResponsePrototype( JSContext* ctx );
83 void createRequestAtoms(JSContext* ctx);
84 void createRequestPrototype(JSContext* ctx);
89 JSValue jsReqProto_ = { JS_UNDEFINED };
90 JSValue jsResProto_ = { JS_UNDEFINED };
92 bool reqAtomsInited_ =
false;
95 JSAtom method, uri, version, url, path, query, headers, body;
98 std::atomic_bool activated = {
false };
99 std::shared_ptr<DebugStream> mylog;
101 std::vector<std::string> searchPaths;
102 std::shared_ptr<UInterface> ui;
103 JSRuntime* rt = {
nullptr };
104 JSContext* ctx = {
nullptr };
105 uint8_t* jsbuf = {
nullptr };
106 std::shared_ptr<DebugStream> jslog = {
nullptr };
107 std::shared_ptr<uniset::JHttpServer> httpserv = {
nullptr };
109 std::shared_ptr<uniset::ObjectIndex> oind;
115 bool set( JSContext* ctx, JSValue& global, int64_t v );
118 std::unordered_map<uniset::ObjectId, jsSensor> inputs;
119 std::unordered_map<uniset::ObjectId, jsSensor> outputs;
120 std::list<JSValue> stepFunctions;
121 std::list<JSValue> stopFunctions;
123 JSValue jsFnStep = { JS_UNDEFINED };
124 JSValue jsFnStart = { JS_UNDEFINED };
125 JSValue jsFnStop = { JS_UNDEFINED };
126 JSValue jsFnTimers = { JS_UNDEFINED };
127 JSValue jsFnOnSensor = { JS_UNDEFINED };
128 JSValue jsGlobal = { JS_UNDEFINED };
129 JSValue jsModule = { JS_UNDEFINED };
130 JSValue jsFnHttpRequest = { JS_UNDEFINED };
131 JHttpServer::HandlerFn httpHandleFn;
133 JSValue js_ui_getValue(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
134 JSValue js_ui_askSensor(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
135 JSValue js_ui_setValue(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
136 JSValue js_uniset_StepCb(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
137 JSValue js_uniset_StopCb(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
138 JSValue js_uniset_httpStart(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
139 JSValue js_log(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
140 JSValue js_log_level(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
143 static JSValue jsUiGetValue_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
144 static JSValue jsUiAskSensor_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
145 static JSValue jsUiSetValue_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
146 static JSValue jsLog_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
147 static JSValue jsLogLevel_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
148 static JSValue jsUniSetStepCb_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
149 static JSValue jsUniSetStopCb_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
150 static JSValue jsUniSetHttpStart_wrapper(JSContext* ctx, JSValueConst this_val,
int argc, JSValueConst* argv);
160#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
163#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
166#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
169#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
172#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
175#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
178#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
181#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
184#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
187#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
190#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
193#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
196#define mylogany log()->any()