📄 ivrserverdoc.cpp
字号:
// IvrServerDoc.cpp : implementation of the CIvrServerDoc class
//
#include "stdafx.h"
#include "IvrServer.h"
#include "IvrServerView.h"
#include "IvrServerDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIvrServerDoc
int iMaxClients=0;
int bNeed;
int iDate;
int iRnum;
char strIP[IP_LEN]; //连接IP地址
int iCToSerPort; //连接服务器的端口号
int g_iTimeOut = 0; //超时值
int iInterface = 0; //接口
IMPLEMENT_DYNCREATE(CIvrServerDoc, CDocument)
BEGIN_MESSAGE_MAP(CIvrServerDoc, CDocument)
//{{AFX_MSG_MAP(CIvrServerDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIvrServerDoc construction/destruction
CIvrServerDoc::CIvrServerDoc()
{
// TODO: add one-time construction code here
}
CIvrServerDoc::~CIvrServerDoc()
{
}
BOOL CIvrServerDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
((CEditView*)m_viewList.GetHead())->SetWindowText(NULL);
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
//0.
char sTemp[STRTEMP_LEN];
memset(sTemp,0x00, sizeof(sTemp));
//1.读取配置文件
if (ReadConfigParam() != RETCODE_SUCCESS)
{
return FALSE;
}
ShowMsg("========> 模拟业务网关产品程序主控显示 <========", bNeed);
//创建线程
pMainThread = (CMainThread *)AfxBeginThread( \
RUNTIME_CLASS(CMainThread), \
THREAD_PRIORITY_NORMAL, \
0, \
CREATE_SUSPENDED, \
NULL);
if (pMainThread != NULL)
{
pMainThread->m_pDoc = this;
switch(m_iType)
{
case 1: //des
pMainThread->iServerPort = iPortDes;
sprintf(sTemp, "DES 服务器主线程 (%p) 巳开始运行...", (void *)pMainThread);
iInterface = INTERFACESEMMETRY; //接口
break;
case 2: //CTCA
pMainThread->iServerPort = iPortCtca;
sprintf(sTemp, "CTCA 服务器主线程 (%p) 巳开始运行...", (void *)pMainThread);
iInterface = INTERFACECTCAANDDER; //接口
break;
case 3:
pMainThread->iServerPort = iPortVis;
sprintf(sTemp, "业务网关服务器主线程 (%p) 巳开始运行...", (void *)pMainThread);
iInterface = INTERFACEVISIBALE; //接口
break;
default:
break;
}
pMainThread->ResumeThread();
ShowMsg(sTemp, bNeed);
}
else
{
ShowMsg("创建服务器主线程失败.", bNeed);
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CIvrServerDoc serialization
void CIvrServerDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CIvrServerDoc diagnostics
#ifdef _DEBUG
void CIvrServerDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CIvrServerDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CIvrServerDoc commands
void CIvrServerDoc::ShowMsg(char *lpszMessage, UINT bNeedShow)
{
for(POSITION pos=GetFirstViewPosition();pos!=NULL;)
{
CView* pView = GetNextView(pos);
CIvrServerView* pQSClientView = DYNAMIC_DOWNCAST(CIvrServerView, pView);
if (pQSClientView != NULL)
{
pQSClientView->ShowMsg(lpszMessage,bNeedShow);
}
}
//((COutBoundView *)m_viewList.GetHead())->ShowMsg(lpszMessage,bNeedShow);
return;
}
void CIvrServerDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
if (!m_viewList.IsEmpty())
{
((CEditView*)m_viewList.GetHead())->SetWindowText(_T(""));
}
CDocument::DeleteContents();
}
BOOL CIvrServerDoc::SaveModified()
{
// TODO: Add your specialized code here and/or call the base class
SetModifiedFlag(FALSE);
return CDocument::SaveModified();
}
int CIvrServerDoc::ReadConfigParam()
{
int iRetCode =0;
//1.
if (pCfg.setfilename(CONFIGUREFILE) == RETCODE_FAIL)
{
AfxMessageBox("读指定文件出错!");
return RETCODE_FAIL;
}
//2.
//2.1.最大的客户连接数目
if ( pCfg.readcfgdata("SerCfg", "MaxClient_Num", &iMaxClients) == RETCODE_FAIL)
{
AfxMessageBox("读客户连接数出错!");
return RETCODE_FAIL;
}
//2.2.des通讯服务器端口号
if ( pCfg.readcfgdata("SerCfg", "Ser_PortDes", &iPortDes) == RETCODE_FAIL)
{
AfxMessageBox("读des通讯服务器端口号出错!");
return RETCODE_FAIL;
}
//2.3.ctca通讯服务器端口号
if ( pCfg.readcfgdata("SerCfg", "Ser_PortCtca", &iPortCtca) == RETCODE_FAIL)
{
AfxMessageBox("读ctca通讯服务器端口号出错!");
return RETCODE_FAIL;
}
//2.4.Vis通讯服务器端口号
if ( pCfg.readcfgdata("SerCfg", "Ser_PortVis", &iPortVis) == RETCODE_FAIL)
{
AfxMessageBox("读Vis通讯服务器端口号出错!");
return RETCODE_FAIL;
}
//2.5.Vis通讯服务器端口号
if ( pCfg.readcfgdata("SerCfg", "PortType", &m_iType) == RETCODE_FAIL)
{
AfxMessageBox("读读跑协议类型出错!");
return RETCODE_FAIL;
}
//3.
//3.1.功调试消息标志
if ( pCfg.readcfgdata("Others", "debugflag", &bNeed) == RETCODE_FAIL)
{
AfxMessageBox("读功调试消息标志出错!");
return RETCODE_FAIL;
}
//3.2.超时
if ( pCfg.readcfgdata("Others", "timeout", &g_iTimeOut) == RETCODE_FAIL)
{
AfxMessageBox("读超时参数出错!");
return RETCODE_FAIL;
}
//4.连接对方的服务器参数
//4.1.通讯服务器端口号
if ( pCfg.readcfgdata("ConnectToServer", "cToServerPort", &iCToSerPort) == RETCODE_FAIL)
{
AfxMessageBox("读通讯服务器端口号出错!");
return RETCODE_FAIL;
}
//4.2.连接到的服务器IP
if ( pCfg.readcfgdata("ConnectToServer", "cToServerIp", strIP, sizeof(strIP)) == RETCODE_FAIL)
{
AfxMessageBox("读连接到的服务器IP参数出错!");
return RETCODE_FAIL;
}
return RETCODE_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -