http_subscribe.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "define.h"
  3. #if USE_NET_HTTP_WEBSITE
  4. #include <regex>
  5. #include <functional>
  6. #include <shared_mutex>
  7. #include "http_interface.h"
  8. namespace ylib
  9. {
  10. namespace network
  11. {
  12. namespace http
  13. {
  14. class request;
  15. class response;
  16. class reqpack;
  17. struct subscribe_info {
  18. std::regex regex;
  19. std::string pattern;
  20. std::string extra;
  21. std::function<void(network::http::request* request,network::http::response* response,const std::string& pattern,const std::string& extra)> callback;
  22. };
  23. /******************************************************
  24. * class:订阅器
  25. ******************************************************/
  26. class subscribe :public ylib::error_base, public network::http::interface_
  27. {
  28. public:
  29. subscribe();
  30. ~subscribe();
  31. bool add(const std::string& pattern,const std::string& extra,std::function<void(network::http::request* request, network::http::response* response, const std::string& pattern, const std::string& extra)> callback);
  32. bool remove(const std::string& pattern);
  33. bool exist(const std::string& pattern);
  34. bool trigger(const std::string& url, network::http::reqpack* rp);
  35. void clear();
  36. private:
  37. std::vector<subscribe_info> m_list;
  38. std::shared_mutex m_rw_mutex;
  39. };
  40. }
  41. }
  42. }
  43. #endif