This commit is contained in:
374
CheckServer/MainFrm.cpp
Normal file
374
CheckServer/MainFrm.cpp
Normal file
@@ -0,0 +1,374 @@
|
||||
// MainFrm.cpp : implementation of the CMainFrame class
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CheckServer.h"
|
||||
|
||||
#include "MainFrm.h"
|
||||
#include "ServerSocket.h"
|
||||
#include "CheckServerView.h"
|
||||
#include "..\\Common\\IPInfos.h"
|
||||
#include "SvrOptionDlg.h"
|
||||
#include "WebReloadThread.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame
|
||||
UINT CMainFrame::tm_CMainFrameOnWebNewsFinded = ::RegisterWindowMessage( "CMainFrame OnWebNewsFinded" );
|
||||
|
||||
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
|
||||
|
||||
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
|
||||
//{{AFX_MSG_MAP(CMainFrame)
|
||||
ON_WM_CREATE()
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_CLOSE()
|
||||
ON_WM_TIMER()
|
||||
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CONNECTION_STATUS, OnUpdateConnectionStatus)
|
||||
ON_UPDATE_COMMAND_UI(ID_INDICATOR_CONNECTION_CLIENTS, OnUpdateConnectionClients)
|
||||
ON_COMMAND(ID_OPERATIONS_STARTSERVER, OnOperationsStartserver)
|
||||
ON_UPDATE_COMMAND_UI(ID_OPERATIONS_STARTSERVER, OnUpdateOperationsStartserver)
|
||||
ON_COMMAND(ID_OPERATIONS_STOPSERVER, OnOperationsStopserver)
|
||||
ON_UPDATE_COMMAND_UI(ID_OPERATIONS_STOPSERVER, OnUpdateOperationsStopserver)
|
||||
ON_COMMAND(ID_OPTIONS_PREFERENCES, OnOptionsPreferences)
|
||||
//}}AFX_MSG_MAP
|
||||
ON_REGISTERED_MESSAGE( tm_CMainFrameOnWebNewsFinded, OnWebNewsFinded )
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
static UINT indicators[] =
|
||||
{
|
||||
ID_SEPARATOR, // status line indicator
|
||||
ID_INDICATOR_CONNECTION_STATUS,
|
||||
ID_INDICATOR_CONNECTION_CLIENTS,
|
||||
ID_INDICATOR_TIME,
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame construction/destruction
|
||||
|
||||
CMainFrame::CMainFrame()
|
||||
{
|
||||
m_pApp = (CCheckServerApp*)AfxGetApp();
|
||||
|
||||
m_pView = NULL;
|
||||
m_pServerSocket = NULL;
|
||||
m_bServerStarted = FALSE;
|
||||
m_nPort = 1500;
|
||||
|
||||
m_pCWebReloadThread = NULL;
|
||||
m_strURL[0] = "http://dart.fss.or.kr/dart/TodayDisclosure?type=listing&sort=time&dayCh=0"; // 거래소공시
|
||||
m_strURL[1] = "http://dart.fss.or.kr/dart/TodayDisclosure?type=kosdaq&sort=time&dayCh=0"; // 코스닥공시
|
||||
}
|
||||
|
||||
CMainFrame::~CMainFrame()
|
||||
{
|
||||
}
|
||||
|
||||
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
|
||||
{
|
||||
if( !CFrameWnd::PreCreateWindow(cs) )
|
||||
return FALSE;
|
||||
// TODO: Modify the Window class or styles here by modifying
|
||||
// the CREATESTRUCT cs
|
||||
|
||||
cs.style = WS_OVERLAPPEDWINDOW;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
||||
{
|
||||
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
|
||||
return -1;
|
||||
|
||||
SetMessageText("프로그램 준비중...");
|
||||
|
||||
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
|
||||
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
|
||||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
|
||||
{
|
||||
TRACE0("Failed to create toolbar\n");
|
||||
return -1; // fail to create
|
||||
}
|
||||
|
||||
if (!m_wndStatusBar.Create(this) ||
|
||||
!m_wndStatusBar.SetIndicators(indicators,
|
||||
sizeof(indicators)/sizeof(UINT)))
|
||||
{
|
||||
TRACE0("Failed to create status bar\n");
|
||||
return -1; // fail to create
|
||||
}
|
||||
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CONNECTION_STATUS),
|
||||
ID_INDICATOR_CONNECTION_STATUS,
|
||||
SBPS_POPOUT, 40);
|
||||
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CONNECTION_CLIENTS),
|
||||
ID_INDICATOR_CONNECTION_CLIENTS,
|
||||
SBPS_NORMAL, 65);
|
||||
m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME),
|
||||
ID_INDICATOR_TIME,
|
||||
SBPS_NORMAL, 110);
|
||||
|
||||
// TODO: Delete these three lines if you don't want the toolbar to
|
||||
// be dockable
|
||||
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
|
||||
EnableDocking(CBRS_ALIGN_ANY);
|
||||
DockControlBar(&m_wndToolBar);
|
||||
|
||||
CString szBuf;
|
||||
szBuf.LoadString(AFX_IDS_APP_TITLE);
|
||||
|
||||
//Change title caption
|
||||
SetWindowText(szBuf);
|
||||
|
||||
SetTimer(ID_TIMER_TIME, TIMER_TIME_VALUE, NULL);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 웹 릴로드 쓰레드 시작.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
m_pCWebReloadThread = (CWebReloadThread*) ::AfxBeginThread( RUNTIME_CLASS( CWebReloadThread ), THREAD_PRIORITY_BELOW_NORMAL );
|
||||
ASSERT( m_pCWebReloadThread );
|
||||
m_pCWebReloadThread->RegisterParent( this );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame diagnostics
|
||||
|
||||
#ifdef _DEBUG
|
||||
void CMainFrame::AssertValid() const
|
||||
{
|
||||
CFrameWnd::AssertValid();
|
||||
}
|
||||
|
||||
void CMainFrame::Dump(CDumpContext& dc) const
|
||||
{
|
||||
CFrameWnd::Dump(dc);
|
||||
}
|
||||
|
||||
#endif //_DEBUG
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CMainFrame message handlers
|
||||
|
||||
void CMainFrame::AddMessage(CString szName, CString szMessage)
|
||||
{
|
||||
m_pView = (CCheckServerView*)GetActiveView();
|
||||
m_pView->AddMessage(GlobalHelper::GetLocalTime(), szName, szMessage);
|
||||
}
|
||||
|
||||
void CMainFrame::ClearAllViews()
|
||||
{
|
||||
m_pView = (CCheckServerView*)GetActiveView();
|
||||
m_pView->ClearView();
|
||||
}
|
||||
|
||||
void CMainFrame::UpdateAllView()
|
||||
{
|
||||
m_pView = (CCheckServerView*)GetActiveView();
|
||||
m_pView->UpdateCols();
|
||||
}
|
||||
|
||||
void CMainFrame::UpdateClientsList(CPtrList* pClientstList)
|
||||
{
|
||||
// m_pUserListView->UpdateClientsList(pClientstList);
|
||||
}
|
||||
|
||||
CPtrList* CMainFrame::GetClientsList()
|
||||
{
|
||||
if (!m_pServerSocket)
|
||||
return NULL;
|
||||
|
||||
return m_pServerSocket->GetClientsList();
|
||||
}
|
||||
|
||||
void CMainFrame::OnDestroy()
|
||||
{
|
||||
CFrameWnd::OnDestroy();
|
||||
}
|
||||
|
||||
void CMainFrame::OnClose()
|
||||
{
|
||||
if (!DisconnectServer())
|
||||
return;
|
||||
|
||||
KillTimer(ID_TIMER_TIME);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 웹 릴로드 쓰레드 종료.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Tell the thread to quit
|
||||
m_pCWebReloadThread->Quit( );
|
||||
//Wait for the thread to quit so the object gets cleaned up before the debugger does it's shutdown heap check.
|
||||
::WaitForSingleObject( m_pCWebReloadThread->m_hThread, INFINITE );
|
||||
|
||||
CFrameWnd::OnClose();
|
||||
}
|
||||
|
||||
LRESULT CMainFrame::OnWebNewsFinded( WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
char* pchar = (char*) wParam;
|
||||
CString szBuf = CString (pchar);
|
||||
AddMessage( "WebNews", szBuf );
|
||||
delete pchar;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void CMainFrame::OnTimer(UINT nIDEvent)
|
||||
{
|
||||
switch (nIDEvent) {
|
||||
|
||||
case ID_TIMER_TIME:
|
||||
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME),
|
||||
CTime::GetCurrentTime().Format("%m/%d/%Y %H:%M:%S") );
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
CFrameWnd::OnTimer(nIDEvent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*============================================================================
|
||||
|
||||
Description: Update the status bar connection status indicator
|
||||
|
||||
Return: -
|
||||
|
||||
============================================================================*/
|
||||
void CMainFrame::OnUpdateConnectionStatus(CCmdUI* pCmdUI)
|
||||
{
|
||||
m_wndStatusBar.SetPaneStyle(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CONNECTION_STATUS),
|
||||
m_bServerStarted ? SBPS_NORMAL : SBPS_POPOUT);
|
||||
|
||||
pCmdUI->SetText(m_bServerStarted ? CString((LPCTSTR)IDS_SERVER_CONNECTED) : CString((LPCTSTR)IDS_SERVER_DISCONNECTED));
|
||||
}
|
||||
|
||||
/*============================================================================
|
||||
|
||||
Description: Update the status bar connection status indicator
|
||||
|
||||
Return: -
|
||||
|
||||
============================================================================*/
|
||||
void CMainFrame::OnUpdateConnectionClients(CCmdUI* pCmdUI)
|
||||
{
|
||||
CString szBuf;
|
||||
int nClients = m_pServerSocket ? m_pServerSocket->GetClientsConnectedCount() : 0;
|
||||
szBuf.Format("접속자수: %d", nClients);
|
||||
|
||||
pCmdUI->SetText(szBuf);
|
||||
}
|
||||
|
||||
void CMainFrame::OnOperationsStartserver()
|
||||
{
|
||||
CString szBuf;
|
||||
|
||||
m_pView = (CCheckServerView*)GetActiveView();
|
||||
m_pView->ClearView(); // ClearAllViews();
|
||||
|
||||
m_pServerSocket = new CServerSocket(this);
|
||||
if (m_pServerSocket->BeginListening(m_nPort, 100)) {
|
||||
|
||||
szBuf.Format("Server started and online on port %d.", m_nPort);
|
||||
AddMessage( "Server", szBuf );
|
||||
|
||||
// m_DlgBarUtil.BlockConrols();
|
||||
m_bServerStarted = TRUE;
|
||||
}
|
||||
else {
|
||||
DisconnectServer();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 웹 릴로드 쓰레드 작업시작 지시.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
m_pCWebReloadThread->SetURL( m_strURL );
|
||||
char* pchar0 = new char[ 100 ];
|
||||
strcpy( pchar0, "WebNewsFind" );
|
||||
m_pCWebReloadThread->DoContinuous( pchar0 );
|
||||
}
|
||||
|
||||
void CMainFrame::OnUpdateOperationsStartserver(CCmdUI* pCmdUI)
|
||||
{
|
||||
pCmdUI->Enable(!m_bServerStarted);
|
||||
}
|
||||
|
||||
void CMainFrame::OnOperationsStopserver()
|
||||
{
|
||||
BOOL bDisconnected = DisconnectServer();
|
||||
// if (bDisconnected)
|
||||
// m_DlgBarUtil.BlockConrols(FALSE);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// 웹 릴로드 쓰레드 작업종료 지시.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
m_pCWebReloadThread->StopContinuous();
|
||||
}
|
||||
|
||||
void CMainFrame::OnUpdateOperationsStopserver(CCmdUI* pCmdUI)
|
||||
{
|
||||
pCmdUI->Enable(m_bServerStarted);
|
||||
}
|
||||
|
||||
BOOL CMainFrame::DisconnectServer()
|
||||
{
|
||||
if (!m_pServerSocket)
|
||||
return TRUE;
|
||||
|
||||
int nClients = m_pServerSocket->GetClientsConnectedCount();
|
||||
if (nClients > 0) {
|
||||
CString szBuf;
|
||||
szBuf.Format(IDS_STOP_SERVER, nClients);
|
||||
int nRet = MessageBox(szBuf, CString((LPCTSTR)AFX_IDS_APP_TITLE), MB_ICONQUESTION|MB_YESNO);
|
||||
if (nRet == IDNO)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
AddMessage( "Server", "Server shutdown and offline!" );
|
||||
|
||||
if (m_pServerSocket) {
|
||||
delete m_pServerSocket;
|
||||
m_pServerSocket = NULL;
|
||||
}
|
||||
|
||||
m_bServerStarted = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CMainFrame::OnOptionsPreferences()
|
||||
{
|
||||
CSvrOptionDlg dlg;
|
||||
|
||||
CIPInfos ipinfo;
|
||||
int nCount = ipinfo.GetLocalIPCount();
|
||||
dlg.m_strSvrIP = "";
|
||||
for( int i=0; i<nCount; i++ )
|
||||
{
|
||||
dlg.m_strSvrIP += ipinfo.GetLocalIP(i) + " ";
|
||||
}
|
||||
|
||||
dlg.m_nPort = m_nPort;
|
||||
dlg.m_strURL1 = m_strURL[0];
|
||||
dlg.m_strURL2 = m_strURL[1];
|
||||
|
||||
if( IDOK == dlg.DoModal() )
|
||||
{
|
||||
if( dlg.m_nPort != m_nPort )
|
||||
{
|
||||
AfxMessageBox("서버의 포트번호를 바뀌었습니다. 서버를 다시 시작하야 적용됩니다.");
|
||||
}
|
||||
|
||||
m_nPort = dlg.m_nPort;
|
||||
m_strURL[0] = dlg.m_strURL1;
|
||||
m_strURL[1] = dlg.m_strURL2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user