From a4f075a4c1c96830694afce4cd9149b1c347b105 Mon Sep 17 00:00:00 2001
From: Fabio Manganiello <blacklight86@gmail.com>
Date: Mon, 24 Sep 2018 09:18:46 +0000
Subject: [PATCH] Added support for ApplicationStartedEvent and
 ApplicationStoppedEvent

---
 platypush/__init__.py                  |  4 ++++
 platypush/message/event/application.py | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 platypush/message/event/application.py

diff --git a/platypush/__init__.py b/platypush/__init__.py
index c6750c3a..fb4de4d2 100644
--- a/platypush/__init__.py
+++ b/platypush/__init__.py
@@ -19,6 +19,7 @@ from .context import register_backends
 from .cron.scheduler import CronScheduler
 from .event.processor import EventProcessor
 from .message.event import Event, StopEvent
+from .message.event.application import ApplicationStartedEvent, ApplicationStoppedEvent
 from .message.request import Request
 from .message.response import Response
 
@@ -113,6 +114,7 @@ class Daemon:
 
     def stop_app(self):
         """ Stops the backends and the bus """
+        self.bus.post(ApplicationStoppedEvent())
         for backend in self.backends.values():
             backend.stop()
         self.bus.stop()
@@ -133,6 +135,8 @@ class Daemon:
         if Config.get_cronjobs():
             CronScheduler(jobs=Config.get_cronjobs()).start()
 
+        self.bus.post(ApplicationStartedEvent())
+
         # Poll for messages on the bus
         try:
             self.bus.poll()
diff --git a/platypush/message/event/application.py b/platypush/message/event/application.py
new file mode 100644
index 00000000..40adbc7d
--- /dev/null
+++ b/platypush/message/event/application.py
@@ -0,0 +1,23 @@
+from platypush.message.event import Event
+
+
+class ApplicationStartedEvent(Event):
+    """
+    Event triggered when the application has started and all the backends have been registered
+    """
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+
+class ApplicationStoppedEvent(Event):
+    """
+    Event triggered when the application stops
+    """
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+
+
+# vim:sw=4:ts=4:et:
+