TeBkUmLpq.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * TeBkUmLpq.h
  15. *
  16. * Created on: 03-Feb-2020
  17. * Author: sumeetc
  18. */
  19. #ifndef WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmLpq_H_
  20. #define WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmLpq_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 (*TeBkUmLpqTemplatePtr) (Context*, std::string&);
  42. class TeBkUmLpqWorld {
  43. int id;
  44. int randomNumber;
  45. public:
  46. TeBkUmLpqWorld();
  47. virtual ~TeBkUmLpqWorld();
  48. int getId() const;
  49. void setId(int id);
  50. int getRandomNumber() const;
  51. void setRandomNumber(int randomNumber);
  52. };
  53. struct UpdQrData {
  54. std::vector<TeBkUmLpqWorld>* wlist;
  55. std::stringstream* ss;
  56. bool status;
  57. int queryCount;
  58. };
  59. class TeBkUmLpqFortune {
  60. int id;
  61. std::string message;
  62. public:
  63. TeBkUmLpqFortune();
  64. virtual ~TeBkUmLpqFortune();
  65. int getId() const;
  66. void setId(int id);
  67. const std::string& getMessage() const;
  68. void setMessage(const std::string& message);
  69. bool operator < (const TeBkUmLpqFortune& other) const;
  70. };
  71. class TeBkUmLpqMessage {
  72. std::string message;
  73. public:
  74. virtual ~TeBkUmLpqMessage();
  75. const std::string& getMessage() const;
  76. void setMessage(const std::string& message);
  77. };
  78. class TeBkUmLpqRouter : public Router {
  79. static const std::string HELLO_WORLD;
  80. static std::string WORLD;
  81. static std::string WORLD_ONE_QUERY;
  82. static std::string WORLD_ALL_QUERY;
  83. static std::string FORTUNE_ALL_QUERY;
  84. static std::string APP_NAME;
  85. static std::string TPE_FN_NAME;
  86. static bool strToNum(const char* str, int len, int& ret);
  87. void db(TeBkUmLpqWorld&);
  88. void queries(const char*, int, std::vector<TeBkUmLpqWorld>&);
  89. void queriesMulti(const char*, int, std::vector<TeBkUmLpqWorld>&);
  90. static void dbUtil(void* ctx, int, int, char *);
  91. static void queriesMultiUtil(void* ctx, int, int, char *, int);
  92. void updates(const char*, int, std::vector<TeBkUmLpqWorld>&);
  93. static void updatesUtil(void* ctx, int, int, char *);
  94. void updatesMulti(const char*, int, std::vector<TeBkUmLpqWorld>&);
  95. static void updatesMultiUtil(void* ctx, int, int, char *, int);
  96. static void updatesMultiUtilCh(void* ctx, bool status, const std::string& query, int counter);
  97. void cachedWorlds(const char*, int, std::vector<TeBkUmLpqWorld>&);
  98. static void updateCacheUtil(void* ctx, int rn, std::vector<LibpqRes>& data);
  99. void getContext(HttpRequest* request, Context* context);
  100. static void getContextUtil(void* ctx, int, int, char *, int);
  101. std::map<int, std::string> _qC;
  102. LibpqDataSourceImpl* sqli;
  103. LibpqDataSourceImpl* getDb();
  104. std::string& getUpdQuery(int count);
  105. public:
  106. TeBkUmLpqRouter();
  107. virtual ~TeBkUmLpqRouter();
  108. void updateCache();
  109. bool route(HttpRequest* req, HttpResponse* res, void* dlib, void* ddlib, SocketInterface* sif);
  110. };
  111. #endif /* WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmLpq_H_ */