/* * BusinessConfig.cpp * * Created on: 2022年10月18日 * Author: Allen */ #include "BusinessConfig.h" #include "base/strings.hpp" CallingStatus::CallingStatus() { _busy = false; } CallingStatus::~CallingStatus() { } CallingStatus* CallingStatus::instance() { static CallingStatus singleton; return &singleton; } void CallingStatus::setBusy(bool busy){ _busy = busy; } void CallingStatus::setTcpModel(TcpModel tcpModel){ _tcpModel = tcpModel; } void CallingStatus::clearTcpModel(){ _tcpModel.type = ""; _tcpModel.action = ""; _tcpModel.from_id = 0; _tcpModel.to_id = 0; _tcpModel.json = NULL; _tcpModel.data = ""; } TcpModel CallingStatus::getTcpModel(){ return _tcpModel; } long CallingStatus::getInteractionId(){ if (_tcpModel.json > 0){ if (_tcpModel.json.isMember("id")){ return _tcpModel.json["id"].asInt(); } } return 0; } bool CallingStatus::busy() { return instance()->_busy; } void sendVoiceTcp(std::string action, TcpModel model, int toId){ //发出TCP TcpModel tcpModel; tcpModel.tid = model.tid; tcpModel.type = TcpType::VOICE; tcpModel.action = action; tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0); tcpModel.to_id = toId; if (model.data!=""){ tcpModel.data = model.data; } else if (model.json>0){ tcpModel.json = model.json; } std::string req = getTcpModelString(tcpModel); LOGD("sendVoiceTcp : %s",req.c_str()); // TcpClient::instance()->sendMsg(req.c_str()); //回调注册 TcpCallback callback; callback.tid = tcpModel.tid; callback.jsonStr = req; callback.onSuccess = [](Json::Value json){ LOGD("voice callback success"); return 0; }; callback.onFalied = [](Json::Value json){ LOGD("voice callback failed"); return 0; }; TcpClient::instance()->sendMsgWithCb(req.c_str(), callback); } TcpCacheManager::TcpCacheManager() { } TcpCacheManager::~TcpCacheManager() { } TcpCacheManager* TcpCacheManager::instance() { static TcpCacheManager singleton; return &singleton; } void TcpCacheManager::setFunc(const std::string tid, TcpCallback callback){ TcpCacheManager::cb.insert(std::map::value_type(tid, callback)); } TcpCallback TcpCacheManager::getFunc(const std::string tid){ std::map::iterator it; it = TcpCacheManager::cb.find(tid); TcpCallback callback; if (it != TcpCacheManager::cb.end()){ callback = it->second; TcpCacheManager::cb.erase(tid); return callback; } callback.tid = "0"; return callback; }