MessageHandler.h 919 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef MESSAGE_HANDLER_H
  2. #define MESSAGE_HANDLER_H
  3. #include <boost/signals2.hpp>
  4. #include <string>
  5. #include "Object.h"
  6. /// A generic message handler.
  7. /// Using @ref write method you send a message to the slots connected to @ref sig signal
  8. class MessageHandler: public Object
  9. {
  10. public:
  11. typedef boost::signals2::signal<void (const char*, int, const char*, const std::string&)> Signal;
  12. MessageHandler(Object* parent = NULL): Object(parent) {}
  13. /// Emmits a message to the slots connected to @ref sig. A simple wrapper to hide the signal
  14. /// @param file Who send the message
  15. /// @param line Who send the message
  16. /// @param func Who send the message
  17. /// @param msg The message to emmit
  18. void write(const char* file, int line, const char* func, const std::string& msg) {sig(file, line, func, msg);}
  19. /// Accessor
  20. Signal& getSignal() {return sig;}
  21. private:
  22. Signal sig; ///< The signal
  23. };
  24. #endif