SDC C-Project CF Review 프로그램
LYW
2021-09-23 097dc87bb95c334e40d856cc558fc24538352ac6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "StdAfx.h"
#include "ResultServerControl.h"
#include "IOCPNetwork/NetDefinition.h"
#include "CHReviewResult/GlassResult.h"
#include "IOCPNetwork/NetServer.h"
 
CResultServerControl::CResultServerControl(void)
{
    m_pServerSocket = NULL;
    InitResultServer();
}
 
CResultServerControl::~CResultServerControl(void)
{
    DeinitResultServer();
}
 
// Result Server
int    CResultServerControl::InitResultServer()
{
    if (m_pServerSocket)
    {
        delete m_pServerSocket;
        m_pServerSocket = NULL;
    }
 
    m_pServerSocket = new CNetServer();
 
    if (m_pServerSocket==NULL) return 0;
 
    int nClientCount = 10;
    m_pServerSocket->SetIN2P(static_cast<IIOCPNetwork2Parent*>(this));
    m_pServerSocket->SetClientInfo(Socket_All_Client, nClientCount, NETCODE_RESULT_SERVER_ALL, NETVER_RESULT_SERVER_ALL, FALSE);
 
    BOOL bResult = m_pServerSocket->InitNetwork(ServerMode, nClientCount, NETPORT_RESULT_SERVER_ALL);
 
    return bResult;
}
 
void CResultServerControl::DeinitResultServer()
{
    if (m_pServerSocket)
    {
        m_pServerSocket->DeinitNetwork();
        delete m_pServerSocket;
    }
    m_pServerSocket = NULL;    
}
 
void CResultServerControl::IOCPNet2P_Connected(int nType)
{
    g_pLog->DisplayMessage(_T("ResultServer Client Connect! [%d]"), nType);
}
 
void CResultServerControl::IOCPNet2P_Disconnected(int nType, int nModuleNo)
{
    g_pLog->DisplayMessage(_T("ResultServer Client Disconnected! [%d, %d]"), nType, nModuleNo);
}
 
BOOL CResultServerControl::IOCPNet2P_Received(int Type, CNetPacket* pPacket, __int64 nContext)
{
    if(!pPacket) return FALSE;
 
    if (Type!=Socket_All_Client) return FALSE;
 
    CNetJoiner* pNetJoiner = NULL;
    
    switch(pPacket->GetPacketCode())
    {
    case CR_MODULE_INDEX:
        g_pLog->DisplayMessage(_T("[%d]NetIOCP2P_Received CA_MODULE_INDEX"), pPacket->GetModuleNo());
        for(int i = 0; i < m_pServerSocket->GetClientCount(); i++)
        {
            pNetJoiner = m_pServerSocket->GetJoinerArray(i);
            if (pNetJoiner && reinterpret_cast<int>(pNetJoiner->GetSocketContext()) == nContext)
            {
                pNetJoiner->SetModuleNo(pPacket->GetModuleNo(), FALSE);
                m_pServerSocket->SendToClient(i, RC_MODULE_INDEX, NET_RESULT_SUCCESS);
            }
        }
        break;
 
    case CR_RESULT_INFO:
        g_pLog->DisplayMessage(_T("[%d]NetIOCP2P_Received CR_RESULT_INFO"), pPacket->GetModuleNo());
        break;
 
    default:
        break;
    }
    
    return TRUE;
}
 
BOOL CResultServerControl::SendReviewResult(int nModuleIdx, int nResultIdx, const SReviewResult* pReviewResult)
{
    if (m_pServerSocket==NULL || pReviewResult==NULL) return FALSE;
    
    CNetPacket *pSendPacket = m_pServerSocket->GetPacket();
    if (pSendPacket)
    {
        // set result packet
        int nResultCode                = 0;                        // result code
        int nModuleIndex            = nModuleIdx;                // module index
        int nTotalGlassResultCount    = 0;                // total glass result count
        int nCurGlassResultCount    = 0;                // current glass result count
        int nTotalModuleResultCount = 0;            // total module result count
        int nCurModuleResultCount    = nResultIdx;        // current module result count
        CString strImagePath        = _T("");
        strImagePath.Format(_T("%s"), pReviewResult->strUploadImgFileName);
 
        pSendPacket->SetInt(nResultCode);                
        pSendPacket->SetInt(nModuleIndex);
        pSendPacket->SetInt(nTotalGlassResultCount);
        pSendPacket->SetInt(nCurGlassResultCount);
        pSendPacket->SetInt(nTotalModuleResultCount);
        pSendPacket->SetInt(nCurModuleResultCount);
        pSendPacket->SetString(strImagePath);
 
        return m_pServerSocket->InvokeToClient(RC_RESULT_INFO, NET_RESULT_SUCCESS, pSendPacket);
    }
 
    return m_pServerSocket->InvokeToClient(RC_RESULT_INFO, NET_RESULT_FAIL);
}