2014-06-23 14:33:11 +00:00
|
|
|
local ffi = require("ffi")
|
|
|
|
local DEBUG = require("dbg")
|
|
|
|
local util = require("ffi/util")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local MessageQueue = require("ui/message/messagequeue")
|
|
|
|
|
|
|
|
local dummy = require("ffi/zeromq_h")
|
2014-06-25 13:31:42 +00:00
|
|
|
local czmq = ffi.load("libs/libczmq.so.1")
|
2014-06-23 14:33:11 +00:00
|
|
|
local zyre = ffi.load("libs/libzyre.so.1")
|
|
|
|
|
|
|
|
local ZyreMessageQueue = MessageQueue:new{
|
|
|
|
header = {},
|
|
|
|
}
|
|
|
|
|
|
|
|
function ZyreMessageQueue:start()
|
|
|
|
self.node = zyre.zyre_new()
|
2014-06-25 13:31:42 +00:00
|
|
|
self.poller = czmq.zpoller_new(zyre.zyre_socket(self.node), nil)
|
2014-06-23 14:33:11 +00:00
|
|
|
for key, value in pairs(self.header) do
|
|
|
|
zyre.zyre_set_header(self.node, key, value)
|
|
|
|
end
|
2014-06-25 13:31:42 +00:00
|
|
|
--zyre.zyre_set_verbose(self.node)
|
|
|
|
zyre.zyre_set_interface(self.node, "wlan0")
|
2014-06-23 14:33:11 +00:00
|
|
|
zyre.zyre_start(self.node)
|
|
|
|
zyre.zyre_join(self.node, "GLOBAL")
|
2014-06-25 13:31:42 +00:00
|
|
|
--zyre.zyre_dump(self.node)
|
2014-06-23 14:33:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ZyreMessageQueue:stop()
|
|
|
|
if self.node ~= nil then
|
|
|
|
DEBUG("stop zyre node")
|
|
|
|
zyre.zyre_stop(self.node)
|
|
|
|
zyre.zyre_destroy(ffi.new('zyre_t *[1]', self.node))
|
|
|
|
end
|
2014-06-25 13:31:42 +00:00
|
|
|
if self.poller ~= nil then
|
|
|
|
czmq.zpoller_destroy(ffi.new('zpoller_t *[1]', self.poller))
|
|
|
|
end
|
2014-06-23 14:33:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ZyreMessageQueue:waitEvent()
|
2014-06-25 13:31:42 +00:00
|
|
|
if czmq.zpoller_wait(self.poller, 0) ~= nil then
|
|
|
|
local msg = zyre.zyre_recv(self.node)
|
|
|
|
if msg ~= nil then
|
|
|
|
table.insert(self.messages, msg)
|
|
|
|
end
|
2014-06-23 14:33:11 +00:00
|
|
|
end
|
|
|
|
return self:handleZMsgs(self.messages)
|
|
|
|
end
|
|
|
|
|
|
|
|
return ZyreMessageQueue
|