X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fwatch.py;h=bda952c259da36299fd5f8859b3c33363983720b;hb=456fcc5a8964c84385d34a6687e83ae05ab2ddc3;hp=ab041edc832c7ae78198ea5deb3375d9e32dff29;hpb=63a086cf3956b93f760b1a0344afd757e0d0392f;p=loctrkd.git diff --git a/loctrkd/watch.py b/loctrkd/watch.py index ab041ed..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 @@ -39,11 +24,13 @@ def runserver(conf: ConfigParser) -> None: try: while True: zmsg = Bcast(zsub.recv()) - print("Bcast:", zmsg) - for pmod in pmods: - if zmsg.proto.startswith(pmod.PROTO_PREFIX): - msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming) - print("I" if zmsg.is_incoming else "O", zmsg.imei, msg) + print("I" if zmsg.is_incoming else "O", zmsg.proto, zmsg.imei) + 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