summaryrefslogtreecommitdiff
path: root/src/qlistener.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/qlistener.lua')
-rw-r--r--src/qlistener.lua37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/qlistener.lua b/src/qlistener.lua
index e3b774b..2a44019 100644
--- a/src/qlistener.lua
+++ b/src/qlistener.lua
@@ -21,25 +21,28 @@
local last_cart = nil
-require "posix"
+posix = require "posix"
mq = require "mq"
package.path = package.path .. ";" .. rhnoplibdir .. "/?.lua"
playlog = require "playlog"
rddb = require "rddb"
-
-conffile = "nopsyncd.conf"
conf = require "conf"
-if conf.music_carts_lo == nil then
- conf.music_carts_lo = 400000
-end
-if conf.music_carts_hi == nil then
- conf.music_carts_hi = 499999
-end
-conf.music_carts_lo = tonumber(conf.music_carts_lo)
-conf.music_carts_hi = tonumber(conf.music_carts_hi)
+local cnf = {}
+function init(conffile)
+ cnf = conf.load(conffile)
+ if cnf.music_carts_lo == nil then
+ cnf.music_carts_lo = 400000
+ end
+ if cnf.music_carts_hi == nil then
+ cnf.music_carts_hi = 499999
+ end
+ cnf.music_carts_lo = tonumber(cnf.music_carts_lo)
+ cnf.music_carts_hi = tonumber(cnf.music_carts_hi)
+end
+
function handle_now(timestamp, nowcart, nowlen)
local results, err = rddb:getCartInfo(nowcart);
if results == nil then
@@ -63,7 +66,7 @@ function handle_message(msg)
else
nowcart = tonumber(nowcart)
nowlen = tonumber(nowlen)
- if last_cart ~= nowcart and nowcart >= conf.music_carts_lo and nowcart <= conf.music_carts_hi and nowlen > 0 then
+ if last_cart ~= nowcart and nowcart >= cnf.music_carts_lo and nowcart <= cnf.music_carts_hi and nowlen > 0 then
last_cart = nowcart
handle_now(timestamp, nowcart, nowlen)
end
@@ -72,24 +75,26 @@ function handle_message(msg)
end
function main_loop()
+ init("nopsyncd.conf")
+
posix.umask("rwxrwxr-x")
- local q, err = mq.create(conf.queue_name, "ro", "rw-rw----")
+ local q, err = mq.create(cnf.queue_name, "ro", "rw-rw----")
if q == nil then
- q, err = mq.open(conf.queue_name, "wo")
+ q, err = mq.open(cnf.queue_name, "wo")
if q == nil then
io.stderr:write("creation of message queue failed: " .. err .. "\n")
os.exit(1)
end
end
- local ret, err = playlog:init()
+ local ret, err = playlog:init(cnf)
if ret == nil then
io.stderr:write("creation of playlog failed: " .. err .. "\n")
os.exit(1)
end
last_cart = assert(playlog:getLastCart())
- local ret, err = rddb:init()
+ local ret, err = rddb:init(cnf)
if ret == nil then
io.stderr:write("opening rivendell db failed: " .. err .. "\n")
playlog:close()