修改websdk,同时支持新版和旧版接口

This commit is contained in:
luoliangyi 2024-04-07 15:28:56 +08:00
parent 1a9a1cabcc
commit 73f6dbc9f3
1 changed files with 56 additions and 42 deletions

View File

@ -21,20 +21,16 @@ static void HGAPI CrashFunc(HGPointer crashAddr, HGPointer param)
HGBase_MakeCrashFile(logPath);
}
static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
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");
HGInt verNum = 2;
HGBase_GetProfileInt(cfgName, "version", "verNum", 2, &verNum);
if (1 == verNum) // 使用V1版本接口
{
ver_1::ManagerV1 manager(msgPump);
ver_1::HttpServer httpServer(msgPump, &manager);
ver_1::SockIoServer sockIoServer(msgPump, &manager);
@ -50,12 +46,20 @@ static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
httpServer.Close();
}
}
else // 使用V2版本接口
static void HGAPI ThreadFuncV2(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, "config2.ini");
ver_2::ManagerV2 manager(msgPump);
ver_2::WSServer wsServer(msgPump, &manager);
sprintf(cfgName, "%s%s", cfgPath, "config2.ini");
HGInt port = 38999;
HGBase_GetProfileInt(cfgName, "connect", "port", 38999, &port);
if (wsServer.Open(port))
@ -64,7 +68,6 @@ static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
wsServer.Close();
}
}
}
#if defined(HG_CMP_MSC)
#include <shellapi.h>
@ -114,10 +117,16 @@ int main()
#endif
curl_global_init(CURL_GLOBAL_ALL);
HGMsgPump msgPump = NULL;
HGBase_CreateMsgPump(&msgPump);
HGThread thread = NULL;
HGBase_OpenThread(ThreadFunc, msgPump, &thread);
HGMsgPump msgPumpV1 = NULL;
HGBase_CreateMsgPump(&msgPumpV1);
HGThread threadV1 = NULL;
HGBase_OpenThread(ThreadFuncV1, msgPumpV1, &threadV1);
HGMsgPump msgPumpV2 = NULL;
HGBase_CreateMsgPump(&msgPumpV2);
HGThread threadV2 = NULL;
HGBase_OpenThread(ThreadFuncV2, msgPumpV2, &threadV2);
#if defined(HG_CMP_MSC)
WNDCLASSA wc = { 0 };
@ -157,10 +166,15 @@ int main()
}
#endif
HGBase_CloseThread(thread);
thread = NULL;
HGBase_DestroyMsgPump(msgPump);
msgPump = NULL;
HGBase_CloseThread(threadV2);
threadV2 = NULL;
HGBase_DestroyMsgPump(msgPumpV2);
msgPumpV2 = NULL;
HGBase_CloseThread(threadV1);
threadV1 = NULL;
HGBase_DestroyMsgPump(msgPumpV1);
msgPumpV1 = NULL;
curl_global_cleanup();
#if defined(HG_CMP_MSC)