ApiServer.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * @Description: ApiServer api服务器
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-04-01 15:44:09
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-04-15 11:19:25
  8. */
  9. #ifndef __APISERVER_HPP_
  10. #define __APISERVER_HPP_
  11. #include <iostream>
  12. #include "HttpServer.h"
  13. #include "hssl.h"
  14. #include "ins_base.hpp"
  15. using namespace std;
  16. namespace ins{
  17. class ApiServer:public Module
  18. {
  19. private:
  20. ApiServer(int port) : Module("ApiServer"), port_(port){
  21. Init();
  22. }
  23. /**
  24. * @description: 注册API
  25. * @param {*}
  26. * @return {*}
  27. */
  28. int8_t RegisterApi();
  29. public:
  30. using Ptr = std::shared_ptr<ApiServer>;
  31. virtual ~ApiServer(){this->Destroy();}
  32. /**
  33. * @description: 初始化
  34. * @param {*}
  35. * @return {*}
  36. */
  37. int8_t Init() override;
  38. /**
  39. * @description: 创建实例
  40. * @param {*}
  41. * @return {*}
  42. */
  43. static std::shared_ptr<ApiServer> CreateNew(int port);
  44. /**
  45. * @description: 获取实例
  46. * @param {*}
  47. * @return {*}
  48. */
  49. static std::shared_ptr<ApiServer> getPtr();
  50. /**
  51. * @description: 释放资源
  52. * @param {*}
  53. * @return {*}
  54. */
  55. void Destroy() override;
  56. /**
  57. * @description: 运行
  58. * @param {*}
  59. * @return {*}
  60. */
  61. int8_t Run();
  62. /**
  63. * @description: 是否正常
  64. * @param {*}
  65. * @return {*}
  66. */
  67. bool isNormally() override{
  68. return true;
  69. }
  70. protected:
  71. int port_;
  72. http_server_t server_;
  73. std::shared_ptr<HttpService> m_HttpService = nullptr;
  74. };
  75. };
  76. // 任务管理器
  77. #endif