📄 upnodeinit.cpp
字号:
/********************************************************************** FileName : UpNodeInit.cpp Description : 上节点初始化函数集 Version : 1.0 Date : 2003年6月17日 Author : 刘荣辉 Other : ***********************************************************************/#include "../include/UpNode.h"//CUpNode::CUpNode()//CUpNode::~CUpNode()//int CUpNode::GetParam(char *FileName); //从配置文件中读取参数值 //int CUpNode::NodeInit(); //初始化(日志/队列参数)//int CUpNode::GetSequence(); //互斥地获得当前流水号,并加1//====================构造函数=======================CUpNode::CUpNode(){ }//====================虚构函数=======================CUpNode::~CUpNode(){ delete WrDeliverLog; delete WrReportLog; delete WrSubmitLog; delete WrSubmit_FailLog; delete RecvQ; delete RspQ; delete SendQ; pthread_mutex_destroy(&SentQ_Lock); pthread_mutex_destroy(&SeqId_Lock); /* MysqlDb->DBClose(); delete MysqlDb; */ }//==========================================================================//====================从配置文件中读取参数值=======================int CUpNode::GetParam(char *FileName){ int RetCode; FileOpr *Fileopr=new FileOpr(); if((RetCode=Fileopr->RWOpen(FileName, "r"))>0) //打开配置文件 { printf("\nError[%d]: Failed to open [%s].",RetCode,FileName); return RetCode; } //------------------------------- if((RetCode=Fileopr->RWRead("DeliverLogFile",DeliverLogFile))>0) { printf("\nError[%d]: Failed to Read 'DeliverLogFile' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("SubmitLogFile",SubmitLogFile))>0) { printf("\nError[%d]: Failed to Read 'SubmitLogFile' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("ReportLogFile",ReportLogFile))>0) { printf("\nError[%d]: Failed to Read 'ReportLogFile' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Submit_FailFile",Submit_FailFile))>0) { printf("\nError[%d]: Failed to Read 'Submit_FailFile' from [%s].\n",RetCode,FileName); return RetCode; } RetCode=Fileopr->RWRead("UpQueueBak",UpQueueBak); if(RetCode) { printf("\nError[%d]: Failed to Read 'UpQueueBak' from [%s].\n",RetCode,FileName); return RetCode; } RetCode=Fileopr->RWRead("UpRecvQ_File",UpRecvQ_File); if(RetCode) { printf("\nError[%d]: Failed to Read 'UpRecvQ_File' from [%s].\n",RetCode,FileName); return RetCode; } RetCode=Fileopr->RWRead("UpSendQ_File",UpSendQ_File); if(RetCode) { printf("\nError[%d]: Failed to Read 'UpSendQ_File' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("NodeID",&NodeID))>0) { printf("\nError[%d]: Failed to Read 'NodeID' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Protocol",&Protocol))>0) { printf("\nError[%d]: Failed to Read 'Protocol' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("NodeCode",NodeCode))>0) { printf("\nError[%d]: Failed to Read 'NodeCode' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("SP_Name",SP_Name))>0) { printf("\nError[%d]: Failed to Read 'SP_Name' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("SP_Id",SP_Id))>0) { printf("\nError[%d]: Failed to Read 'SP_Id' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("SP_Code",SP_Code))>0) { printf("\nError[%d]: Failed to Read 'SP_Code' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("NodeIp",NodeIp))>0) { printf("\nError[%d]: Failed to Read 'NodeIp' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Port",&Port))>0) { printf("\nError[%d]: Failed to Read 'Port' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Secret",Secret))>0) { printf("\nError[%d]: Failed to Read 'Secret' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("ShowLog",&ShowLog))>0) { printf("\nError[%d]: Failed to Read 'ShowLog' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Sent_Window_Size",&Sent_Window_Size))>0) { printf("\nError[%d]: Failed to Read 'Sent_Window_Size' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("ActiveTest_Time",&ActiveTest_Time))>0) { printf("\nError[%d]: Failed to Read 'ActiveTest_Time' from [%s].\n",RetCode,FileName); return RetCode; } if (ActiveTest_Time<10 || ActiveTest_Time>100) { ActiveTest_Time=50; //ActiveTest_Time超限时的缺省值 } if((RetCode=Fileopr->RWRead("Recv_Queue_Size",&Recv_Queue_Size))>0) { printf("\nError[%d]: Failed to Read 'Recv_Queue_Size' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Send_Queue_Size",&Send_Queue_Size))>0) { printf("\nError[%d]: Failed to Read 'Send_Queue_Size' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Recv_Q_Full_Wait",&Recv_Q_Full_Wait))>0) { printf("\nError[%d]: Failed to Read 'Recv_Q_Full_Wait' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Send_Q_Full_Wait",&Send_Q_Full_Wait))>0) { printf("\nError[%d]: Failed to Read 'Send_Q_Full_Wait' from [%s].\n",RetCode,FileName); return RetCode; } if((RetCode=Fileopr->RWRead("Send_Q_Empty_Wait",&Send_Q_Empty_Wait))>0) { printf("\nError[%d]: Failed to Read 'Send_Q_Empty_Wait' from [%s].\n",RetCode,FileName); return RetCode; } //------------------------------- if((RetCode=Fileopr->RWClose())>0) //关闭配置文件 { printf("\nError[%d]: Failed to Close [%s].",RetCode,FileName); return RetCode; } delete Fileopr; return 0;}//=========================初始化参数===============================int CUpNode::NodeInit(){ int RetCode; ToExit = 0; //节点退出标识 State = 1; //节点状态为正在连接 SeqId = 1; //发给上节点的包的流水号 ReadThr = 0; WriteThr = 0; //------------------日志文件初始化---------------------- WrDeliverLog=new FileOpr(); WrSubmitLog=new FileOpr(); WrReportLog=new FileOpr(); WrSubmit_FailLog=new FileOpr(); if((RetCode=WrDeliverLog->RWOpen(DeliverLogFile, "w"))>0) //打开Deliver日志文件 { printf("\nError[%d]: Opening DeliverLog file.",RetCode); return 1 ; } if((RetCode=WrSubmitLog->RWOpen(SubmitLogFile, "w"))>0) //打开Submit日志文件 { printf("\nError[%d]: Opening SubmitLog file.",RetCode); return 1 ; } if((RetCode=WrReportLog->RWOpen(ReportLogFile, "w"))>0) //打开Report日志文件 { printf("\nError[%d]: Opening ReportLog file.",RetCode); return 1 ; } if((RetCode=WrSubmit_FailLog->RWOpen(Submit_FailFile, "w"))>0) //打开Submit_Fail日志文件 { printf("\nError[%d]: Opening Submit_FailFile.",RetCode); return 1 ; } //------------------队列初始化---------------------- RecvQ = new FIFO_RecvQ(Recv_Queue_Size); //收、发队列初始化 SendQ = new FIFO_SendQ(Send_Queue_Size); RspQ = new FIFO_RecvQ(Send_Queue_Size*2); //应答包队列初始化 SentQ.Map_Init(Sent_Window_Size); //已发送队列初始化,滑动窗口 pthread_mutex_init(&SentQ_Lock,NULL); pthread_mutex_init(&SeqId_Lock,NULL); /* MysqlDb = new DB_MySQL; //数据库初始化、连接 MysqlDb->DBInit(DB_ConfigFile); MysqlDb->DBConn(); */ return 0;}//==========================================================================//===========================获得当前流水号=================================int CUpNode::GetSequence() //互斥地获得当前流水号,并加1{ int temp; pthread_mutex_lock(&SeqId_Lock); temp = SeqId++; pthread_mutex_unlock(&SeqId_Lock); return temp ; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -