BusinessConfig.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * BusinessConfig.cpp
  3. *
  4. * Created on: 2022年10月18日
  5. * Author: Allen
  6. */
  7. #include "BusinessConfig.h"
  8. #include "base/strings.hpp"
  9. CallingStatus::CallingStatus() {
  10. _busy = false;
  11. }
  12. CallingStatus::~CallingStatus() {
  13. }
  14. CallingStatus* CallingStatus::instance() {
  15. static CallingStatus singleton;
  16. return &singleton;
  17. }
  18. void CallingStatus::setBusy(bool busy){
  19. _busy = busy;
  20. }
  21. void CallingStatus::setTcpModel(TcpModel tcpModel){
  22. _tcpModel = tcpModel;
  23. }
  24. void CallingStatus::clearTcpModel(){
  25. _tcpModel.type = "";
  26. _tcpModel.action = "";
  27. _tcpModel.from_id = 0;
  28. _tcpModel.to_id = 0;
  29. _tcpModel.json = NULL;
  30. _tcpModel.data = "";
  31. }
  32. TcpModel CallingStatus::getTcpModel(){
  33. return _tcpModel;
  34. }
  35. long CallingStatus::getInteractionId(){
  36. if (_tcpModel.json > 0){
  37. if (_tcpModel.json.isMember("id")){
  38. return _tcpModel.json["id"].asInt();
  39. }
  40. }
  41. return 0;
  42. }
  43. bool CallingStatus::busy() {
  44. return instance()->_busy;
  45. }
  46. TcpCacheManager::TcpCacheManager() {
  47. }
  48. TcpCacheManager::~TcpCacheManager() {
  49. }
  50. TcpCacheManager* TcpCacheManager::instance() {
  51. static TcpCacheManager singleton;
  52. return &singleton;
  53. }
  54. void TcpCacheManager::setFunc(const std::string tid, TcpCallback callback){
  55. TcpCacheManager::cb.insert(std::map<std::string, TcpCallback>::value_type(tid, callback));
  56. }
  57. TcpCallback TcpCacheManager::getFunc(const std::string tid){
  58. std::map<std::string, TcpCallback>::iterator it;
  59. it = TcpCacheManager::cb.find(tid);
  60. TcpCallback callback;
  61. if (it != TcpCacheManager::cb.end()){
  62. callback = it->second;
  63. TcpCacheManager::cb.erase(tid);
  64. return callback;
  65. }
  66. callback.tid = "0";
  67. return callback;
  68. }