2017-12-18 01:10:51 +01:00
|
|
|
from queue import Queue
|
|
|
|
|
|
|
|
class Bus(object):
|
|
|
|
""" Main local bus where the daemon will listen for new messages """
|
|
|
|
|
2017-12-18 03:09:38 +01:00
|
|
|
def __init__(self, on_msg=None):
|
2017-12-18 01:10:51 +01:00
|
|
|
self.bus = Queue()
|
|
|
|
self.on_msg = on_msg
|
|
|
|
|
|
|
|
def post(self, msg):
|
|
|
|
""" Sends a message to the bus """
|
|
|
|
self.bus.put(msg)
|
|
|
|
|
|
|
|
def loop_forever(self):
|
|
|
|
""" Reads messages from the bus """
|
2017-12-18 03:09:38 +01:00
|
|
|
if not self.on_msg: return
|
|
|
|
|
2017-12-18 01:10:51 +01:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
self.on_msg(self.bus.get())
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
return
|
|
|
|
|
|
|
|
# vim:sw=4:ts=4:et:
|
|
|
|
|