X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fwatch.py;h=6d3dcd9fa8ed7eb1f4eba1cdacd266549e9b2519;hb=84861997657f7a8daab41aa13790981bd77749f8;hp=7221d2b716595fb05623f1f66a8d476aaeee9d3c;hpb=5ef83cb7db7464a5a625b0b7c86c4e25ebbb0de1;p=loctrkd.git diff --git a/loctrkd/watch.py b/loctrkd/watch.py index 7221d2b..6d3dcd9 100644 --- a/loctrkd/watch.py +++ b/loctrkd/watch.py @@ -8,19 +8,12 @@ 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] = [] @@ -28,7 +21,7 @@ def runserver(conf: ConfigParser) -> None: global pmods pmods = [ cast(ProtoModule, import_module("." + modnm, __package__)) - for modnm in conf.get("collector", "protocols").split(",") + for modnm in conf.get("common", "protocols").split(",") ] # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?! zctx = zmq.Context() # type: ignore @@ -41,9 +34,11 @@ def runserver(conf: ConfigParser) -> None: 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): + if pmod.proto_handled(zmsg.proto): 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