//------------------------------------------------------------------------------------- void BillingHandler_ThirdParty::onLoginAccountCB(KBEngine::MemoryStream& s) { std::string loginName, accountName, password, postdatas, getdatas; COMPONENT_ID cid; SERVER_ERROR_CODE success = SERVER_ERR_OP_FAILED; s >> cid >> loginName >> accountName >> password >> success; s.readBlob(postdatas); s.readBlob(getdatas); if(!success) { accountName = ""; } Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(LOGINAPP_TYPE, cid); if(cinfos == NULL || cinfos->pChannel == NULL) { ERROR_MSG("BillingHandler_ThirdParty::onCreateAccountCB: loginapp not found!\n"); return; } dbThreadPool_.addTask(new DBTaskAccountLogin(cinfos->pChannel->addr(), loginName, accountName, password, success, postdatas, getdatas)); }
void EntityApp<E>::onBroadcastGlobalDataChange(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string key, value; bool isDelete; s >> isDelete; s.readBlob(key); if(!isDelete) { s.readBlob(value); } PyObject * pyKey = script::Pickler::unpickle(key); if(pyKey == NULL) { ERROR_MSG("EntityApp::onBroadcastCellAppDataChange: no has key!\n"); return; } Py_INCREF(pyKey); if(isDelete) { if(pGlobalData_->del(pyKey)) { // 通知脚本 SCRIPT_OBJECT_CALL_ARGS1(getEntryScript().get(), const_cast<char*>("onGlobalDataDel"), const_cast<char*>("O"), pyKey); } } else { PyObject * pyValue = script::Pickler::unpickle(value); if(pyValue == NULL) { ERROR_MSG("EntityApp::onBroadcastCellAppDataChange: no has value!\n"); Py_DECREF(pyKey); return; } Py_INCREF(pyValue); if(pGlobalData_->write(pyKey, pyValue)) { // 通知脚本 SCRIPT_OBJECT_CALL_ARGS2(getEntryScript().get(), const_cast<char*>("onGlobalData"), const_cast<char*>("OO"), pyKey, pyValue); } Py_DECREF(pyValue); } Py_DECREF(pyKey); }
//------------------------------------------------------------------------------------- void InterfacesHandler_Interfaces::charge(Network::Channel* pChannel, KBEngine::MemoryStream& s) { Network::Channel* pInterfacesChannel = Dbmgr::getSingleton().networkInterface().findChannel(g_kbeSrvConfig.interfacesAddr()); KBE_ASSERT(pInterfacesChannel); if(pInterfacesChannel->isDestroyed()) { if(!this->reconnect()) return; } std::string chargeID; std::string datas; CALLBACK_ID cbid; DBID dbid; s >> chargeID; s >> dbid; s.readBlob(datas); s >> cbid; INFO_MSG(fmt::format("InterfacesHandler_Interfaces::charge: chargeID={0}, dbid={3}, cbid={1}, datas={2}!\n", chargeID, cbid, datas, dbid)); Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(InterfacesInterface::charge); (*pBundle) << pChannel->componentID(); (*pBundle) << chargeID; (*pBundle) << dbid; (*pBundle).appendBlob(datas); (*pBundle) << cbid; pInterfacesChannel->send(pBundle); }
void EntityApp<E>::onExecScriptCommand(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string cmd; s.readBlob(cmd); PyObject* pycmd = PyUnicode_DecodeUTF8(cmd.data(), cmd.size(), NULL); if(pycmd == NULL) { SCRIPT_ERROR_CHECK(); return; } DEBUG_MSG(boost::format("EntityApp::onExecScriptCommand: size(%1%), command=%2%.\n") % cmd.size() % cmd); std::string retbuf = ""; PyObject* pycmd1 = PyUnicode_AsEncodedString(pycmd, "utf-8", NULL); if(script_.run_simpleString(PyBytes_AsString(pycmd1), &retbuf) == 0) { // 将结果返回给客户端 Mercury::Bundle bundle; ConsoleInterface::ConsoleExecCommandCBMessageHandler msgHandler; bundle.newMessage(msgHandler); ConsoleInterface::ConsoleExecCommandCBMessageHandlerArgs1::staticAddToBundle(bundle, retbuf); bundle.send(this->getNetworkInterface(), pChannel); } Py_DECREF(pycmd); Py_DECREF(pycmd1); }
//------------------------------------------------------------------------------------- void BillingSystem::onAccountLogin(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string loginName, accountName, password, datas; COMPONENT_ID cid; s >> cid >> loginName >> password; s.readBlob(datas); lockthread(); REQLOGIN_MAP::iterator iter = reqAccountLogin_requests_.find(loginName); if(iter != reqAccountLogin_requests_.end()) { unlockthread(); return; } LoginAccountTask* pinfo = new LoginAccountTask(); pinfo->commitName = loginName; pinfo->accountName = loginName; pinfo->getDatas = ""; pinfo->password = password; pinfo->postDatas = datas; pinfo->success = false; pinfo->baseappID = cid; pinfo->dbmgrID = pChannel->componentID(); pinfo->address = pChannel->addr(); reqAccountLogin_requests_[pinfo->commitName] = pinfo; unlockthread(); this->threadPool().addTask(pinfo); }
//------------------------------------------------------------------------------------- void BillingSystem::charge(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { OrdersCharge* pOrdersCharge = new OrdersCharge(); pOrdersCharge->dbmgrID = pChannel->componentID(); pOrdersCharge->address = pChannel->addr(); s >> pOrdersCharge->baseappID; s >> pOrdersCharge->ordersID; s >> pOrdersCharge->dbid; s.readBlob(pOrdersCharge->postDatas); s >> pOrdersCharge->cbid; INFO_MSG(boost::format("BillingSystem::charge: componentID=%5%, chargeID=%1%, dbid=%2%, cbid=%3%, datas=%4%!\n") % pOrdersCharge->ordersID % pOrdersCharge->dbid % pOrdersCharge->cbid % pOrdersCharge->postDatas % pOrdersCharge->baseappID); ORDERS::iterator iter = orders_.find(pOrdersCharge->ordersID); if(iter != orders_.end()) { ERROR_MSG(boost::format("BillingSystem::charge: chargeID=%1% is exist!\n") % pOrdersCharge->ordersID); delete pOrdersCharge; return; } ChargeTask* pinfo = new ChargeTask(); pinfo->pOrders = pOrdersCharge; orders_[pOrdersCharge->ordersID].reset(pOrdersCharge); this->threadPool().addTask(pinfo); }
//------------------------------------------------------------------------------------- void PythonApp::onExecScriptCommand(Network::Channel* pChannel, KBEngine::MemoryStream& s) { std::string cmd; s.readBlob(cmd); PyObject* pycmd = PyUnicode_DecodeUTF8(cmd.data(), cmd.size(), NULL); if(pycmd == NULL) { SCRIPT_ERROR_CHECK(); return; } DEBUG_MSG(fmt::format("PythonApp::onExecScriptCommand: size({}), command={}.\n", cmd.size(), cmd)); std::string retbuf = ""; PyObject* pycmd1 = PyUnicode_AsEncodedString(pycmd, "utf-8", NULL); script_.run_simpleString(PyBytes_AsString(pycmd1), &retbuf); if(retbuf.size() == 0) { retbuf = "\r\n"; } // 将结果返回给客户端 Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); ConsoleInterface::ConsoleExecCommandCBMessageHandler msgHandler; (*pBundle).newMessage(msgHandler); ConsoleInterface::ConsoleExecCommandCBMessageHandlerArgs1::staticAddToBundle((*pBundle), retbuf); pChannel->send(pBundle); Py_DECREF(pycmd); Py_DECREF(pycmd1); }
//------------------------------------------------------------------------------------- void BillingHandler_ThirdParty::charge(Network::Channel* pChannel, KBEngine::MemoryStream& s) { std::string chargeID; std::string datas; CALLBACK_ID cbid; DBID dbid; s >> chargeID; s >> dbid; s.readBlob(datas); s >> cbid; INFO_MSG(fmt::format("BillingHandler_ThirdParty::charge: chargeID={0}, dbid={3}, cbid={1}, datas={2}!\n", chargeID, cbid, datas, dbid)); KBE_ASSERT(pBillingChannel_); Network::Bundle::SmartPoolObjectPtr bundle = Network::Bundle::createSmartPoolObj(); (*(*bundle)).newMessage(BillingSystemInterface::charge); (*(*bundle)) << pChannel->componentID(); (*(*bundle)) << chargeID; (*(*bundle)) << dbid; (*(*bundle)).appendBlob(datas); (*(*bundle)) << cbid; if(pBillingChannel_->isDestroyed()) { if(!this->reconnect()) return; } (*(*bundle)).send(Dbmgr::getSingleton().networkInterface(), pBillingChannel_); }
//------------------------------------------------------------------------------------- void InterfacesHandler_Interfaces::onChargeCB(KBEngine::MemoryStream& s) { std::string chargeID; std::string datas; CALLBACK_ID cbid; COMPONENT_ID cid; DBID dbid; SERVER_ERROR_CODE retcode; s >> cid; s >> chargeID; s >> dbid; s.readBlob(datas); s >> cbid; s >> retcode; INFO_MSG(fmt::format("InterfacesHandler_Interfaces::onChargeCB: chargeID={0}, dbid={3}, cbid={1}, cid={4}, datas={2}!\n", chargeID, cbid, datas, dbid, cid)); Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(BASEAPP_TYPE, cid); if (cid == 0 || cinfos == NULL || cinfos->pChannel == NULL || cinfos->pChannel->isDestroyed()) { ERROR_MSG(fmt::format("InterfacesHandler_Interfaces::onChargeCB: baseapp not found!, chargeID={}, cid={}.\n", chargeID, cid)); // 此时应该随机找一个baseapp调用onLoseChargeCB bool found = false; Components::COMPONENTS& components = Components::getSingleton().getComponents(BASEAPP_TYPE); for (Components::COMPONENTS::iterator iter = components.begin(); iter != components.end(); ++iter) { cinfos = &(*iter); if (cinfos == NULL || cinfos->pChannel == NULL || cinfos->pChannel->isDestroyed()) { continue; } WARNING_MSG(fmt::format("InterfacesHandler_Interfaces::onChargeCB: , chargeID={}, not found cid={}, forward to component({}) processing!\n", chargeID, cid, cinfos->cid)); found = true; break; } if (!found) return; } Network::Bundle* pBundle = Network::Bundle::createPoolObject(); (*pBundle).newMessage(BaseappInterface::onChargeCB); (*pBundle) << chargeID; (*pBundle) << dbid; (*pBundle).appendBlob(datas); (*pBundle) << cbid; (*pBundle) << retcode; cinfos->pChannel->send(pBundle); }
//------------------------------------------------------------------------------------- void Dbmgr::onBroadcastGlobalDataChanged(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { uint8 dataType; std::string key, value; bool isDelete; COMPONENT_TYPE componentType; s >> dataType; s >> isDelete; s.readBlob(key); if(!isDelete) { s.readBlob(value); } s >> componentType; switch(dataType) { case GlobalDataServer::GLOBAL_DATA: if(isDelete) pGlobalData_->del(pChannel, componentType, key); else pGlobalData_->write(pChannel, componentType, key, value); break; case GlobalDataServer::BASEAPP_DATA: if(isDelete) pBaseAppData_->del(pChannel, componentType, key); else pBaseAppData_->write(pChannel, componentType, key, value); break; case GlobalDataServer::CELLAPP_DATA: if(isDelete) pCellAppData_->del(pChannel, componentType, key); else pCellAppData_->write(pChannel, componentType, key, value); break; default: KBE_ASSERT(false && "dataType is error!\n"); break; }; }
//------------------------------------------------------------------------------------- void Cellapp::onExecuteRawDatabaseCommandCB(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string err; CALLBACK_ID callbackID = 0; uint32 nrows = 0; uint32 nfields = 0; uint64 affectedRows = 0; PyObject* pResultSet = NULL; PyObject* pAffectedRows = NULL; PyObject* pErrorMsg = NULL; s >> callbackID; s >> err; if(err.size() <= 0) { s >> nfields; pErrorMsg = Py_None; Py_INCREF(pErrorMsg); if(nfields > 0) { pAffectedRows = Py_None; Py_INCREF(pAffectedRows); s >> nrows; pResultSet = PyList_New(nrows); for (uint32 i = 0; i < nrows; ++i) { PyObject* pRow = PyList_New(nfields); for(uint32 j = 0; j < nfields; ++j) { std::string cell; s.readBlob(cell); PyObject* pCell = NULL; if(cell == "NULL") { Py_INCREF(Py_None); pCell = Py_None; } else { pCell = PyBytes_FromStringAndSize(cell.data(), cell.length()); } PyList_SET_ITEM(pRow, j, pCell); } PyList_SET_ITEM(pResultSet, i, pRow); } }
//------------------------------------------------------------------------------------- void InterfacesHandler_Interfaces::onLoginAccountCB(KBEngine::MemoryStream& s) { std::string loginName, accountName, password, postdatas, getdatas; COMPONENT_ID cid; SERVER_ERROR_CODE success = SERVER_ERR_OP_FAILED; s >> cid >> loginName >> accountName >> password >> success; s.readBlob(postdatas); s.readBlob(getdatas); bool needCheckPassword = (success == SERVER_ERR_LOCAL_PROCESSING); if (success != SERVER_SUCCESS && success != SERVER_ERR_LOCAL_PROCESSING) accountName = ""; else success = SERVER_SUCCESS; Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(LOGINAPP_TYPE, cid); if(cinfos == NULL || cinfos->pChannel == NULL) { ERROR_MSG("InterfacesHandler_Interfaces::onLoginAccountCB: loginapp not found!\n"); return; } std::string dbInterfaceName = Dbmgr::getSingleton().selectAccountDBInterfaceName(accountName); thread::ThreadPool* pThreadPool = DBUtil::pThreadPool(dbInterfaceName); if (!pThreadPool) { ERROR_MSG(fmt::format("InterfacesHandler_Interfaces::onLoginAccountCB: not found dbInterface({})!\n", dbInterfaceName)); return; } pThreadPool->addTask(new DBTaskAccountLogin(cinfos->pChannel->addr(), loginName, accountName, password, success, postdatas, getdatas, needCheckPassword)); }
//------------------------------------------------------------------------------------- void Dbmgr::onAccountLogin(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string loginName, password, datas; s >> loginName >> password; s.readBlob(datas); if(loginName.size() == 0) { ERROR_MSG("Dbmgr::onAccountLogin: loginName is empty.\n"); return; } pBillingAccountHandler_->loginAccount(pChannel, loginName, password, datas); }
//------------------------------------------------------------------------------------- void InterfacesHandler_ThirdParty::onCreateAccountCB(KBEngine::MemoryStream& s) { std::string registerName, accountName, password, postdatas, getdatas; COMPONENT_ID cid; SERVER_ERROR_CODE success = SERVER_ERR_OP_FAILED; s >> cid >> registerName >> accountName >> password >> success; s.readBlob(postdatas); s.readBlob(getdatas); if(success != SERVER_SUCCESS) { accountName = ""; } Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(LOGINAPP_TYPE, cid); if(cinfos == NULL || cinfos->pChannel == NULL) { ERROR_MSG("InterfacesHandler_ThirdParty::onCreateAccountCB: loginapp not found!\n"); return; } std::string dbInterfaceName = Dbmgr::getSingleton().selectAccountDBInterfaceName(accountName); thread::ThreadPool* pThreadPool = DBUtil::pThreadPool(dbInterfaceName); if (!pThreadPool) { ERROR_MSG(fmt::format("InterfacesHandler_ThirdParty::onCreateAccountCB: not found dbInterface({})!\n", dbInterfaceName)); return; } pThreadPool->addTask(new DBTaskCreateAccount(cinfos->pChannel->addr(), registerName, accountName, password, postdatas, getdatas)); }
//------------------------------------------------------------------------------------- void Dbmgr::reqCreateAccount(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string registerName, password, datas; s >> registerName >> password; s.readBlob(datas); if(registerName.size() == 0) { ERROR_MSG("Dbmgr::reqCreateAccount: registerName is empty.\n"); return; } pBillingHandler_->createAccount(pChannel, registerName, password, datas); numCreatedAccount_++; }
//------------------------------------------------------------------------------------- void Interfaces::reqCreateAccount(Network::Channel* pChannel, KBEngine::MemoryStream& s) { std::string registerName, accountName, password, datas; COMPONENT_ID cid; uint8 accountType = 0; s >> cid >> registerName >> password >> accountType; s.readBlob(datas); if(accountType == (uint8)ACCOUNT_TYPE_MAIL) { } REQCREATE_MAP::iterator iter = reqCreateAccount_requests_.find(registerName); if(iter != reqCreateAccount_requests_.end()) { return; } CreateAccountTask* pinfo = new CreateAccountTask(); pinfo->commitName = registerName; pinfo->accountName = registerName; pinfo->getDatas = ""; pinfo->password = password; pinfo->postDatas = datas; pinfo->retcode = SERVER_ERR_OP_FAILED; pinfo->baseappID = cid; pinfo->dbmgrID = pChannel->componentID(); pinfo->address = pChannel->addr(); pinfo->enable = true; reqCreateAccount_requests_[pinfo->commitName] = pinfo; // 把请求交由脚本处理 SCOPED_PROFILE(SCRIPTCALL_PROFILE); PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), const_cast<char*>("onRequestCreateAccount"), const_cast<char*>("ssy#"), registerName.c_str(), password.c_str(), datas.c_str(), datas.length()); if(pyResult != NULL) Py_DECREF(pyResult); else SCRIPT_ERROR_CHECK(); }
//------------------------------------------------------------------------------------- void Dbmgr::reqCreateAccount(Network::Channel* pChannel, KBEngine::MemoryStream& s) { std::string registerName, password, datas; uint8 uatype = 0; s >> registerName >> password >> uatype; s.readBlob(datas); if(registerName.size() == 0) { ERROR_MSG("Dbmgr::reqCreateAccount: registerName is empty.\n"); return; } pInterfacesAccountHandler_->createAccount(pChannel, registerName, password, datas, ACCOUNT_TYPE(uatype)); numCreatedAccount_++; }
//------------------------------------------------------------------------------------- void Interfaces::charge(Network::Channel* pChannel, KBEngine::MemoryStream& s) { OrdersCharge* pOrdersCharge = new OrdersCharge(); pOrdersCharge->timeout = timestamp() + uint64(g_kbeSrvConfig.interfaces_orders_timeout_ * stampsPerSecond()); pOrdersCharge->dbmgrID = pChannel->componentID(); pOrdersCharge->address = pChannel->addr(); s >> pOrdersCharge->baseappID; s >> pOrdersCharge->ordersID; s >> pOrdersCharge->dbid; s.readBlob(pOrdersCharge->postDatas); s >> pOrdersCharge->cbid; INFO_MSG(fmt::format("Interfaces::charge: componentID={4}, chargeID={0}, dbid={1}, cbid={2}, datas={3}!\n", pOrdersCharge->ordersID, pOrdersCharge->dbid, pOrdersCharge->cbid, pOrdersCharge->postDatas, pOrdersCharge->baseappID)); ORDERS::iterator iter = orders_.find(pOrdersCharge->ordersID); if(iter != orders_.end()) { ERROR_MSG(fmt::format("Interfaces::charge: chargeID={} is exist!\n", pOrdersCharge->ordersID)); delete pOrdersCharge; return; } ChargeTask* pinfo = new ChargeTask(); pinfo->orders = *pOrdersCharge; pinfo->pOrders = pOrdersCharge; orders_[pOrdersCharge->ordersID].reset(pOrdersCharge); // 把请求交由脚本处理 SCOPED_PROFILE(SCRIPTCALL_PROFILE); PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), const_cast<char*>("onRequestCharge"), const_cast<char*>("sKy#"), pOrdersCharge->ordersID.c_str(), pOrdersCharge->dbid, pOrdersCharge->postDatas.c_str(), pOrdersCharge->postDatas.length()); if(pyResult != NULL) Py_DECREF(pyResult); else SCRIPT_ERROR_CHECK(); }
//------------------------------------------------------------------------------------- void Interfaces::onAccountLogin(Network::Channel* pChannel, KBEngine::MemoryStream& s) { std::string loginName, accountName, password, datas; COMPONENT_ID cid; s >> cid >> loginName >> password; s.readBlob(datas); REQLOGIN_MAP::iterator iter = reqAccountLogin_requests_.find(loginName); if(iter != reqAccountLogin_requests_.end()) { return; } LoginAccountTask* pinfo = new LoginAccountTask(); pinfo->commitName = loginName; pinfo->accountName = loginName; pinfo->getDatas = ""; pinfo->password = password; pinfo->postDatas = datas; pinfo->retcode = SERVER_ERR_OP_FAILED; pinfo->baseappID = cid; pinfo->dbmgrID = pChannel->componentID(); pinfo->address = pChannel->addr(); pinfo->enable = true; reqAccountLogin_requests_[pinfo->commitName] = pinfo; // 把请求交由脚本处理 SCOPED_PROFILE(SCRIPTCALL_PROFILE); PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), const_cast<char*>("onRequestAccountLogin"), const_cast<char*>("ssy#"), loginName.c_str(), password.c_str(), datas.c_str(), datas.length()); if(pyResult != NULL) Py_DECREF(pyResult); else SCRIPT_ERROR_CHECK(); }
//------------------------------------------------------------------------------------- void BillingSystem::onAccountLogin(Mercury::Channel* pChannel, KBEngine::MemoryStream& s) { std::string loginName, accountName, password, datas; COMPONENT_ID cid; s >> cid >> loginName >> password; s.readBlob(datas); LoginAccountTask* pinfo = new LoginAccountTask(); pinfo->commitName = loginName; pinfo->accountName = loginName; pinfo->getDatas = ""; pinfo->password = password; pinfo->postDatas = datas; pinfo->success = false; pinfo->baseappID = cid; pinfo->dbmgrID = pChannel->componentID(); pinfo->address = pChannel->addr(); this->threadPool().addTask(pinfo); }
//------------------------------------------------------------------------------------- void InterfacesHandler_ThirdParty::onChargeCB(KBEngine::MemoryStream& s) { std::string chargeID; std::string datas; CALLBACK_ID cbid; COMPONENT_ID cid; DBID dbid; SERVER_ERROR_CODE retcode; s >> cid; s >> chargeID; s >> dbid; s.readBlob(datas); s >> cbid; s >> retcode; INFO_MSG(fmt::format("InterfacesHandler_ThirdParty::onChargeCB: chargeID={0}, dbid={3}, cbid={1}, cid={4}, datas={2}!\n", chargeID, cbid, datas, dbid, cid)); Components::ComponentInfos* cinfos = Components::getSingleton().findComponent(BASEAPP_TYPE, cid); if(cinfos == NULL || cinfos->pChannel == NULL || cinfos->pChannel->isDestroyed()) { ERROR_MSG(fmt::format("InterfacesHandler_ThirdParty::onChargeCB: baseapp not found!, chargeID={}, cid={}.\n", chargeID, cid)); return; } Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject(); (*pBundle).newMessage(BaseappInterface::onChargeCB); (*pBundle) << chargeID; (*pBundle) << dbid; (*pBundle).appendBlob(datas); (*pBundle) << cbid; (*pBundle) << retcode; cinfos->pChannel->send(pBundle); }
inline void CallbackMgr<PyObjectPtr>::createFromStream(KBEngine::MemoryStream& s) { CALLBACK_ID v; s >> v; idAlloc_.lastID(v); uint32 size; s >> size; for(uint32 i=0; i<size; i++) { CALLBACK_ID cbID; s >> cbID; std::string data; s.readBlob(data); PyObject* pyCallback = NULL; if(data.size() > 0) pyCallback = script::Pickler::unpickle(data); uint64 timeout; s >> timeout; if(pyCallback == NULL || cbID == 0) { ERROR_MSG(fmt::format("CallbackMgr::createFromStream: pyCallback({}) is error!\n", cbID)); continue; } cbMap_.insert(CallbackMgr<PyObjectPtr>::CALLBACKS::value_type(cbID, std::pair< PyObjectPtr, uint64 >(pyCallback, timeout))); Py_DECREF(pyCallback); } }
//------------------------------------------------------------------------------------- void Logger::writeLog(Network::Channel* pChannel, KBEngine::MemoryStream& s) { ++g_secsNumlogs; ++g_totalNumlogs; LOG_ITEM* pLogItem = new LOG_ITEM(); std::string str; s >> pLogItem->uid; s >> pLogItem->logtype; s >> pLogItem->componentType; s >> pLogItem->componentID; s >> pLogItem->componentGlobalOrder; s >> pLogItem->componentGroupOrder; s >> pLogItem->t; s >> pLogItem->kbetime; s.readBlob(str); time_t tt = static_cast<time_t>(pLogItem->t); tm* aTm = localtime(&tt); // YYYY year // MM month (2 digits 01-12) // DD day (2 digits 01-31) // HH hour (2 digits 00-23) // MM minutes (2 digits 00-59) // SS seconds (2 digits 00-59) if(aTm == NULL) { ERROR_MSG("Logger::writeLog: log is error!\n"); delete pLogItem; return; } char timebuf[MAX_BUF]; pLogItem->logstream << KBELOG_TYPE_NAME_EX(pLogItem->logtype); pLogItem->logstream << " "; pLogItem->logstream << COMPONENT_NAME_EX_2(pLogItem->componentType); kbe_snprintf(timebuf, MAX_BUF, "%02d", (int)pLogItem->componentGroupOrder); pLogItem->logstream << timebuf; pLogItem->logstream << " "; pLogItem->logstream << pLogItem->uid; pLogItem->logstream << " "; pLogItem->logstream << pLogItem->componentID; pLogItem->logstream << " "; kbe_snprintf(timebuf, MAX_BUF, " [%-4d-%02d-%02d %02d:%02d:%02d %03d] ", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec, pLogItem->kbetime); pLogItem->logstream << timebuf; pLogItem->logstream << "- "; pLogItem->logstream << str; DebugHelper::getSingleton().changeLogger(COMPONENT_NAME_EX(pLogItem->componentType)); PRINT_MSG(pLogItem->logstream.str()); DebugHelper::getSingleton().changeLogger("default"); LOG_WATCHERS::iterator iter = logWatchers_.begin(); for(; iter != logWatchers_.end(); ++iter) { iter->second.onMessage(pLogItem); } // 缓存一部分log,提供工具查看log时能快速获取初始上下文 buffered_logs_.push_back(pLogItem); if(buffered_logs_.size() > 64) { pLogItem = buffered_logs_.front(); buffered_logs_.pop_front(); delete pLogItem; } }