TeBkUmMgr.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_t1_INCLUDE_TeBkUmMgr_H_
  20. #define WEB_t1_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. class TeBkUmMgrWorld {
  42. int id;
  43. int randomNumber;
  44. public:
  45. TeBkUmMgrWorld(int id);
  46. TeBkUmMgrWorld(int id, int randomNumber);
  47. TeBkUmMgrWorld();
  48. virtual ~TeBkUmMgrWorld();
  49. int getId() const;
  50. void setId(int id);
  51. int getRandomNumber() const;
  52. void setRandomNumber(int randomNumber);
  53. };
  54. class TeBkUmMgrFortune {
  55. int id;
  56. std::string message;
  57. public:
  58. TeBkUmMgrFortune();
  59. virtual ~TeBkUmMgrFortune();
  60. int getId() const;
  61. void setId(int id);
  62. const std::string& getMessage() const;
  63. void setMessage(const std::string& message);
  64. bool operator < (const TeBkUmMgrFortune& other) const;
  65. };
  66. class TeBkUmMgrMessage {
  67. std::string message;
  68. public:
  69. virtual ~TeBkUmMgrMessage();
  70. const std::string& getMessage() const;
  71. void setMessage(const std::string& message);
  72. };
  73. class TeBkUmMgrRouter : public Router {
  74. static const std::string HELLO_WORLD;
  75. static std::string WORLD;
  76. static std::string FORTUNE;
  77. static TemplatePtr tmplFunc;
  78. static Ser m_ser;
  79. static Ser w_ser;
  80. static SerCont wcont_ser;
  81. bool strToNum(const char* str, int len, int& ret);
  82. void db(TeBkUmMgrWorld&);
  83. void queries(const char*, int, std::vector<TeBkUmMgrWorld>&);
  84. #ifdef INC_SDORM_MONGO
  85. static void dbUtil(void* ctx, int rn, std::vector<MgRawRes>& data);
  86. #endif
  87. void updates(const char*, int, std::vector<TeBkUmMgrWorld>&);
  88. void cachedWorlds(const char*, int, std::vector<TeBkUmMgrWorld>&);
  89. #ifdef INC_SDORM_MONGO
  90. static void updateCacheUtil(void* ctx, int rn, std::vector<MgRawRes>& data);
  91. #endif
  92. void getContext(HttpRequest* request, Context* context);
  93. #ifdef INC_SDORM_MONGO
  94. static void getContextUtil(void* ctx, int rn, std::vector<MgRawRes>& data);
  95. MongoDBRawDataSourceImpl* sqli;
  96. MongoDBRawDataSourceImpl* getDb();
  97. #endif
  98. public:
  99. TeBkUmMgrRouter();
  100. virtual ~TeBkUmMgrRouter();
  101. void updateCache();
  102. bool route(HttpRequest* req, HttpResponse* res, BaseSocket* sif);
  103. };
  104. #endif /* WEB_t1_INCLUDE_TeBkUmMgr_H_ */