allow AsyncSignalHandler to attach and detach from an EventBase
[folly.git] / folly / io / async / AsyncSignalHandler.h
index bd8cffff3f24f58a15bceeb8e7db79fa95bf564f..056655337cb7accbc3dd7adf0e34f9fc188ee5e6 100644 (file)
@@ -16,7 +16,7 @@
 #pragma once
 
 #include <folly/io/async/EventBase.h>
-#include <event.h>
+#include <folly/portability/Event.h>
 #include <map>
 
 namespace folly {
@@ -48,6 +48,30 @@ class AsyncSignalHandler {
   explicit AsyncSignalHandler(EventBase* eventBase);
   virtual ~AsyncSignalHandler();
 
+  /**
+   * Attach this AsyncSignalHandler to an EventBase.
+   *
+   * This should only be called if the AsyncSignalHandler is not currently
+   * registered for any signals and is not currently attached to an existing
+   * EventBase.
+   */
+  void attachEventBase(EventBase* eventBase);
+
+  /**
+   * Detach this AsyncSignalHandler from its EventBase.
+   *
+   * This should only be called if the AsyncSignalHandler is not currently
+   * registered for any signals.
+   */
+  void detachEventBase();
+
+  /**
+   * Get the EventBase used by this AsyncSignalHandler.
+   */
+  EventBase* getEventBase() const {
+    return eventBase_;
+  }
+
   /**
    * Register to receive callbacks about the specified signal.
    *
@@ -86,7 +110,7 @@ class AsyncSignalHandler {
 
   static void libeventCallback(libevent_fd_t signum, short events, void* arg);
 
-  EventBase* eventBase_;
+  EventBase* eventBase_{nullptr};
   SignalEventMap signalEvents_;
 };