|
|
|
@ -390,7 +390,7 @@ function BaseControl:listen(noun, query, callback)
|
|
|
|
callback=callback,
|
|
|
|
callback=callback,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if self.local_nouns[noun] ~= nil then
|
|
|
|
if self.local_nouns[noun] ~= nil then
|
|
|
|
return true
|
|
|
|
return id, true
|
|
|
|
elseif self.remote_nouns[noun] ~= nil then
|
|
|
|
elseif self.remote_nouns[noun] ~= nil then
|
|
|
|
self.network:send(self.remote_nouns[noun], {
|
|
|
|
self.network:send(self.remote_nouns[noun], {
|
|
|
|
ty=Message.ListenRequest,
|
|
|
|
ty=Message.ListenRequest,
|
|
|
|
@ -398,10 +398,24 @@ function BaseControl:listen(noun, query, callback)
|
|
|
|
id=id,
|
|
|
|
id=id,
|
|
|
|
query=query,
|
|
|
|
query=query,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
return id, true
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
return id, false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function BaseControl:cancel(noun, id)
|
|
|
|
|
|
|
|
if self.listeners[noun] == nil or self.listeners[noun][id] == nil then
|
|
|
|
|
|
|
|
error("can't cancel unknown listener on \""..noun.."\"")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if self.local_nouns[noun] == nil and self.remote_nouns[noun] ~= nil then
|
|
|
|
|
|
|
|
self.network:send(self.remote_nouns[noun], {
|
|
|
|
|
|
|
|
ty=Message.ListenCancel,
|
|
|
|
|
|
|
|
noun=noun,
|
|
|
|
|
|
|
|
id=id,
|
|
|
|
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.listeners[noun][id] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
@ -469,6 +483,12 @@ function BaseControl:_network_handler(remote, msg)
|
|
|
|
if self.listeners[msg.noun][msg.id] ~= nil then
|
|
|
|
if self.listeners[msg.noun][msg.id] ~= nil then
|
|
|
|
self.listeners[msg.noun][msg.id].callback(msg.value)
|
|
|
|
self.listeners[msg.noun][msg.id].callback(msg.value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
elseif msg.ty == Message.ListenCancel then
|
|
|
|
|
|
|
|
if self.listeners[msg.noun][msg.id] ~= nil then
|
|
|
|
|
|
|
|
if self.listeners[msg.noun][msg.id].addr == remote then
|
|
|
|
|
|
|
|
self.listeners[msg.noun][msg.id] = nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
|
error("TODO: MessageType Unknown")
|
|
|
|
error("TODO: MessageType Unknown")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|