2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/ui/message/filemessagequeue.lua
Frans de Jonge a2dcfe9aec
[doc] Tag @todo, @fixme and @warning (#5244)
This commit standardizes the various todos around the code a bit in a manner recognized by LDoc.

Besides drawing more attention by being displayed in the developer docs, they're also extractable with LDoc on the command line:

```sh
ldoc --tags todo,fixme *.lua
```

However, whether that particular usage offers any advantage over other search tools is questionable at best.

* and some random beautification
2019-08-23 19:53:53 +02:00

53 lines
1.7 KiB
Lua

local ffi = require("ffi")
local logger = require("logger")
local MessageQueue = require("ui/message/messagequeue")
local _ = require("ffi/zeromq_h")
local czmq = ffi.load("libs/libczmq.so.1")
local filemq = ffi.load("libs/libfmq.so.1")
local FileMessageQueue = MessageQueue:new{
client = nil,
server = nil,
}
function FileMessageQueue:init()
if self.client ~= nil then
self.fmq_recv = filemq.fmq_client_recv
self.filemq = self.client
self.poller = czmq.zpoller_new(filemq.fmq_client_handle(self.client), nil)
elseif self.server ~= nil then
--- @todo currently fmq_server_recv API is not available
--self.fmq_recv = filemq.fmq_server_recv
self.filemq = self.server
--- @todo currently fmq_server_handle API is not available
--self.poller = czmq.zpoller_new(filemq.fmq_server_handle(self.server), nil)
end
end
function FileMessageQueue:stop()
if self.client ~= nil then
logger.dbg("stop filemq client")
filemq.fmq_client_destroy(ffi.new('fmq_client_t *[1]', self.client))
end
if self.server ~= nil then
logger.dbg("stop filemq server")
filemq.fmq_server_destroy(ffi.new('fmq_server_t *[1]', self.server))
end
if self.poller ~= nil then
czmq.zpoller_destroy(ffi.new('zpoller_t *[1]', self.poller))
end
end
function FileMessageQueue:waitEvent()
if not self.poller then return end
if czmq.zpoller_wait(self.poller, 0) ~= nil then
local msg = self.fmq_recv(self.filemq)
if msg ~= nil then
table.insert(self.messages, msg)
end
end
return self:handleZMsgs(self.messages)
end
return FileMessageQueue