Implement simple verb calling
Signed-off-by: Rahix <rahix@rahix.de>
This commit is contained in:
parent
c6bbdcf984
commit
e4f19c3e20
2 changed files with 28 additions and 0 deletions
10
bc.lua
10
bc.lua
|
|
@ -240,6 +240,12 @@ end
|
||||||
function BaseControl:call(verb, ...)
|
function BaseControl:call(verb, ...)
|
||||||
if self.local_verbs[verb] ~= nil then
|
if self.local_verbs[verb] ~= nil then
|
||||||
self.local_verbs[verb](...)
|
self.local_verbs[verb](...)
|
||||||
|
elseif self.remote_verbs[verb] ~= nil then
|
||||||
|
self.network:send(self.remote_verbs[verb], {
|
||||||
|
ty=Message.VerbRequest,
|
||||||
|
verb=verb,
|
||||||
|
param={...},
|
||||||
|
})
|
||||||
else
|
else
|
||||||
error("unknown verb")
|
error("unknown verb")
|
||||||
end
|
end
|
||||||
|
|
@ -272,6 +278,10 @@ function BaseControl:_network_handler(remote, msg)
|
||||||
})
|
})
|
||||||
elseif msg.ty == Message.NounResponse then
|
elseif msg.ty == Message.NounResponse then
|
||||||
-- Handled via pull
|
-- Handled via pull
|
||||||
|
elseif msg.ty == Message.VerbRequest then
|
||||||
|
if self.local_verbs[msg.verb] ~= nil then
|
||||||
|
self.local_verbs[msg.verb](table.unpack(msg.param))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
error("TODO: MessageType Unknown")
|
error("TODO: MessageType Unknown")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,22 @@ function test_get_network()
|
||||||
local bc2 = BaseControl:new()
|
local bc2 = BaseControl:new()
|
||||||
|
|
||||||
assert_equal(123, bc2:get("getnw1"), "wrong value")
|
assert_equal(123, bc2:get("getnw1"), "wrong value")
|
||||||
|
assert_nil(bc2:get("getnw2"), "found non-exisiting")
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_call_network()
|
||||||
|
local bc1 = BaseControl:new()
|
||||||
|
local tmp, n = 0, 0
|
||||||
|
bc1:register("callnw1", function(param, p2)
|
||||||
|
assert_equal(p2, 1234)
|
||||||
|
tmp = param
|
||||||
|
n = n + 1
|
||||||
|
end)
|
||||||
|
bc1:finalize()
|
||||||
|
|
||||||
|
local bc2 = BaseControl:new()
|
||||||
|
|
||||||
|
bc2:call("callnw1", 4321, 1234)
|
||||||
|
assert_equal(4321, tmp, "call incomplete")
|
||||||
|
assert_equal(1, n, "call not correct")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue