From 40219aa5ff570f83ff05ec885dc95443fd821f4f Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 5 Aug 2022 19:05:07 +0530 Subject: [PATCH] Common: Add TODO in IEventQueue --- monkey/common/event_queue/i_event_queue.py | 3 ++ .../event_queue/pypubsub_event_queue.py | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 monkey/common/event_queue/pypubsub_event_queue.py diff --git a/monkey/common/event_queue/i_event_queue.py b/monkey/common/event_queue/i_event_queue.py index 960b5b385..03689b814 100644 --- a/monkey/common/event_queue/i_event_queue.py +++ b/monkey/common/event_queue/i_event_queue.py @@ -51,3 +51,6 @@ class IEventQueue(ABC): """ pass + + +# TODO: Add unsubscribing functions diff --git a/monkey/common/event_queue/pypubsub_event_queue.py b/monkey/common/event_queue/pypubsub_event_queue.py new file mode 100644 index 000000000..486233fd0 --- /dev/null +++ b/monkey/common/event_queue/pypubsub_event_queue.py @@ -0,0 +1,43 @@ +from typing import Any, Callable, Sequence + +from common.events import AbstractEvent +from .i_event_queue import IEventQueue +from pubsub import pub, ALL_TOPICS + + +class PypubsubEventQueue(IEventQueue): + + @staticmethod + def subscribe_all(subscriber: Callable[..., Any]): + pub.subscribe(listener=subscriber, topicName=ALL_TOPICS) + + def subscribe_types(self, types: Sequence[AbstractEvent], subscriber: Callable[..., Any]): + """ + Subscribes a subscriber to all specifed event types + + :param types: Event types to which the subscriber should subscribe + :param subscriber: Callable that should subscribe to events + """ + + pass + + def subscribe_tags(self, tags: Sequence[str], subscriber: Callable[..., Any]): + """ + Subscribes a subscriber to all specified event tags + + :param tags: Event tags to which the subscriber should subscribe + :param subscriber: Callable that should subscribe to events + """ + + pass + + def publish(self, event: AbstractEvent, data: Any): + """ + Publishes an event with the given data + + :param event: Event to publish + :param data: Data to pass to subscribers with the event publish + """ + + pass +