config_simple.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _RPC_CONFIG_H_
  2. #define _RPC_CONFIG_H_
  3. #include <string>
  4. #include <vector>
  5. #include <unordered_map>
  6. #include "Json.h"
  7. namespace srpc
  8. {
  9. class RPCConfig
  10. {
  11. public:
  12. using ErrorPageMap = std::unordered_map<int, std::string>;
  13. bool load(const char *file);
  14. unsigned short server_port() const { return this->s_port; }
  15. const char *server_cert_file() const { return this->s_cert_file.c_str(); }
  16. const char *server_file_key() const { return this->s_file_key.c_str(); }
  17. unsigned short client_port() const { return this->c_port; }
  18. const char *client_host() const { return this->c_host.c_str(); }
  19. int redirect_max() const { return this->c_redirect_max; }
  20. int retry_max() const { return this->c_retry_max; }
  21. const char *client_user_name() const { return this->c_user_name.c_str(); }
  22. const char *client_password() const { return this->c_password.c_str(); }
  23. const char *get_root_path() const { return this->root_path.c_str(); }
  24. const ErrorPageMap& get_error_page() const { return this->error_page; }
  25. public:
  26. RPCConfig() : s_port(0), c_port(0), c_redirect_max(0), c_retry_max(0) { }
  27. ~RPCConfig();
  28. private:
  29. void load_server();
  30. void load_client();
  31. wfrest::Json data;
  32. unsigned short s_port;
  33. std::string s_cert_file;
  34. std::string s_file_key;
  35. std::string c_host;
  36. unsigned short c_port;
  37. int c_redirect_max;
  38. int c_retry_max;
  39. std::string c_user_name;
  40. std::string c_password;
  41. std::string root_path;
  42. ErrorPageMap error_page;
  43. };
  44. }
  45. #endif