Beispiel #1
0
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;
}
Beispiel #2
0
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;
}
Beispiel #3
0
int CEmsInfo::SendProcess(int a_nCmdCode, int a_nFlag, char *a_chMessageBuffer, int a_nMessageBufferLen)
{
    bool blnRet = true;
    char strCmdCode[11];
    int nNodeNo = 0;
    int nProcNo = 0;
    CGlobal *cGlob = NULL;
    CModuleIPC *cIpc = NULL;
    CProtocol cProto;

    DEBUG_LOG("SEND PROCESS\n");

    cGlob = CGlobal::GetInstance();

    nNodeNo = cGlob->GetLocalNodeNo();
    nProcNo =  cGlob->GetLocalProcNo();

    cProto.SetSource(nNodeNo, nProcNo);

    /* TEST */
    cProto.SetDestination(m_nAtomNodeNo, m_nStmNo);

    /* flag setting */
    switch(a_nFlag){
        case CProtocol::FLAG_REQUEST:   cProto.SetFlagRequest();    break;
        case CProtocol::FLAG_RESPONSE:  cProto.SetFlagResponse();   break;
        case CProtocol::FLAG_NOTIFY:    cProto.SetFlagNotify();     break;
        case CProtocol::FLAG_RETRNS:    cProto.SetFlagRetransmit(); break;
        case CProtocol::FLAG_BROAD:     cProto.SetFlagBroadcast();  break;
        case CProtocol::FLAG_ERROR:     cProto.SetFlagError();      break;
        default:
                                        STA_LOG(STA_ERR,"Invalid Message flag(%d)\n",a_nFlag);
                                        return STA_NOK;
    }

    /* PKG CLASS ACTION 
     * 000 003 XXXX
     */
    snprintf(strCmdCode, 11,"00000%d",a_nCmdCode);
    strCmdCode[11] = '\0';
    cProto.SetCommand(strCmdCode);

    cProto.SetPayload(a_chMessageBuffer, a_nMessageBufferLen);

    cIpc = cGlob->GetModuleIPC();

    blnRet = cIpc->SendMesg(cProto);
    if(blnRet != true){
        STA_LOG(STA_ERR,"IPC Send failed(cmdCode=%d, flag=%d)\n", a_nCmdCode, a_nFlag);
        return STA_NOK;
    }

    m_nMessageBufferLen = 0;

    return STA_OK;
}
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 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;
}
Beispiel #6
0
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;
}
Beispiel #7
0
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;	
}
Beispiel #8
0
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, &ltm);
			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, &ltm);
			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;	
}
Beispiel #9
0
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, &ltm);
			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, &ltm);
			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;
}
Beispiel #10
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;
}
Beispiel #11
0
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;
}
Beispiel #12
0
int CMain::ReceiveIpcHandler()
{
	int cmdCode = 0;
	string strCmdCode;
	CGlobal *cGlob = NULL;
	CModuleIPC *cIpc = NULL;
	CProtocol cProto;
	char chFlag = 0;
	int nRet = 0;

	cGlob = CGlobal::GetInstance();

	cIpc = cGlob->GetModuleIPC();

	nRet = cIpc->RecvMesg(cGlob->GetLocalProcNo(), cProto, -1);
	if(nRet < 0){
		CLA_LOG(CLA_ERR,false,"Message receive failed(ERR:%s)\n", cIpc->m_strErrorMsg.c_str());
		return CLA_NOK;
	}
	else if(nRet == 0){
		return CLA_OK;
	}

	chFlag = cProto.GetFlag();

	if((chFlag != CProtocol::FLAG_RESPONSE)){
		CLA_LOG(CLA_ERR,false,"Invalid Flag(flag=%d)\n",chFlag);
		return CLA_NOK;
	}

	strCmdCode = cProto.GetCommand();

	cmdCode = CGlobal::GetCmdCode(strCmdCode);

	switch(cmdCode){
		case CMD_CLI_COMMAND:
			{
				unsigned int fd = 0;
				unsigned int nSessionId = 0;
				CCliPeer *cPeer = NULL;
				CSession *cSession = NULL;
				CCliRsp decRsp;
				string strPayload;

				nSessionId = cProto.GetSequence();

				cSession = FindSession(nSessionId);
				if(cSession == NULL){
					CLA_LOG(CLA_ERR,false,"Can not find session(id=%d)\n",nSessionId);
					return CLA_NOK;
				}

				strPayload = cProto.GetPayload();

				decRsp.DecodeMessage(strPayload);

				decRsp.SetSessionId(cSession->GetClcSessionId());

				decRsp.EncodeMessage(strPayload);

				cProto.SetPayload(strPayload);
				cProto.SetSequence(cSession->GetClcSessionId());

				fd = cSession->GetPeerFd();

				cPeer = FindPeerByFd(fd);
				if(cPeer == NULL){
					CLA_LOG(CLA_ERR,false,"Can not find peer(fd=%d)\n",fd);
					delete cSession;
					return CLA_NOK;
				}

				if(cPeer->GetTimestamp() != cSession->GetPeerTimestamp()){
					CLA_LOG(CLA_ERR,false,"Can not find peer(timestamp=%lu, %lu)\n", 
							cPeer->GetTimestamp() ,cSession->GetPeerTimestamp());
					delete cSession;
					return CLA_NOK;
				}

				/* update hist */
				UpdateHist(cPeer, cSession, &decRsp);

				cPeer->Send(cProto);

				delete cSession;
			}
			break;
		default :
			CLA_LOG(CLA_ERR,false,"Invalid cmdCode(%s)\n",cProto.GetCommand().c_str());
			return CLA_NOK;

	};


	return CLA_OK;
}