BusinessConfig.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. void sendVoiceTcp(std::string action, TcpModel model, int toId){
  47. //发出TCP
  48. TcpModel tcpModel;
  49. tcpModel.tid = model.tid;
  50. tcpModel.type = TcpType::VOICE;
  51. tcpModel.action = action;
  52. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  53. tcpModel.to_id = toId;
  54. if (model.data!=""){
  55. tcpModel.data = model.data;
  56. } else if (model.json>0){
  57. tcpModel.json = model.json;
  58. }
  59. std::string req = getTcpModelString(tcpModel);
  60. LOGD("sendVoiceTcp : %s",req.c_str());
  61. // TcpClient::instance()->sendMsg(req.c_str());
  62. //回调注册
  63. TcpCallback callback;
  64. callback.tid = tcpModel.tid;
  65. callback.jsonStr = req;
  66. callback.onSuccess = [](Json::Value json){
  67. LOGD("voice callback success");
  68. return 0;
  69. };
  70. callback.onFalied = [](Json::Value json){
  71. LOGD("voice callback failed");
  72. return 0;
  73. };
  74. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  75. }
  76. TcpCacheManager::TcpCacheManager() {
  77. }
  78. TcpCacheManager::~TcpCacheManager() {
  79. }
  80. TcpCacheManager* TcpCacheManager::instance() {
  81. static TcpCacheManager singleton;
  82. return &singleton;
  83. }
  84. void TcpCacheManager::setFunc(const std::string tid, TcpCallback callback){
  85. TcpCacheManager::cb.insert(std::map<std::string, TcpCallback>::value_type(tid, callback));
  86. }
  87. TcpCallback TcpCacheManager::getFunc(const std::string tid){
  88. std::map<std::string, TcpCallback>::iterator it;
  89. it = TcpCacheManager::cb.find(tid);
  90. TcpCallback callback;
  91. if (it != TcpCacheManager::cb.end()){
  92. callback = it->second;
  93. TcpCacheManager::cb.erase(tid);
  94. return callback;
  95. }
  96. callback.tid = "0";
  97. return callback;
  98. }