2024-04-23 09:50:11 +00:00
|
|
|
#include "base/HGDef.h"
|
2022-05-18 03:30:13 +00:00
|
|
|
#include "base/HGInc.h"
|
2022-09-23 09:53:00 +00:00
|
|
|
#include "base/HGCrash.h"
|
2022-05-18 03:30:13 +00:00
|
|
|
#include "base/HGThread.h"
|
2022-05-21 06:34:02 +00:00
|
|
|
#include "base/HGUtility.h"
|
2022-05-30 11:01:23 +00:00
|
|
|
#include "base/HGIni.h"
|
2022-05-21 10:09:34 +00:00
|
|
|
#include "base/HGMsgPump.h"
|
2022-05-23 10:29:23 +00:00
|
|
|
#include "ManagerV1.h"
|
|
|
|
#include "ManagerV2.h"
|
2022-05-23 02:35:42 +00:00
|
|
|
#include "HttpServer.h"
|
|
|
|
#include "SockIoServer.h"
|
|
|
|
#include "WSServer.h"
|
|
|
|
#include "MsgPumpCallback.h"
|
2022-07-02 02:40:30 +00:00
|
|
|
#include "curl/curl.h"
|
2022-05-03 10:25:52 +00:00
|
|
|
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGMsgPump msgPumpV1 = NULL;
|
2024-04-19 03:40:33 +00:00
|
|
|
HGMsgPump msgPumpV2 = NULL;
|
|
|
|
|
2022-10-12 03:35:09 +00:00
|
|
|
static void HGAPI CrashFunc(HGPointer crashAddr, HGPointer param)
|
2022-09-23 09:53:00 +00:00
|
|
|
{
|
|
|
|
HGChar logPath[256];
|
|
|
|
HGBase_GetLogFilePath(logPath, 256);
|
|
|
|
strcat(logPath, "crash.dmp");
|
|
|
|
HGBase_MakeCrashFile(logPath);
|
|
|
|
}
|
|
|
|
|
2024-04-07 07:28:56 +00:00
|
|
|
static void HGAPI ThreadFuncV1(HGThread thread, HGPointer param)
|
|
|
|
{
|
|
|
|
(void)thread;
|
|
|
|
HGMsgPump msgPump = (HGMsgPump)param;
|
|
|
|
|
|
|
|
HGChar cfgPath[256];
|
|
|
|
HGBase_GetConfigPath(cfgPath, 256);
|
|
|
|
HGChar cfgName[256];
|
|
|
|
sprintf(cfgName, "%s%s", cfgPath, "config.ini");
|
|
|
|
|
|
|
|
ver_1::ManagerV1 manager(msgPump);
|
|
|
|
ver_1::HttpServer httpServer(msgPump, &manager);
|
|
|
|
ver_1::SockIoServer sockIoServer(msgPump, &manager);
|
|
|
|
|
|
|
|
if (httpServer.Open(18999))
|
|
|
|
{
|
|
|
|
if (sockIoServer.Open(28999))
|
|
|
|
{
|
|
|
|
HGBase_RunMsgPump(msgPump, ver_1::HGMsgPumpCallback, NULL);
|
|
|
|
sockIoServer.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
httpServer.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HGAPI ThreadFuncV2(HGThread thread, HGPointer param)
|
2022-05-03 10:25:52 +00:00
|
|
|
{
|
|
|
|
(void)thread;
|
2022-05-21 10:09:34 +00:00
|
|
|
HGMsgPump msgPump = (HGMsgPump)param;
|
2022-05-03 10:25:52 +00:00
|
|
|
|
2022-05-21 06:34:02 +00:00
|
|
|
HGChar cfgPath[256];
|
|
|
|
HGBase_GetConfigPath(cfgPath, 256);
|
2022-06-10 06:33:16 +00:00
|
|
|
HGChar cfgName[256];
|
2024-04-07 07:28:56 +00:00
|
|
|
sprintf(cfgName, "%s%s", cfgPath, "config2.ini");
|
|
|
|
|
|
|
|
ver_2::ManagerV2 manager(msgPump);
|
|
|
|
ver_2::WSServer wsServer(msgPump, &manager);
|
|
|
|
|
|
|
|
HGInt port = 38999;
|
|
|
|
HGBase_GetProfileInt(cfgName, "connect", "port", 38999, &port);
|
|
|
|
if (wsServer.Open(port))
|
|
|
|
{
|
|
|
|
HGBase_RunMsgPump(msgPump, ver_2::HGMsgPumpCallback, NULL);
|
|
|
|
wsServer.Close();
|
|
|
|
}
|
2022-05-03 10:25:52 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 13:03:28 +00:00
|
|
|
|
2022-05-03 10:25:52 +00:00
|
|
|
#if defined(HG_CMP_MSC)
|
2024-04-19 03:40:33 +00:00
|
|
|
|
2024-04-23 09:50:11 +00:00
|
|
|
#ifndef _DEBUG
|
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
#define SERVICE_NAME TEXT("HWWebService")
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
#define SERVICE_NAME TEXT("LSCWebService")
|
|
|
|
#elif defined(OEM_CANGTIAN)
|
|
|
|
#define SERVICE_NAME TEXT("CTSWebService")
|
|
|
|
#elif defined(OEM_ZHONGJING)
|
|
|
|
#define SERVICE_NAME TEXT("ZJWebService")
|
|
|
|
#elif defined(OEM_ZIGUANG)
|
|
|
|
#define SERVICE_NAME TEXT("ZGWebService")
|
|
|
|
#elif defined(OEM_NEUTRAL)
|
|
|
|
#define SERVICE_NAME TEXT("NEUWebService")
|
|
|
|
#elif defined(OEM_DELI)
|
|
|
|
#define SERVICE_NAME TEXT("DLWebService")
|
2022-05-03 10:25:52 +00:00
|
|
|
#else
|
2024-04-19 03:40:33 +00:00
|
|
|
#define SERVICE_NAME TEXT("HGWebService")
|
2022-05-03 10:25:52 +00:00
|
|
|
#endif
|
2024-04-19 03:40:33 +00:00
|
|
|
|
|
|
|
SERVICE_STATUS_HANDLE ServiceStatusHandle = NULL;
|
|
|
|
SERVICE_STATUS ServiceStatus = {0};
|
|
|
|
|
|
|
|
void WINAPI ServiceCtrlHandler(DWORD dwControl)
|
2022-05-03 10:25:52 +00:00
|
|
|
{
|
2024-04-19 03:40:33 +00:00
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_STOP: // 暂停控制
|
|
|
|
ServiceStatus.dwCurrentState = SERVICE_STOPPED;// 状态设置为停止
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGBase_ExitMsgPump(msgPumpV1);
|
2024-04-19 03:40:33 +00:00
|
|
|
HGBase_ExitMsgPump(msgPumpV2);
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:// 关机控制
|
|
|
|
ServiceStatus.dwCurrentState = SERVICE_STOPPED;// 状态设置为停止
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGBase_ExitMsgPump(msgPumpV1);
|
2024-04-19 03:40:33 +00:00
|
|
|
HGBase_ExitMsgPump(msgPumpV2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-09-23 09:53:00 +00:00
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
// 设置服务状态
|
|
|
|
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
|
|
|
}
|
2022-05-03 10:25:52 +00:00
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
void WINAPI ServiceMain(DWORD dwNumServicesArgs, LPTSTR* lpServiceArgVectors)
|
|
|
|
{
|
|
|
|
ServiceStatusHandle = RegisterServiceCtrlHandler(SERVICE_NAME, ServiceCtrlHandler);
|
|
|
|
if (NULL == ServiceStatusHandle)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceStatus.dwServiceType = SERVICE_WIN32;
|
|
|
|
ServiceStatus.dwCurrentState = SERVICE_START_PENDING; // 服务正在启动
|
|
|
|
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP; // 接受关机与暂停两种控制
|
|
|
|
ServiceStatus.dwWin32ExitCode = 0; // 下面四个默认都为0
|
|
|
|
ServiceStatus.dwServiceSpecificExitCode = 0;
|
|
|
|
ServiceStatus.dwCheckPoint = 0;
|
|
|
|
ServiceStatus.dwWaitHint = 0;
|
|
|
|
|
|
|
|
WSADATA ws = { 0 };
|
|
|
|
int ret = WSAStartup(MAKEWORD(2, 2), &ws);
|
|
|
|
assert(0 == ret);
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
2024-04-07 07:28:56 +00:00
|
|
|
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGBase_CreateMsgPump(&msgPumpV1);
|
|
|
|
//HGThread threadV1 = NULL;
|
|
|
|
//HGBase_OpenThread(ThreadFuncV1, msgPumpV1, &threadV1);
|
2024-04-07 07:28:56 +00:00
|
|
|
|
|
|
|
HGBase_CreateMsgPump(&msgPumpV2);
|
|
|
|
HGThread threadV2 = NULL;
|
|
|
|
HGBase_OpenThread(ThreadFuncV2, msgPumpV2, &threadV2);
|
2023-03-20 13:03:28 +00:00
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
ServiceStatus.dwCurrentState = SERVICE_RUNNING; // 成功运行则把状态设置为运行状态
|
|
|
|
SetServiceStatus(ServiceStatusHandle, &ServiceStatus);
|
2023-03-20 13:03:28 +00:00
|
|
|
|
2024-04-07 07:28:56 +00:00
|
|
|
HGBase_CloseThread(threadV2);
|
|
|
|
threadV2 = NULL;
|
|
|
|
HGBase_DestroyMsgPump(msgPumpV2);
|
|
|
|
msgPumpV2 = NULL;
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGBase_CloseThread(threadV1);
|
|
|
|
//threadV1 = NULL;
|
|
|
|
//HGBase_DestroyMsgPump(msgPumpV1);
|
|
|
|
//msgPumpV1 = NULL;
|
2024-04-07 07:28:56 +00:00
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
curl_global_cleanup();
|
|
|
|
WSACleanup();
|
|
|
|
}
|
2022-07-02 02:40:30 +00:00
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
HGBase_RegisterCrashFunc(CrashFunc, NULL);
|
|
|
|
|
|
|
|
TCHAR serviceName[128];
|
|
|
|
lstrcpy(serviceName, SERVICE_NAME);
|
|
|
|
|
|
|
|
SERVICE_TABLE_ENTRY tableEntry[2];
|
|
|
|
tableEntry[0].lpServiceName = serviceName; // 服务程序名称
|
|
|
|
tableEntry[0].lpServiceProc = ServiceMain; // 服务程序入口
|
|
|
|
tableEntry[1].lpServiceName = NULL;
|
|
|
|
tableEntry[1].lpServiceProc = NULL;
|
|
|
|
|
|
|
|
StartServiceCtrlDispatcher(tableEntry);
|
|
|
|
return 0;
|
2022-10-24 14:48:17 +00:00
|
|
|
}
|
2024-04-19 03:40:33 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2024-04-23 09:50:11 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
WSADATA ws = { 0 };
|
|
|
|
int ret = WSAStartup(MAKEWORD(2, 2), &ws);
|
|
|
|
assert(0 == ret);
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
|
|
|
//HGBase_CreateMsgPump(&msgPumpV1);
|
|
|
|
//HGThread threadV1 = NULL;
|
|
|
|
//HGBase_OpenThread(ThreadFuncV1, msgPumpV1, &threadV1);
|
|
|
|
|
|
|
|
HGBase_CreateMsgPump(&msgPumpV2);
|
|
|
|
HGThread threadV2 = NULL;
|
|
|
|
HGBase_OpenThread(ThreadFuncV2, msgPumpV2, &threadV2);
|
|
|
|
|
|
|
|
HGBase_CloseThread(threadV2);
|
|
|
|
threadV2 = NULL;
|
|
|
|
HGBase_DestroyMsgPump(msgPumpV2);
|
|
|
|
msgPumpV2 = NULL;
|
|
|
|
//HGBase_CloseThread(threadV1);
|
|
|
|
//threadV1 = NULL;
|
|
|
|
//HGBase_DestroyMsgPump(msgPumpV1);
|
|
|
|
//msgPumpV1 = NULL;
|
|
|
|
|
|
|
|
curl_global_cleanup();
|
|
|
|
WSACleanup();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2024-04-19 03:40:33 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
HGBase_RegisterCrashFunc(CrashFunc, NULL);
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGBase_CreateMsgPump(&msgPumpV1);
|
|
|
|
//HGThread threadV1 = NULL;
|
|
|
|
//HGBase_OpenThread(ThreadFuncV1, msgPumpV1, &threadV1);
|
2024-04-19 03:40:33 +00:00
|
|
|
|
|
|
|
HGBase_CreateMsgPump(&msgPumpV2);
|
|
|
|
HGThread threadV2 = NULL;
|
|
|
|
HGBase_OpenThread(ThreadFuncV2, msgPumpV2, &threadV2);
|
|
|
|
|
|
|
|
HGBase_CloseThread(threadV2);
|
|
|
|
threadV2 = NULL;
|
|
|
|
HGBase_DestroyMsgPump(msgPumpV2);
|
|
|
|
msgPumpV2 = NULL;
|
2024-04-23 09:50:11 +00:00
|
|
|
//HGBase_CloseThread(threadV1);
|
|
|
|
//threadV1 = NULL;
|
|
|
|
//HGBase_DestroyMsgPump(msgPumpV1);
|
|
|
|
//msgPumpV1 = NULL;
|
2024-04-19 03:40:33 +00:00
|
|
|
|
|
|
|
curl_global_cleanup();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|