void CCommandPra::CmdAppKill(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { if (a_clsRecvP.IsFlagNotify() == false) { g_pclsLogPra->WARNING("CMD 'APP_KILL', not set notify flag"); } CCmdBase clsBase; if (clsBase.NotifyParse(a_clsRecvP.GetPayload().c_str()) == false) { g_pclsLogPra->ERROR("CMD 'APP_KILL', invalied body format"); return; } if (clsBase.m_bIsAll) { // 전체 프로세스 강제 종료 a_clsPM.StopForceibly(); } else { // 지정 프로세스의 강제 종료 auto iter = clsBase.m_lstTarget.begin(); for (; iter != clsBase.m_lstTarget.end(); ++iter) { a_clsPM.StopForceibly(iter->first); } } return; }
int CEmsInfo::ReceiveStaRequestProcess(CProtocol &cProto) { std::vector<char> vecPayload; CSessionInfo *cSessionInfo = NULL; CStmReqApi cDecApi; char *szPayload = NULL; char chFlag = 0; time_t tm = 0; tm = time(NULL); chFlag = cProto.GetFlag(); if(chFlag != CProtocol::FLAG_REQUEST){ STA_LOG(STA_ERR,"Invalid Flag(flag=%d)\n",chFlag); return STA_NOK; } cProto.GetPayload(vecPayload); cSessionInfo = new CSessionInfo(); cSessionInfo->SetReceiveTime(tm); szPayload = new char[vecPayload.size() + 1]; strncpy(szPayload, &vecPayload[0], vecPayload.size()); szPayload[vecPayload.size()] = '\0'; cSessionInfo->SetReceiveData(szPayload, vecPayload.size()); DEBUG_LOG("RECEIVE DATA (Wait 3 time)\n"); m_lstPendingQueue.push_back(cSessionInfo); return STA_OK; }
bool CCommandPra::ProcMesgModule(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CConfigPra& clsCfg = CConfigPra::Instance(); #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Recvive message form Module"); a_clsRecvP.Print(g_pclsLogPra, LV_DEBUG, true); #endif int nDstNode = 0; int nDstProc = 0; a_clsRecvP.GetDestination(nDstNode, nDstProc); // PRA가 처리해 할 명령인가? if (nDstProc == clsCfg.m_nProcNo) { return Command(a_clsRecvP, a_clsPM); } // 메세지를 전송할 APP를 찾는다. string strProcName; if (a_clsPM.GetProcName(nDstProc, &strProcName) != NULL) { CAppQueue& clsQ = CAppQueue::Instance(); if (clsQ.SendCmd(a_clsRecvP, strProcName.c_str()) == false) { g_pclsLogPra->ERROR("message send faile, to app"); a_clsRecvP.Print(g_pclsLogPra, LV_INFO); return false; } } else { g_pclsLogPra->ERROR("not found target app process"); a_clsRecvP.Print(g_pclsLogPra, LV_INFO); } return true; }
int CAppQueue::RecvCmd(CProtocol& a_clsProto) { if (m_pclsQ == NULL) { g_pclsLogPra->ERROR("CMQ, command queue not opend"); return false; } char* szRecvBuf = NULL; int nRead = m_pclsQ->ReceiveCommand(&szRecvBuf); if (nRead < 0) { if (nRead == -E_Q_NOENT) { return 0; } g_pclsLogPra->ERROR("CMQ, receive command failed, ret: %d\n", nRead); return -1; } if (a_clsProto.SetAll(szRecvBuf, nRead) == false) { g_pclsLogPra->ERROR("CMQ, invalied receive message"); a_clsProto.Print(g_pclsLogPra, LV_INFO, true); m_pclsQ->FreeReadData(); return -1; } m_pclsQ->FreeReadData(); return 1; }
void CCommandPra::CmdAppStart(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { if (a_clsRecvP.IsFlagNotify() == false) { g_pclsLogPra->WARNING("CMD 'APP_START', not set notify flag"); } CCmdBase clsBase; if (clsBase.NotifyParse(a_clsRecvP.GetPayload().c_str()) == false) { g_pclsLogPra->ERROR("CMD 'APP_START', invalied body format"); return; } if (clsBase.m_bIsAll) { // 전체 프로세스 실행 요청 a_clsPM.Run(-1); } else { // 지정 프로세스의 실행 요청 list<pair<int, string> >::iterator iter = clsBase.m_lstTarget.begin(); for (; iter != clsBase.m_lstTarget.end(); ++iter) { a_clsPM.Run(iter->first); } } return; }
void CCommandPra::CmdAppLogLevel(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CConfigPra& clsCfg = CConfigPra::Instance(); CAppQueue& clsQ = CAppQueue::Instance(); CCmdAppLogLevel clsLog; // Notify parsing string strBody; CCmdAppCtl clsCtl; // APP에 보낼 body 메세지 CProtocol clsSendP; // APP에 보낼 message if (a_clsRecvP.IsFlagNotify() == false) { g_pclsLogPra->WARNING("CMD, 'LOG_LEVEL' not set notify flag"); } if (clsLog.NotifyParse(a_clsRecvP.GetPayload().c_str()) == false) { g_pclsLogPra->ERROR("CMD, 'LOG_LEVEL' invalied body format"); return; } // 프로세스 보낼 메세지 구성 clsCtl.m_strAction = "LOG_LEVEL"; clsCtl.m_nOption = clsLog.m_nLogLevel; clsSendP.SetCommand(CMD_APP_CTL); clsSendP.SetFlagRequest(); clsSendP.SetSource(clsCfg.m_nNodeNo, clsCfg.m_nProcNo); clsSendP.SetSequence(); clsSendP.SetPayload(clsCtl.RequestGen()); if (clsLog.m_bIsAll) { // 전체 프로세스 loglevel 변경 요청 vector<CProcessManager::ST_APPINFO> vecInfo; a_clsPM.GetAppInfo(vecInfo, CProcStatus::RUNNING); for (size_t i=0; i < vecInfo.size(); ++i) { clsSendP.SetDestination(clsCfg.m_nNodeNo, vecInfo[i].m_nProcNo); if (clsQ.SendCmd(clsSendP, vecInfo[i].m_strProcName.c_str()) == false) { g_pclsLogPra->ERROR("APP loglevel send failed"); } } } else { // 지정 프로세스의 loglevel 변경 요청 list<pair<int, string> >::iterator iter = clsLog.m_lstTarget.begin(); for (; iter != clsLog.m_lstTarget.end(); ++iter) { clsSendP.SetDestination(clsCfg.m_nNodeNo, iter->first); if (clsQ.SendCmd(clsSendP, iter->second.c_str()) == false) { g_pclsLogPra->ERROR("APP loglevel send failed"); } } } return; }
bool CCommandPra::Command(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { int nCmd = atoi(a_clsRecvP.GetCommand().c_str()); switch (nCmd) { case CMD_PING : CmdPing(a_clsRecvP); break; case CMD_PRA_RECONFIG : CmdAppReconfig(a_clsRecvP, a_clsPM); break; case CMD_APP_STATUS : CmdAppStatus(a_clsRecvP, a_clsPM); break; case CMD_APP_START : CmdAppStart(a_clsRecvP, a_clsPM); break; case CMD_APP_STOP : CmdAppStop(a_clsRecvP, a_clsPM); break; case CMD_APP_KILL : CmdAppKill(a_clsRecvP, a_clsPM); break; case CMD_APP_INIT : CmdAppInit(a_clsRecvP, a_clsPM); break; case CMD_APP_SUSPEND : CmdAppSuspend(a_clsRecvP, a_clsPM); break; case CMD_APP_RESUME : CmdAppResume(a_clsRecvP, a_clsPM); break; case CMD_APP_LOGLEVEL : CmdAppLogLevel(a_clsRecvP, a_clsPM); break; case CMD_STS_APP : CmdStaticApp(a_clsRecvP, a_clsPM); break; case CMD_BATCH_START : CmdBatchStart(a_clsRecvP, a_clsPM); break; case CMD_CLI_COMMAND : CmdCli(a_clsRecvP, a_clsPM); break; default : g_pclsLogPra->ERROR("CMD, not support command"); a_clsRecvP.Print(g_pclsLogPra, LV_INFO, true); return false; } return true; }
bool CModuleIPC::SendMesg(CProtocol& a_cMesg) { int nDstNodeNo = -1; int nDstProcNo = -1; a_cMesg.GetDestination(nDstNodeNo, nDstProcNo); int nToProcNo = -1; if (m_clsRoute.Lookup(nDstNodeNo, nDstProcNo, nToProcNo) == false) { m_strErrorMsg = "not found routing table"; return false; } modipc_t::iterator iter = m_mapIPC.find(nToProcNo); if (iter == m_mapIPC.end()) { m_strErrorMsg = "not found procno"; return false; } pthread_mutex_lock(&iter->second.m_tMutex); iter->second.m_deqMsg.push_back(a_cMesg); pthread_cond_signal(&iter->second.m_tCond); pthread_mutex_unlock(&iter->second.m_tMutex); return true; }
void CCommandPra::CmdAppReconfig(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CProtocol clsResp; CCmdBase clsBase; if (a_clsRecvP.IsFlagNotify() == false) { g_pclsLogPra->WARNING("CMD, 'PRA_RECONFIG', check notify flag"); return; } CConfigPra& clsCfg = CConfigPra::Instance(); CMesgRoute& clsRoute = CMesgRoute::Instance(); CAddress& clsAddr = CAddress::Instance(); list<CProcessManager::ST_APPINFO> lstProcess; clsCfg.LoadProcess(lstProcess); // 현재 프로세스의 비활성화 flag 설정 a_clsPM.Disable(); for (auto iter = lstProcess.begin(); iter != lstProcess.end(); ++iter) { a_clsPM.Add(*iter); clsAddr.AddApp(iter->m_strPkgName.c_str(), iter->m_strNodeType.c_str(), iter->m_strProcName.c_str(), iter->m_nProcNo); clsRoute.AddRoute(iter->m_nProcNo, clsCfg.m_nProcNo); } clsRoute.PrintTable(g_pclsLogPra, LV_INFO); return; }
void CCommandPra::CmdCli(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CCliReq clsCliReq; string strBody = a_clsRecvP.GetPayload(); if (clsCliReq.DecodeMessage(strBody) != CCliApi::RESULT_OK) { g_pclsLogPra->ERROR("CMD 'CLI' invalied body message"); return; } string strCliCmd = clsCliReq.GetCmdName(); if (strCliCmd.compare("DISP-PRC") == 0) { return CmdCli_DispProc(a_clsRecvP, clsCliReq, a_clsPM); } else if (strCliCmd.compare("INIT-PRC") == 0) { return CmdCli_InitProc(a_clsRecvP, clsCliReq, a_clsPM); } else if (strCliCmd.compare("START-PRC") == 0) { return CmdCli_StartProc(a_clsRecvP, clsCliReq, a_clsPM); } else if (strCliCmd.compare("STOP-PRC") == 0) { return CmdCli_StopProc(a_clsRecvP, clsCliReq, a_clsPM); } else { g_pclsLogPra->WARNING("CMD 'CLI', not support command"); return; } return; }
void CCommandPra::CmdPing(CProtocol& a_clsRecvP) { CProtocol clsResp; clsResp.SetResponse(a_clsRecvP); CCmdBase clsBase; string strBody; if (a_clsRecvP.IsFlagRequest()) { strBody = clsBase.ErrorGen(0, "ok i am alive"); } else { strBody = clsBase.ErrorGen(0, "not set requst flag"); clsResp.SetFlagError(); g_pclsLogPra->ERROR("MSGP, ping, not set request flag"); } clsResp.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsResp) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsResp.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsResp.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
int CClaInterface::RegReqFunc(CProtocol &cProto) { CCliRegReqApi cReqApi; string strPayload; /* send reg message */ cReqApi.Init(m_strUserId); cReqApi.EncodeMessage(strPayload); cProto.SetCommand("0000080002"); cProto.SetFlagRequest(); cProto.SetSource(0, 0); cProto.SetDestination(0, 0); cProto.SetPayload(strPayload); return RESULT_OK; }
bool CAppQueue::SendCmd(CProtocol& a_clsProto, const char* a_szTarget) { if (m_pclsQ == NULL) { g_pclsLogPra->ERROR("CMQ, command queue not opend"); return false; } vector<char> vecMesg; a_clsProto.GenStream(vecMesg); int nRet = m_pclsQ->SendCommand((char*)a_szTarget, 0, &vecMesg[0], vecMesg.size()); if (nRet != 0) { g_pclsLogPra->ERROR("CMQ, command send failed, to: %s, ret: %d", a_szTarget, nRet); a_clsProto.Print(g_pclsLogPra, LV_INFO, true); return false; } return true; }
void CCommandPra::CmdStaticApp(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { if (a_clsRecvP.IsFlagBroadcast() == false) { g_pclsLogPra->WARNING("statics not set broadcast"); } vector<CProcessManager::ST_APPINFO> vecInfo; a_clsPM.GetAppInfo(vecInfo, CProcStatus::RUNNING); CConfigPra& clsCfg = CConfigPra::Instance(); CAppQueue& clsQ = CAppQueue::Instance(); for (size_t i=0; i < vecInfo.size(); i++) { a_clsRecvP.SetDestination(clsCfg.m_nNodeNo, vecInfo[i].m_nProcNo); if (clsQ.SendCmd(a_clsRecvP, vecInfo[i].m_strProcName.c_str()) == false) { g_pclsLogPra->ERROR("statics send failed, pname: %s", vecInfo[i].m_strProcName.c_str()); } } return; }
void CProcessManager::CheckAlive(void) { CConfigPra& clsCfg = CConfigPra::Instance(); CAppQueue& clsQ = CAppQueue::Instance(); // Alive check를 위한 Ping 메세지 생성 CProtocol clsProto; clsProto.SetCommand(CMD_PING); clsProto.SetFlagRequest(); clsProto.SetSource(clsCfg.m_nNodeNo, clsCfg.m_nProcNo); clsProto.SetPayload(NULL, 0); time_t curtime = time(NULL); auto iter = m_mapProcess.begin(); for (; iter != m_mapProcess.end(); iter++) { if (iter->second.m_pclsApp->GetStatus() != CProcStatus::RUNNING) { continue; } // Alive 체크 // 조건1) 마지막 alive 시간 + hangup 시간 이내 인가? // 조건2) alive 체크 주기 인가? if (curtime <= (iter->second.m_nAliveTime + m_nHangupTime)) { if (curtime >= (iter->second.m_nAliveTime + m_nAlivePeriod)) { clsProto.SetDestination(clsCfg.m_nNodeNo, iter->first); clsProto.SetSequence(); auto miter = m_mapProcess.find(iter->first); if (miter == m_mapProcess.end()) { continue; } if (clsQ.SendCmd(clsProto, miter->second.m_stAppInfo.m_strProcName.c_str()) == false) { g_pclsLogPra->ERROR("PM, CMD 'PING' send failed"); continue; } } continue; } // HANGUP 처리 g_pclsLogPra->CRITICAL("PM, process hangup, pno: %d, pname: %s", iter->first, iter->second.m_stAppInfo.m_strProcName.c_str()); iter->second.m_pclsApp->SetStatus(CProcStatus::HANGUP); iter->second.m_pclsApp->SendSignal(SIGSEGV); } return; }
int CEmsInfo::SendHeartBeatRsp() { bool blnRet = true; int nNodeNo = 0; int nProcNo = 0; CGlobal *cGlob = NULL; CModuleIPC *cIpc = NULL; CProtocol cProto; DEBUG_LOG("SEND HEARTBEAT RESPONSE PROCESS\n"); cGlob = CGlobal::GetInstance(); nNodeNo = cGlob->GetLocalNodeNo(); nProcNo = cGlob->GetLocalProcNo(); cProto.SetSource(nNodeNo, nProcNo); cProto.SetDestination(m_nAtomNodeNo, m_nStmNo); /* flag setting */ cProto.SetFlagResponse(); /* PKG CLASS ACTION * 000 003 XXXX */ cProto.SetCommand("0000030008"); cIpc = cGlob->GetModuleIPC(); blnRet = cIpc->SendMesg(cProto); if(blnRet != true){ STA_LOG(STA_ERR,"IPC Send failed(HEARTBEAT RESPONSE)\n"); return STA_NOK; } return STA_OK; }
int CClaInterface::RegRspFunc(CProtocol &cProto) { CCliRegRspApi cRspApi; string strPayload; strPayload = cProto.GetPayload(); cRspApi.DecodeMessage(strPayload); if(cRspApi.GetCode() != CCliRegRspApi::RESULT_CODE_REG_SUCCESS){ return RESULT_REG_FAILED; } return RESULT_OK; }
void CCommandPra::CmdAppStatus(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CCmdBase clsBase; bool bIsError = false; string strBody; if (a_clsRecvP.IsFlagRequest() == false) { strBody = clsBase.ErrorGen(1, "not set request flag"); bIsError = true; goto JumpSend; } if (clsBase.RequestParse(a_clsRecvP.GetPayload().c_str()) == false) { strBody = clsBase.ErrorGen(1, "invalied body format"); bIsError = true; goto JumpSend; } GetAppStatus(a_clsPM, clsBase); strBody = clsBase.ResponseGen(); JumpSend: CProtocol clsResp; clsResp.SetResponse(a_clsRecvP); if (bIsError) { clsResp.SetFlagError(); } clsResp.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsResp) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsResp.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsResp.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
bool CCommandPra::ProcMesgApp(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CConfigPra& clsCfg = CConfigPra::Instance(); #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Recvive message form App"); a_clsRecvP.Print(g_pclsLogPra, LV_DEBUG, true); #endif int nDstNode = 0; int nDstProc = 0; a_clsRecvP.GetDestination(nDstNode, nDstProc); // TODO // APP에서 ATOM node, proc no을 알수 없어 0으로 지정한 경우 // command에 따라 ATOM node, procno을 재지정 해준다. // 이럴 경우 APP에서 추가 명령이 발생할 때 마다 수정이 필요하므로 // 향후 개선이 필요하다. if (nDstNode == 0 && nDstProc == 0) { int nCmd = atoi(a_clsRecvP.GetCommand().c_str()); switch (nCmd) { case CMD_NODELIST : CAddress::Instance().LookupAtom("ATOM_NM", nDstNode, nDstProc); a_clsRecvP.SetDestination(nDstNode, nDstProc); break; } } // PRA가 처리해 할 명령인가? if (nDstProc == clsCfg.m_nProcNo) { return Command(a_clsRecvP, a_clsPM); } // agent에 메세지 전송 CModuleIPC& clsIPC = CModuleIPC::Instance(); if (clsIPC.SendMesg(a_clsRecvP) == false) { g_pclsLogPra->ERROR("CMD, mode ipc send failed"); a_clsRecvP.Print(g_pclsLogPra, LV_INFO); return false; } // APP의 Alive 주기적 검사를 줄이기 위해 APP에서 메세지가 왔다면 // 이를 APP가 정상적으로 Alive 중인것으로 판단. int nSrcNode = 0; int nSrcProc = 0; a_clsRecvP.GetSource(nSrcNode, nSrcProc); if (nSrcProc > 0) { a_clsPM.AliveOk(nSrcProc); } return true; }
void CCommandPra::CmdAppInit(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CConfigPra& clsCfg = CConfigPra::Instance(); CAppQueue& clsQ = CAppQueue::Instance(); CCmdAppInit clsInit; // Request body parsing CCmdAppInit::ST_RESPONSE stResponse; string strBody; bool bIsError = false; CCmdAppCtl clsCtl; // APP에 보낼 body 메세지 CProtocol clsSendP; // APP에 보낼 message if (a_clsRecvP.IsFlagRequest() == false) { strBody = clsInit.ErrorGen(1, "CMD 'APP_INIT', not set request flag"); bIsError = true; goto JumpSend; } if (clsInit.RequestParse(a_clsRecvP.GetPayload().c_str()) == false) { strBody = clsInit.ErrorGen(1, "CMD 'APP_INIT', invalied body format"); bIsError = true; goto JumpSend; } // 프로세스 보낼 메세지 구성 clsCtl.m_strAction = "INIT"; clsSendP.SetCommand(CMD_APP_CTL); clsSendP.SetFlagNotify(); clsSendP.SetSource(clsCfg.m_nNodeNo, clsCfg.m_nProcNo); clsSendP.SetSequence(); clsSendP.SetPayload(clsCtl.RequestGen()); if (clsInit.m_bIsAll) { // 전체 프로세스 init 요청 vector<CProcessManager::ST_APPINFO> vecInfo; a_clsPM.GetAppInfo(vecInfo, CProcStatus::RUNNING); for (size_t i=0; i < vecInfo.size(); ++i) { clsSendP.SetDestination(clsCfg.m_nNodeNo, vecInfo[i].m_nProcNo); stResponse.m_nProcNo = vecInfo[i].m_nProcNo; stResponse.m_strProcName = vecInfo[i].m_strProcName; stResponse.m_bSuccess = true; if (clsQ.SendCmd(clsSendP, vecInfo[i].m_strProcName.c_str()) == false) { g_pclsLogPra->ERROR("APP init send failed"); stResponse.m_bSuccess = false; } clsInit.m_lstResponse.push_back(stResponse); } } else { // 지정 프로세스의 init 요청 list<pair<int, string> >::iterator iter = clsInit.m_lstTarget.begin(); for (; iter != clsInit.m_lstTarget.end(); ++iter) { clsSendP.SetDestination(clsCfg.m_nNodeNo, iter->first); stResponse.m_nProcNo = iter->first; stResponse.m_strProcName = iter->second; stResponse.m_bSuccess = true; if (clsQ.SendCmd(clsSendP, iter->second.c_str()) == false) { g_pclsLogPra->ERROR("APP init send failed"); stResponse.m_bSuccess = false; } clsInit.m_lstResponse.push_back(stResponse); } } strBody = clsInit.ResponseGen(); JumpSend: CProtocol clsResp; clsResp.SetResponse(a_clsRecvP); if (bIsError) { clsResp.SetFlagError(); } clsResp.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsResp) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsResp.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsResp.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
void CCommandPra::CmdCli_InitProc(CProtocol& a_clsRecvP, CCliReq& clsCliReq, CProcessManager& a_clsPM) { CConfigPra& clsCfg = CConfigPra::Instance(); // 프로세스 보낼 메세지 구성 CCmdAppCtl clsCtl; // APP에 보낼 body 메세지 clsCtl.m_strAction = "INIT"; CProtocol clsSendP; // APP에 보낼 message clsSendP.SetCommand(CMD_APP_CTL); clsSendP.SetFlagNotify(); clsSendP.SetSource(clsCfg.m_nNodeNo, clsCfg.m_nProcNo); clsSendP.SetSequence(); clsSendP.SetPayload(clsCtl.RequestGen()); // CLI response 메세지 구성 CCliRsp clsCliRsp; clsCliRsp.SetSessionId(clsCliReq.GetSessionId()); clsCliRsp.SetResultCode(1, "SUCCESS"); clsCliRsp.SetText (""); clsCliRsp.SetTextAppend("================================\n"); clsCliRsp.SetTextAppend(" procno procname success\n"); clsCliRsp.SetTextAppend("---------- ---------- ----------\n"); CAppQueue& clsQ = CAppQueue::Instance(); string strProcName; int nProcNo = -1; for (uint32_t i=0; i < clsCliReq.GetCount(); i++) { // Argument if (clsCliReq[i].GetName().compare("SERVICE_NAME") == 0) { // TODO // sevice name process invoke continue; } else if (clsCliReq[i].GetName().compare("PROCESS_NAME") == 0) { // Parameter for (uint32_t j=0; j < clsCliReq[i].GetCount(); j++) { strProcName = clsCliReq[i][j].GetString(); nProcNo = a_clsPM.FindProcNo(strProcName); if (nProcNo <= 0) { g_pclsLogPra->ERROR("CMD 'CLI' uknown process no, pname: %s", strProcName.c_str()); clsCliRsp.NPrintf(1024, "%10d %10s %10s\n", -1, strProcName.c_str(), "FAILED"); continue; } // 프로세스의 init 요청 clsSendP.SetDestination(clsCfg.m_nNodeNo, nProcNo); if (clsQ.SendCmd(clsSendP, clsCliReq[i][j].GetString().c_str()) == false) { g_pclsLogPra->ERROR("APP init send failed"); clsCliRsp.NPrintf(1024, "%10d %10s %10s\n", -1, strProcName.c_str(), "FAILED"); continue; } clsCliRsp.NPrintf(1024, "%10d %10s %10s\n", nProcNo, strProcName.c_str(), "OK"); } } } clsCliRsp.SetTextAppend("================================\n"); string strBody; clsCliRsp.EncodeMessage(strBody); // 응답 메세지 생성 clsSendP.SetResponse(a_clsRecvP); clsSendP.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsSendP) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsSendP.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsSendP.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
void CCommandPra::CmdCli_StopProc(CProtocol& a_clsRecvP, CCliReq& clsCliReq, CProcessManager& a_clsPM) { vector<int> vecTarget; int nProcNo = -1; for (uint32_t i=0; i < clsCliReq.GetCount(); i++) { // Argument if (clsCliReq[i].GetName().compare("SERVICE_NAME") == 0) { // TODO // sevice name process invoke continue; } else if (clsCliReq[i].GetName().compare("PROCESS_NAME") == 0) { // Parameter for (uint32_t j=0; j < clsCliReq[i].GetCount(); j++) { nProcNo = a_clsPM.FindProcNo(clsCliReq[i][j].GetString()); if (nProcNo <= 0) { g_pclsLogPra->ERROR("CMD 'CLI' uknown process no, pname: %s", clsCliReq[i][j].GetString().c_str()); continue; } a_clsPM.Stop(nProcNo); vecTarget.push_back(nProcNo); } } } list<CProcessManager::ST_APPRUNINFO> lstInfo; list<CProcessManager::ST_APPRUNINFO>::iterator liter; struct tm ltm; char szStartTime[40] = {0x00,}; char szStopTime[40] = {0x00,}; CCliRsp clsCliRsp; clsCliRsp.SetSessionId(clsCliReq.GetSessionId()); clsCliRsp.SetResultCode(1, "SUCCESS"); clsCliRsp.SetText (""); clsCliRsp.SetTextAppend("===============================================================================================\n"); clsCliRsp.SetTextAppend(" pid procname status start time stop time version\n"); clsCliRsp.SetTextAppend("---------- -------------------- ---------- -------------------- -------------------- ----------\n"); for (size_t i=0; i < vecTarget.size(); i++) { if (a_clsPM.GetStatus(lstInfo, vecTarget[i]) != 1) { g_pclsLogPra->ERROR("CMD 'CLI' status not found, pno: %d", vecTarget[i]); continue; } liter = lstInfo.begin(); if (liter->m_stRun.m_tStartTime > 0) { localtime_r(&liter->m_stRun.m_tStartTime, <m); snprintf(szStartTime, sizeof(szStartTime), "%04d-%02d-%02d %02d:%02d:%02d", ltm.tm_year + 1900, ltm.tm_mon+1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec); } if (liter->m_stRun.m_tStopTime > 0) { localtime_r(&liter->m_stRun.m_tStopTime, <m); snprintf(szStopTime, sizeof(szStopTime), "%04d-%02d-%02d %02d:%02d:%02d", ltm.tm_year + 1900, ltm.tm_mon+1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec); } clsCliRsp.NPrintf(1024, "%10d %-20s %10s %20s %20s %10s\n", liter->m_stRun.m_nPid, liter->m_stInfo.m_strProcName.c_str(), CProcStatus::StatusToString(liter->m_stRun.m_enStatus), szStartTime, szStopTime, liter->m_stRun.m_strVersion.c_str()); } clsCliRsp.SetTextAppend("===============================================================================================\n"); string strBody; clsCliRsp.EncodeMessage(strBody); // 응답 메세지 생성 CProtocol clsSendP; clsSendP.SetResponse(a_clsRecvP); clsSendP.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsSendP) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsSendP.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsSendP.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
void CCommandPra::CmdCli_DispProc(CProtocol& a_clsRecvP, CCliReq& clsCliReq, CProcessManager& a_clsPM) { list<CProcessManager::ST_APPRUNINFO> lstInfo; a_clsPM.GetStatus(lstInfo, -1); string strWorst = CProcStatus::StatusToString(a_clsPM.GetStatusWorst()); struct tm ltm; char szStartTime[40] = {0x00,}; char szStopTime[40] = {0x00,}; CCliRsp clsCliRsp; clsCliRsp.SetSessionId(clsCliReq.GetSessionId()); clsCliRsp.SetResultCode(1, "SUCCESS"); clsCliRsp.SetText (""); clsCliRsp.NPrintf(1024, "worst status: %s\n", strWorst.c_str()); clsCliRsp.SetTextAppend("===============================================================================================\n"); clsCliRsp.SetTextAppend(" pid procname status start time stop time version\n"); clsCliRsp.SetTextAppend("---------- -------------------- ---------- -------------------- -------------------- ----------\n"); for (auto iter = lstInfo.begin(); iter != lstInfo.end(); ++iter) { if (iter->m_stRun.m_tStartTime > 0) { localtime_r(&iter->m_stRun.m_tStartTime, <m); snprintf(szStartTime, sizeof(szStartTime), "%04d-%02d-%02d %02d:%02d:%02d", ltm.tm_year + 1900, ltm.tm_mon+1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec); } if (iter->m_stRun.m_tStopTime > 0) { localtime_r(&iter->m_stRun.m_tStopTime, <m); snprintf(szStopTime, sizeof(szStopTime), "%04d-%02d-%02d %02d:%02d:%02d", ltm.tm_year + 1900, ltm.tm_mon+1, ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec); } clsCliRsp.NPrintf(1024, "%10d %-20s %10s %20s %20s %10s\n", iter->m_stRun.m_nPid, iter->m_stInfo.m_strProcName.c_str(), CProcStatus::StatusToString(iter->m_stRun.m_enStatus), szStartTime, szStopTime, iter->m_stRun.m_strVersion.c_str()); } clsCliRsp.SetTextAppend("===============================================================================================\n"); string strBody; clsCliRsp.EncodeMessage(strBody); // 응답 메세지 생성 CProtocol clsSendP; clsSendP.SetResponse(a_clsRecvP); clsSendP.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsSendP) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsSendP.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsSendP.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
//------------------------------------------------------------------------------ int main( int argc, char* argv[] ) { string usbId; printf( VERSIONINFO "\n" ); if( argc != 2) { help(); return 1; } strncpy( filename, argv[1], sizeof(filename) ); // load settings: cout << "reading psi46test.ini..." << endl; if( !settings.read( "psi46test.ini" ) ) { printf( "error reading \"psi46test.ini\"\n" ); return 2; } cout << "logging to " << filename << endl; if( !Log.open( filename ) ) { printf( "log: error creating file\n" ); return 3; } for( size_t iroc = 0; iroc < 16; ++iroc ) for( size_t idac = 0; idac < 256; ++idac ) dacval[iroc][idac] = -1; // DP // open test board on USB: Log.section("DTB"); try { if( !tb.FindDTB(usbId) ) { printf( "found DTB %s\n", usbId.c_str() ); } else if( tb.Open( usbId ) ) { printf( "\nDTB %s opened\n", usbId.c_str() ); string info; try { tb.GetInfo(info); printf( "--- DTB info-------------------------------------\n" "%s" "-------------------------------------------------\n", info.c_str() ); Log.puts( info.c_str() ); tb.Welcome(); tb.Flush(); } catch( CRpcError &e ) { e.What(); printf( "ERROR: DTB software version could not be identified, please update it!\n" ); tb.Close(); printf( "Connection to Board %s has been cancelled\n", usbId.c_str() ); } } else { printf( "USB error: %s\n", tb.ConnectionError() ); printf( "DTB: could not open port to device %s\n", settings.port_tb ); printf( "Connect testboard and try command 'scan' to find connected devices.\n" ); printf( "Make sure you have permission to access USB devices.\n" ); } // open wafer prober: if( settings.port_prober >= 0 ) if( !prober.open( settings.port_prober ) ) { printf( "Prober: could not open port %i\n", settings.port_prober ); Log.puts( "Prober: could not open port\n" ); return 4; } Log.flush(); // Beat Meier: vector<uint16_t> vx; vx.resize(13); for (unsigned int i=0; i<vx.size(); i++) vx[i] = i+1000; tb.VectorTest(vx, vx); printf("vx={"); for (unsigned int i=0; i<vx.size(); i++) printf(" %i",int(vx[i])); printf(" }\n"); #ifdef ROOT TFile* histoFile = new TFile( "Test.root", "RECREATE" ); cout << "ROOT application..." << endl; TApplication theApp( "psi46test", &argc, argv ); #endif // call command interpreter: nEntry = 0; cmd(); cout << "Daq close..." << endl; tb.Daq_Close(); tb.Flush(); cout << "ROOT close ..." << endl; //histoFile->Write(); histoFile->Close(); tb.Close(); } catch( CRpcError &e ) { e.What(); } return 0; }
void CCommandPra::CmdBatchStart(CProtocol& a_clsRecvP, CProcessManager& a_clsPM) { CCmdBatchStart clsBatch; bool bIsError = false; string strBody; CProcStatus::EN_STATUS nStatus = CProcStatus::NONE; if (a_clsRecvP.IsFlagRequest() == false) { strBody = clsBatch.ErrorGen(1, "not set request flag"); bIsError = true; goto JumpSend; } if (clsBatch.RequestParse(a_clsRecvP.GetPayload().c_str()) == false) { strBody = clsBatch.ErrorGen(1, "invalied body format"); bIsError = true; goto JumpSend; } // 배치 프로세스 실행 a_clsPM.Run(clsBatch.m_nProcNo); // batch exit wait usleep(100); a_clsPM.CheckExit(clsBatch.m_nProcNo); nStatus = a_clsPM.GetStatus(clsBatch.m_nProcNo); switch (nStatus) { case CProcStatus::RUNNING : clsBatch.m_strStatus = "pending"; break; case CProcStatus::STOPPED : clsBatch.m_strStatus = "normal"; clsBatch.m_nExitCd = a_clsPM.GetExitCode(clsBatch.m_nProcNo); break; default : clsBatch.m_strStatus = "failed"; } strBody = clsBatch.ResponseGen(); JumpSend: CProtocol clsResp; clsResp.SetResponse(a_clsRecvP); if (bIsError) { clsResp.SetFlagError(); } clsResp.SetPayload(strBody); if (CModuleIPC::Instance().SendMesg(clsResp) == false) { g_pclsLogPra->ERROR("CMD, send message failed, %s", CModuleIPC::Instance().m_strErrorMsg.c_str()); clsResp.Print(g_pclsLogPra, LV_ERROR, true); } #ifdef PRA_DEBUG g_pclsLogPra->DEBUG("Send message"); clsResp.Print(g_pclsLogPra, LV_DEBUG, true); #endif return; }
CSession( UINT id ) : m_id(id) { protocol.Clear(); protocol.Append( new CTcpProtocol ); protocol.Append( new CHttpProtocol ); protocol.Append( new CXmlRpcProtocol ); }
int32_t CCMWebServer::showNode_WatchPoint(CMClient *pClient, stringstream &ss) { CMTCPClient cClientM, cClientS; vector<string> server_spec; pClient->getCMTCPServer(server_spec); if (server_spec.size() >= 1) { cClientM.setServerAddr(server_spec[0].c_str()); cClientM.start(); } if (server_spec.size() >= 2) { cClientS.setServerAddr(server_spec[1].c_str()); cClientS.start(); } CNodetype cNodeType; CProtocol cProtocol; getNodeInput in; getNodeOutput out; in.type = cmd_get_info_watchpoint; if(in.nodeToBuf() <= 0) { ss << "Communication Error!"; return -1; } char* replyBody = NULL; int32_t replyLen = 0; if(cClientM.send(in.buf, in.len) == 0 && cClientM.recv(replyBody, replyLen) == 0 || cClientS.send(in.buf, in.len) == 0 && cClientS.recv(replyBody, replyLen) == 0) { ss << "<html>\n"; ss << " <head></head>\n"; ss << " <body>\n"; char* p = replyBody; //eMessageType type = (eMessageType)(*p); p += 1; int32_t node_num = ntohl(*(int32_t*)p); p += 4; ss << " <a href=\"\" onclick=\"history.back(); return false;\">Back</a>\n"; ss << " <a href=\"\" onclick=\"location.reload(); return false;\">Refresh</a>\n"; ss << " <br> <b>All Nodes' State and WatchPoint</b>\n"; ss << " <br> Total Nodes' Number: <b>" << node_num << "</b>\n"; ss << " <table frame=\"box\" rules=\"all\">\n"; ss << " <tr>\n"; ss << " <td align=\"center\">Node</td>\n"; ss << " <td align=\"center\">State</td>\n"; ss << " <td align=\"center\">CPU Busy</td>\n"; ss << " <td align=\"center\">Load One</td>\n"; ss << " </tr>\n"; for (int32_t j = 0; j < node_num; j++) { ss << " <tr>"; ss << "<td align=\"center\">"; ss << cProtocol.protocolToStr((eprotocol)*p); p += 1; string ip = p; ss << ":" << ip.c_str(); p += 24; ss << ":" << ntohs(*(uint16_t*)p) << "</td>"; p += 2; estate state = (estate)(*p); p += 1; ss << "<td align=\"center\" bgcolor=\""; if (state == normal) { ss << "lawngreen\">"; } else { ss << "red\">"; } if (state == normal) { ss << "Normal"; } else if (state == abnormal) { ss << "Abnormal"; } else if (state == timeout) { ss << "Timeout"; } else if (state == unvalid) { ss << "Unvalid"; } else if (state == uninit) { ss << "Uninit"; } else { ss << "Unknown"; } ss << "</td>"; ss << "<td align=\"center\">" << ntohl(*(uint32_t*)p) << ".0 %</td>"; p += 4; ss << "<td align=\"center\">" << ntohl(*(uint32_t*)p) << ".0</td>"; p += 4; ss << "<tr>\n"; } ss << " </table>\n"; ss << " </body>\n"; ss << "</html>\n"; } else { ss << "Communication Error!"; return -1; } return 0; }
void CHttpThread::sendHttp(const CProtocol& protocol) { //LOG_PROTOCOL(protocol); QByteArray postData; // konwertuj protokol do postaci binarnej tablicy QByteArray if (!convertToBinary(postData, protocol)){ // nieprawidlowy format protokolu LOG_ERROR("Sending protocol error. idPackage:", protocol.getIdPackage()); DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::OUTPUT_PROTOCOL_FORMAT_ERROR)); resultsQueue.push(res); } else { //convertToProtocolDebug(postData); uint16_t crc = NUtil::CCryptography::crc16(postData.constData(), postData.size()); postData.replace(postData.size() - sizeof(crc), sizeof(crc), reinterpret_cast<char*>(&crc), sizeof(crc)); // tworzy tymczasowa petle komunikatow QEventLoop eventLoop; // dla sygnalu QNetworkAccessManager::finished wywolaj QEventLoop::quit QNetworkAccessManager mgr; QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); // HTTP const std::string url = NEngine::CConfigurationFactory::getInstance()->getServerUrl(); QUrl qUrl(url.c_str()); QNetworkRequest req(qUrl); // typ MIME req.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/octet-stream")); // wyslij post'a std::shared_ptr<QNetworkReply> reply(mgr.post(req, postData)); eventLoop.exec(); // czekaj QEventLoop::quit (czyli QNetworkAccessManager::finished) if (reply->error() == QNetworkReply::NoError) { //success LOG_DEBUG("Protocol has been sent successfully. idPackage:", protocol.getIdPackage()); CByteWrapper wrapper(reply->readAll()); // wyslanie potwierdzenia zmiany konfiguracji - jesli zmiana odbyla sie bez problemow nie zwraca danych if (wrapper.getSize() > 0) { if (!wrapper.isCRCValid()) { LOG_ERROR("Received protocol error - CRC. idPackage:", protocol.getIdPackage()); DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::CRC_ERROR)); resultsQueue.push(res); } else { std::shared_ptr<CProtocol> responseProtocol = convertToProtocol(wrapper); // przekonwertuj do struktury if (!responseProtocol) { // blad struktury protokolu LOG_ERROR("Received protocol error. idPackage:", protocol.getIdPackage()); DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::INPUT_PROTOCOL_FORMAT_ERROR)); resultsQueue.push(res); } else { LOG_DEBUG("Protocol has been received successfully. idPackage:", responseProtocol->getIdPackage()); DConnectionResult res(new CConnectionResult(protocol, responseProtocol, EConnectionStatus::NONE)); resultsQueue.push(res); } } } } else { LOG_ERROR("Protocol sending error. idPackage:", protocol.getIdPackage(), ". Error: ", reply->errorString().toStdString()); DConnectionResult res(new CConnectionResult(protocol, EConnectionStatus::CONNECTION_ERROR)); resultsQueue.push(res); } } }
bool CHttpThread::convertToBinary(QByteArray& array, const CProtocol& protocol) { array.reserve(protocol.getSize()); convertToBinary(array, protocol.getVersion()); convertToBinary(array, protocol.getSize()); convertToBinary(array, protocol.getIdConcentrator()); convertToBinary(array, protocol.getIdPackage()); convertToBinary(array, protocol.getType()); switch(protocol.getType()){ case MONITOR_DATA: convertToBinary(array, std::dynamic_pointer_cast<CMonitorData>(protocol.getMessage())); break; case CONFIGURATION_RESPONSE: convertToBinary(array, std::dynamic_pointer_cast<CConfigurationResponse>(protocol.getMessage())); break; case SERVER_REQUEST: convertToBinary(array, std::dynamic_pointer_cast<CServerRequest>(protocol.getMessage())); break; case SERVER_MONITOR_RESPONSE: // typ protokolu server -> concentrator return false; break; } convertToBinary(array, protocol.getCRC()); return true; }
int OnRecv( CBuffer* pBuffer ){ protocol.Execute( pBuffer ); return 0; }