X-Git-Url: http://www.average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fwatch.py;h=bda952c259da36299fd5f8859b3c33363983720b;hb=023da3cd78841eb34d8286cf289995be658f0fa2;hp=7221d2b716595fb05623f1f66a8d476aaeee9d3c;hpb=5ef83cb7db7464a5a625b0b7c86c4e25ebbb0de1;p=loctrkd.git diff --git a/loctrkd/watch.py b/loctrkd/watch.py index 7221d2b..bda952c 100644 --- a/loctrkd/watch.py +++ b/loctrkd/watch.py @@ -8,28 +8,13 @@ from typing import Any, cast, List import zmq from . import common +from .protomodule import ProtoModule from .zmsg import Bcast log = getLogger("loctrkd/watch") -class ProtoModule: - PROTO_PREFIX: str - - @staticmethod - def parse_message(packet: bytes, is_incoming: bool = True) -> Any: - ... - - -pmods: List[ProtoModule] = [] - - def runserver(conf: ConfigParser) -> None: - global pmods - pmods = [ - cast(ProtoModule, import_module("." + modnm, __package__)) - for modnm in conf.get("collector", "protocols").split(",") - ] # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?! zctx = zmq.Context() # type: ignore zsub = zctx.socket(zmq.SUB) # type: ignore @@ -40,10 +25,12 @@ def runserver(conf: ConfigParser) -> None: while True: zmsg = Bcast(zsub.recv()) print("I" if zmsg.is_incoming else "O", zmsg.proto, zmsg.imei) - for pmod in pmods: - if zmsg.proto.startswith(pmod.PROTO_PREFIX): - msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming) - print(msg) + pmod = common.pmod_for_proto(zmsg.proto) + if pmod is not None: + msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming) + print(msg) + if zmsg.is_incoming and hasattr(msg, "rectified"): + print(msg.rectified()) except KeyboardInterrupt: pass