1 /*
2 * Copyright (C) 2015-2019 Alibaba Group Holding Limited
3 */
4
5 #include <string.h>
6 #include <stdarg.h>
7
8 #include "amp_config.h"
9 #include "aos_system.h"
10 #include "amp_defines.h"
11 #include "quickjs.h"
12 #include "quickjs_addon_common.h"
13
14 #define MOD_STR "BLECFGNET"
15
16 static JSClassID js_blecfgnet_class_id;
17
native_blecfgnet_start(JSContext * ctx,JSValueConst this_val,int argc,JSValueConst * argv)18 static JSValue native_blecfgnet_start(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
19 {
20 int ret = -1;
21 ret = BleCfg_run();
22 if (ret != 0) {
23 amp_warn(MOD_STR, "ble config net start failed");
24 }
25
26 out:
27 return JS_NewInt32(ctx, ret);
28 }
29
native_blecfgnet_recovery_wifi(JSContext * ctx,JSValueConst this_val,int argc,JSValueConst * argv)30 static JSValue native_blecfgnet_recovery_wifi(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
31 {
32 int ret = -1;
33 ret = BleCfg_recovery_wifi();
34 if (ret != 0) {
35 amp_warn(MOD_STR, "ble config net recovery wifi failed");
36 }
37
38 out:
39 return JS_NewInt32(ctx, ret);
40 }
41
native_blecfgnet_recovery_devinfo(JSContext * ctx,JSValueConst this_val,int argc,JSValueConst * argv)42 static JSValue native_blecfgnet_recovery_devinfo(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
43 {
44 int ret = -1;
45 ret = BleCfg_recovery_devinfo();
46 if (ret != 0) {
47 amp_warn(MOD_STR, "ble config net recovery device info failed");
48 }
49
50 out:
51 return JS_NewInt32(ctx, ret);
52 }
53
54 static JSClassDef js_blecfgnet_class = {
55 "blecfgnet",
56 };
57
58 static const JSCFunctionListEntry js_blecfgnet_funcs[] = {
59 JS_CFUNC_DEF("start", 0, native_blecfgnet_start),
60 JS_CFUNC_DEF("recoveryWifi", 0, native_blecfgnet_recovery_wifi),
61 JS_CFUNC_DEF("recoveryDevInfo", 0, native_blecfgnet_recovery_devinfo)
62 };
63
js_blecfgnet_init(JSContext * ctx,JSModuleDef * m)64 static int js_blecfgnet_init(JSContext *ctx, JSModuleDef *m)
65 {
66 JSValue proto;
67
68 JS_NewClassID(&js_blecfgnet_class_id);
69
70 JS_NewClass(JS_GetRuntime(ctx), js_blecfgnet_class_id, &js_blecfgnet_class);
71 proto = JS_NewObject(ctx);
72 JS_SetPropertyFunctionList(ctx, proto, js_blecfgnet_funcs, countof(js_blecfgnet_funcs));
73 JS_SetClassProto(ctx, js_blecfgnet_class_id, proto);
74 return JS_SetModuleExportList(ctx, m, js_blecfgnet_funcs, countof(js_blecfgnet_funcs));
75 }
76
js_init_module_blecfgnet(JSContext * ctx,const char * module_name)77 JSModuleDef *js_init_module_blecfgnet(JSContext *ctx, const char *module_name)
78 {
79 JSModuleDef *m;
80 m = JS_NewCModule(ctx, module_name, js_blecfgnet_init);
81 if (!m)
82 return NULL;
83 JS_AddModuleExportList(ctx, m, js_blecfgnet_funcs, countof(js_blecfgnet_funcs));
84 return m;
85 }
86
module_blecfgnet_register(void)87 void module_blecfgnet_register(void)
88 {
89 amp_debug(MOD_STR, "module_blecfgnet_register");
90 JSContext *ctx = js_get_context();
91 js_init_module_blecfgnet(ctx, "BLECFGNET");
92 }
93
94
95
96
97