1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/env lua
require "ubus"
require "uloop"
uloop.init()
local conn = ubus.connect()
if not conn then
error("Failed to connect to ubus")
end
local my_method = {
broken = {
hello = 1,
hello1 = {
function(req)
end, {id = "fail" }
},
},
test = {
hello = {
function(req, msg)
conn:reply(req, {message="foo"});
print("Call to function 'hello'")
for k, v in pairs(msg) do
print("key=" .. k .. " value=" .. tostring(v))
end
end, {id = ubus.INT32, msg = ubus.STRING }
},
hello1 = {
function(req)
conn:reply(req, {message="foo1"});
conn:reply(req, {message="foo2"});
print("Call to function 'hello1'")
end, {id = ubus.INT32, msg = ubus.STRING }
},
deferred = {
function(req)
conn:reply(req, {message="wait for it"})
local def_req = conn:defer_request(req)
uloop.timer(function()
conn:reply(def_req, {message="done"})
conn:complete_deferred_request(def_req, 0)
print("Deferred request complete")
end, 2000)
print("Call to function 'deferred'")
end, {}
}
}
}
conn:add(my_method)
local my_event = {
test = function(msg)
print("Call to test event")
for k, v in pairs(msg) do
print("key=" .. k .. " value=" .. tostring(v))
end
end,
}
conn:listen(my_event)
uloop.run()
|