2024-02-19 16:26:59 +03:00
|
|
|
"""Facilitates communication between processes."""
|
|
|
|
|
|
|
|
|
|
from enum import Enum
|
2025-08-08 15:08:37 +03:00
|
|
|
from typing import Any
|
2024-02-19 16:26:59 +03:00
|
|
|
|
2024-06-22 00:30:19 +03:00
|
|
|
from .zmq_proxy import Publisher, Subscriber
|
2024-02-19 16:26:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class DetectionTypeEnum(str, Enum):
|
|
|
|
|
all = ""
|
2024-04-02 16:07:50 +03:00
|
|
|
api = "api"
|
2024-02-19 16:26:59 +03:00
|
|
|
video = "video"
|
|
|
|
|
audio = "audio"
|
2025-03-23 22:30:48 +03:00
|
|
|
lpr = "lpr"
|
2024-02-19 16:26:59 +03:00
|
|
|
|
|
|
|
|
|
2024-06-22 00:30:19 +03:00
|
|
|
class DetectionPublisher(Publisher):
|
2024-02-19 16:26:59 +03:00
|
|
|
"""Simplifies receiving video and audio detections."""
|
|
|
|
|
|
2024-06-22 00:30:19 +03:00
|
|
|
topic_base = "detection/"
|
2024-02-19 16:26:59 +03:00
|
|
|
|
2025-08-08 15:08:37 +03:00
|
|
|
def __init__(self, topic: str) -> None:
|
2024-06-22 00:30:19 +03:00
|
|
|
super().__init__(topic)
|
2024-02-19 16:26:59 +03:00
|
|
|
|
|
|
|
|
|
2024-06-22 00:30:19 +03:00
|
|
|
class DetectionSubscriber(Subscriber):
|
|
|
|
|
"""Simplifies receiving video and audio detections."""
|
2024-02-19 16:26:59 +03:00
|
|
|
|
2024-06-22 00:30:19 +03:00
|
|
|
topic_base = "detection/"
|
2024-02-19 16:26:59 +03:00
|
|
|
|
2025-08-08 15:08:37 +03:00
|
|
|
def __init__(self, topic: str) -> None:
|
2024-06-22 00:30:19 +03:00
|
|
|
super().__init__(topic)
|
|
|
|
|
|
|
|
|
|
def check_for_update(
|
2025-08-08 15:08:37 +03:00
|
|
|
self, timeout: float | None = None
|
|
|
|
|
) -> tuple[str, Any] | tuple[None, None] | None:
|
2024-06-22 00:30:19 +03:00
|
|
|
return super().check_for_update(timeout)
|
|
|
|
|
|
2025-05-13 17:27:20 +03:00
|
|
|
def _return_object(self, topic: str, payload: Any) -> Any:
|
2024-06-22 00:30:19 +03:00
|
|
|
if payload is None:
|
|
|
|
|
return (None, None)
|
2025-08-08 15:08:37 +03:00
|
|
|
return (topic[len(self.topic_base) :], payload)
|