SignalHandler.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef SIGNALHANDLER_H
  2. #define SIGNALHANDLER_H
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. #include <ctime>
  9. #include <functional>
  10. #include "SignalEvent.h"
  11. using namespace std;
  12. /*
  13. SignalHandler will run a certain function whenever the signal is emitted and received, which "handles" the signal and data passed through
  14. This runs or handles the state change in the observer
  15. */
  16. class SignalHandler{
  17. public:
  18. //creates the signal handler with a unique id
  19. SignalHandler();
  20. ~SignalHandler();
  21. //gets the id of handler
  22. string getID() const;
  23. //function used to handler the event and its data
  24. virtual void handle(SignalEvent* event) = 0;
  25. private:
  26. string id;
  27. };
  28. /*
  29. FunctionHandler is a signal handler will take a function as a paramter for contruction and use that to handle the signal instead
  30. */
  31. class FunctionHandler: public SignalHandler{
  32. public:
  33. //creates the signal handler with a function to store. Note that this is normally a function lambda
  34. FunctionHandler(function<void(SignalEvent*)> newFunc);
  35. //copy constructor for the handler
  36. FunctionHandler(FunctionHandler& other);
  37. ~FunctionHandler();
  38. protected:
  39. //function used to run the function contained to handle the event and its data
  40. virtual void handle(SignalEvent* event);
  41. //variable used to store the function. Function is a void type that takes a signalEvent ptr as a parameter
  42. function<void(SignalEvent*)> func;
  43. };
  44. #endif