int main(int argc,char *argv[]) { int rtn; openlog("yktbu",LOG_PID|LOG_CONS|LOG_NDELAY,LOG_LOCAL0); g_pSvrLink = BUPubInitialize(g_XBDefines,CallBDFunc,WriteAppInfo,&g_LogFile); SetLogShowLevel(0); sprintf(g_szVerNo,"%s %s (%s)",argv[0],YKT_VERSION,__DATE__); if(argc==2) { if(strncmp(argv[1],"-v",2)==0||strncmp(argv[1],"-V",2)==0) { printf("%s\n",g_szVerNo); closelog(); return 0; } } if (argc<2) ReadIni("ksbu.ini"); else ReadIni(argv[1]); ResetBPFunctions(); if (argc>2) { ListBPFunctions(argv[2]); } // 初始化数据库连接: SQLInitialize(); if (SQLConnectToServer()!=0) { DEBUG_RUNTIME_MSGOUT("不能正常建立数据库连接, 检查配置和数据库服务器!\n"); return(-100); } DEBUG_RUNTIME_MSGOUT("连接数据库成功!\n"); CAccTrans& ats=CAccTrans::GetInst(); if(ats.LoadCfg()!=0) { DEBUG_RUNTIME_MSGOUT("加载系统参数失败!\n"); //RAISE_RUNTIME_ERROR("加载数据库账务配置参数失败!\n"); return(-200); } DEBUG_RUNTIME_MSGOUT("加载系统参数成功!\n"); // 初始化与BCC连接: do { rtn = g_pSvrLink->ToLink(&g_BUnit); if (rtn==1) { DEBUG_RUNTIME_MSGOUT("与业务调度中心(BCC)的连接成功!\n"); break; } else if (rtn==-100) { DEBUG_RUNTIME_MSGOUT("估计业务调度中心(BCC)尚未正式启动,或者检查配置中的[SERVER]项参数\n"); mysleep(g_BUnit.iHBInterval); } else { // 应该属于故障,或对方并不是BCC return(rtn); } } while (1); #ifdef WIN32 setnoblockgetch(); #endif while (g_pSvrLink->LinkOK()) { #ifdef WIN32 switch (mygetch()) { case '?': case 'h': case 'H': printf("\nCommand List:\n"); printf("\t ? or h: display this Help informations!\n"); printf("\t x: To eXit this business unit.\n"); printf("\t d: Display functions status.\n"); printf("\t l: List functions status into <function.lst>.\n"); printf("Enter command to select:"); break; case 'x': case 'X': g_pSvrLink->bExit = true; continue; break; case 'd': case 'D': ListBPFunctions(NULL); break; case 'l': case 'L': ListBPFunctions("function.lst"); break; } #endif if (!SQLIsConnectOK()) { mysleep(1000); if (!g_pSvrLink->CheckLink()) break; // BCC exit (可能用户发现数据库连接断开,需要维护系统,导致手工将BCC退出同时也需要BU退出) if (SQLConnectToServer()!=0) { // SQL Link error: DEBUG_RUNTIME_MSGOUT("不能正常建立数据库连接, 检查配置和数据库服务器!\n"); } else { DEBUG_RUNTIME_MSGOUT("与数据库连接成功!\n"); } continue; } else g_pSvrLink->Processing(&g_BUnit); if (g_pSvrLink->bExit) break; } /* ****** Updated by CHENYH at 2004-4-14 11:07:19 ****** 经过测试后,CheckLink()工作正常,测试环境为:BCC(WIN)+BU(WIN),BCC(LINUX)+BU(WIN),BCC(LINUX)+BU(LINUX) while (1) { mysleep(1000); if (!g_SvrLink.CheckLink()) { printf("TEST CHECK LINK return <false>!\n"); break; } } */ g_pSvrLink->Close(); SQLExit(); DEBUG_RUNTIME_MSGOUT("业务处理单元BU系统正常退出!\n"); g_LogFile.Close(); closelog(); return(0); }
/* ****** Updated by CHENYH at 2004-4-9 10:06:44 ****** 增加pArrays: 为了能够接收处理多请求记录的情况 */ int CallBDFunc(int fno,TRUSERID *handle,ST_CPACK *rpack,ST_PACK *pArrays,int *iRetCode, char *szMsg) { int r=0; int rtn=0; int sendtype=0; char param[101]=""; #ifdef _DEBUG1 CMemoryState cm1, cm2, cm3; #endif APPFUNC pFunc = g_BDefines[fno].pFunc; #ifdef _DEBUG1 cm1.Checkpoint(); #endif *iRetCode=0; *szMsg=0; //判断是否是结帐时刻,如果是则等待处理 sendtype=rpack->head.RequestType/10000; switch(sendtype) { case 93: rtn = (*pFunc)(handle,rpack->head.RequestType,&rpack->pack,iRetCode,szMsg); break; default: rtn=GetParameter(GLOBE_FLAG_BALANCE,param); if(rtn) { *iRetCode=rtn; break; } else if(strncmp(param,"0",1)!=0) { rtn=E_DAYEND_STATUS; *iRetCode=rtn; break; } rtn = (*pFunc)(handle,rpack->head.RequestType,&rpack->pack,iRetCode,szMsg); break; } if(rtn) { char sErrMsg[60]=""; char sRetMsg[256]=""; if(*szMsg) snprintf(sRetMsg,256," %s",szMsg); r=get_errcode_msg(*iRetCode, sErrMsg); db_rollback(); snprintf(szMsg,256,"%s%s",sErrMsg,sRetMsg); writelog(LOG_ERR,"Func[%d]ecode[%d]msg[%s]",rpack->head.RequestType,*iRetCode,szMsg); ERR_DEAL(szMsg,*iRetCode); if(r) { AnswerData(handle,*iRetCode,szMsg); db_disconnect(); writelog(LOG_ERR,"数据库错误,系统退出"); exit(1); } } else { r=db_commit(); if(r) { *iRetCode=E_DB_COMMIT; strcpy(szMsg,"数据库事务提交失败"); writelog(LOG_ERR,"Func[%d]Msg[%s]",rpack->head.RequestType,szMsg); db_rollback(); ERR_DEAL( szMsg,*iRetCode); } } #ifdef _DEBUG1 cm2.Checkpoint(); if (cm3.Difference(cm1, cm2)) { BCCMsgLogOut(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType); g_LogFile.WriteLogEx(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType); cm3.DumpStatistics(); } #endif if (g_BUnit.m_SqlDB.lErrorCode<=-10000) // 出现SQL比较严重的错误 { if (SQLIsConnectOK()==0) { SQLDisconnect(); } g_BUnit.m_SqlDB.lErrorCode = 0; } return(rtn); }