Этот коммит содержится в:
Alexander UR6LKW
2025-05-19 16:51:57 +03:00
родитель 058607fe5b
Коммит 65914bc653
16 изменённых файлов: 1430 добавлений и 0 удалений
+54
Просмотреть файл
@@ -0,0 +1,54 @@
import logging
import time
from abc import ABC, abstractmethod
from .call import Call
from .dmrproto import DMRPPacketData
class AppException(Exception):
pass
class IAppDispatcher(ABC):
"""
Dispatcher interface for app
"""
@abstractmethod
def inject_packet(self, p: DMRPPacketData) -> None:
pass
class IAppCallInterceptor(ABC):
@abstractmethod
def process_call_packet(self, call: Call, p: DMRPPacketData) -> None:
pass
class App(ABC):
def __init__(self) -> None:
self.dispatcher: IAppDispatcher|None = None
@abstractmethod
def get_name(self) -> str:
pass
class AppKeeper:
def __init__(self, dispatcher: IAppDispatcher):
self.dispatcher: IAppDispatcher = dispatcher
self.apps: list[App] = []
def register(self, app: App) -> bool:
logging.info(f"Registered app '{app.get_name()}' ")
app.dispatcher = self.dispatcher
self.apps.append(app)
return True
def process_call_packet(self, call: Call, p: DMRPPacketData) -> None:
for app in self.apps:
if isinstance(app, IAppCallInterceptor):
app.process_call_packet(call, p)