TeBkUmMgr.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. Copyright 2009-2020, Sumeet Chhetri
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. * TeBkUmMgr.h
  15. *
  16. * Created on: 03-Feb-2020
  17. * Author: sumeetc
  18. */
  19. #ifndef WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmMgr_H_
  20. #define WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmMgr_H_
  21. #include "TemplateHandler.h"
  22. #include "vector"
  23. #ifndef OS_MINGW
  24. #include <netinet/in.h>
  25. #include <arpa/inet.h>
  26. #endif
  27. #include "DataSourceManager.h"
  28. #include <stdlib.h>
  29. #include <algorithm>
  30. #include "CryptoHandler.h"
  31. #include "vector"
  32. #include "CastUtil.h"
  33. #include <stdlib.h>
  34. #include "CacheManager.h"
  35. #include "HttpRequest.h"
  36. #include "HttpResponse.h"
  37. #include "JSONSerialize.h"
  38. #include "string"
  39. #include "yuarel.h"
  40. #include "Router.h"
  41. typedef void (*TeBkUmMgrTemplatePtr) (Context*, std::string&);
  42. class TeBkUmMgrWorld {
  43. int id;
  44. int randomNumber;
  45. public:
  46. TeBkUmMgrWorld();
  47. virtual ~TeBkUmMgrWorld();
  48. int getId() const;
  49. void setId(int id);
  50. int getRandomNumber() const;
  51. void setRandomNumber(int randomNumber);
  52. };
  53. class TeBkUmMgrFortune {
  54. int id;
  55. std::string message;
  56. public:
  57. TeBkUmMgrFortune();
  58. virtual ~TeBkUmMgrFortune();
  59. int getId() const;
  60. void setId(int id);
  61. const std::string& getMessage() const;
  62. void setMessage(const std::string& message);
  63. bool operator < (const TeBkUmMgrFortune& other) const;
  64. };
  65. class TeBkUmMgrMessage {
  66. std::string message;
  67. public:
  68. virtual ~TeBkUmMgrMessage();
  69. const std::string& getMessage() const;
  70. void setMessage(const std::string& message);
  71. };
  72. class TeBkUmMgrRouter : public Router {
  73. static const std::string HELLO_WORLD;
  74. static std::string WORLD;
  75. static std::string FORTUNE;
  76. static std::string APP_NAME;
  77. static std::string TPE_FN_NAME;
  78. bool strToNum(const char* str, int len, int& ret);
  79. void db(TeBkUmMgrWorld&);
  80. void queries(const char*, int, std::vector<TeBkUmMgrWorld>&);
  81. #ifdef INC_SDORM_MONGO
  82. static void dbUtil(void* ctx, int rn, std::vector<MgRawRes>& data);
  83. #endif
  84. void updates(const char*, int, std::vector<TeBkUmMgrWorld>&);
  85. void cachedWorlds(const char*, int, std::vector<TeBkUmMgrWorld>&);
  86. #ifdef INC_SDORM_MONGO
  87. static void updateCacheUtil(void* ctx, int rn, std::vector<MgRawRes>& data);
  88. #endif
  89. void getContext(HttpRequest* request, Context* context);
  90. #ifdef INC_SDORM_MONGO
  91. static void getContextUtil(void* ctx, int rn, std::vector<MgRawRes>& data);
  92. MongoDBRawDataSourceImpl* sqli;
  93. MongoDBRawDataSourceImpl* getDb();
  94. #endif
  95. public:
  96. TeBkUmMgrRouter();
  97. virtual ~TeBkUmMgrRouter();
  98. void updateCache();
  99. bool route(HttpRequest* req, HttpResponse* res, void* dlib, void* ddlib, SocketInterface* sif);
  100. };
  101. #endif /* WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmMgr_H_ */