123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /*
- * 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<std::string, TcpCallback>::value_type(tid, callback));
- }
- TcpCallback TcpCacheManager::getFunc(const std::string tid){
- std::map<std::string, TcpCallback>::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;
- }
|