Holger Hans Peter Freyther | 4a62bb0 | 2018-02-25 21:17:30 +0000 | [diff] [blame^] | 1 | json = require("json") |
| 2 | socket = require("socket") |
| 3 | socket.unix = require("socket.unix") |
| 4 | |
| 5 | local g_c = socket.unix.dgram() |
| 6 | local g_ms = nil |
| 7 | |
| 8 | local mod = {} |
| 9 | |
| 10 | -- Register the MS instance with the system |
| 11 | function mod.register(ms, path) |
| 12 | g_ms = ms |
| 13 | |
| 14 | g_c:connect(path) |
| 15 | |
| 16 | local event = {} |
| 17 | event['ms'] = g_ms |
| 18 | event['type'] = 'register' |
| 19 | g_c:send(json.encode(event)) |
| 20 | end |
| 21 | |
| 22 | -- Send an event |
| 23 | function mod.send(data) |
| 24 | local event = {} |
| 25 | event['ms'] = g_ms |
| 26 | event['type'] = 'event' |
| 27 | event['data'] = data |
| 28 | g_c:send(json.encode(event)) |
| 29 | end |
| 30 | |
| 31 | return mod |