diff --git a/CHANGELOG b/CHANGELOG index 21ee499ccb2c680b26e0a82f897885ab59b8770f..8ee564775e12c86e111bd1d61c7488b1f02c2200 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,25 @@ +XEngine_APIService V3.0.0.1001 + +增加:系统API函数模块 +增加:进程守护功能和接口支持 +增加:启动隐藏窗口和自动启动的功能选项 +增加:对本地屏幕和声音录像推流的支持 +增加:停止推流协议 +增加:权限提示 +修改:初始化配置不在需要配置结构参数 +修改:启动失败不在直接退出 +修正:后台服务协议没有HTTP返回请求的问题 + +added:system api module +added:deamon process and http api interface for process deamon +added:hide windows when start and auto start option +added:screen and sound push stream +added:stop stream record protocol +added:permission handle +modify:init configure does not need configure parament +modify:does not directly exit when configure init failed. +fixed:does not http response for backservice +====================================================================================== XEngine_APIService V2.11.0.1001 增加:用户验证功能 diff --git a/COPYRIGHT b/COPYRIGHT index 468d10b9673598e8b6fb9a5600a55322a1645f6f..22854f532d82acd97b5c8f565da8a36397eb6253 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -2,6 +2,9 @@ XEngine:https://gitee.com/xyry/libxengine or https://github.com/libxengine/xengine jsoncpp:https://github.com/open-source-parsers/jsoncpp opencc:https://github.com/BYVoid/OpenCC +opencv:https://github.com/opencv/opencv +libqrencode:https://github.com/fukuchi/libqrencode +lua:https://github.com/lua/lua data sources: IP:https://github.com/lionsoul2014/ip2region diff --git a/README.en.md b/README.en.md index b703219dc8ffd35ec9dab9255cad2ec4e3ab1319..8eb90809ca0dd1b3e372afccc591bc6ff8a9e2d8 100644 --- a/README.en.md +++ b/README.en.md @@ -7,6 +7,7 @@ As long as the repository is not in suspended state, we will maintain and develo c c++ 接口服务器 c c++ interface api service This is an api interface for information query service,At present, the information search service on the market need to charge, and our information search service is free and open source. +Not only is it a query service, but it can also provide functions such as machine management and process deamon. This service mainly uses HTTP/V1.1 to implement various interface services This is a general information query service that does not contain any language attributes You can use this code to implement your own information query service, which supports querying any information @@ -48,6 +49,7 @@ Support privatization deployment, free, safe, open source, controllable 28. Sensitive word detection 29. remote control(back management) 30. Image Process +31. process deamon ## install @@ -67,7 +69,7 @@ MYSQL database version 8.0 or above is required. Create a table through CreateDa Modify the database configuration in XSQL in the configuration file to your #### Windows -need to vcpkg configure third-part env.refer vcpkg install guide.after installed and execution:vcpkg.exe install lua lua:x64-windows opencc opencc:x64-windows opencv[contrib] libqrencode opencv[contrib]:x64-windows libqrencode:x64-windows +need to vcpkg configure third-part env.refer vcpkg install guide.after installed and execution:vcpkg.exe install lua:x84-windows lua:x64-windows opencc:x84-windows opencc:x64-windows opencv[contrib]:x84-windows libqrencode:x84-windows opencv[contrib]:x64-windows libqrencode:x64-windows use vs open and compile,suport windows 7sp1 and above Just Run it diff --git a/README.md b/README.md index fa361ea8f44d1c0928b62ae73b5b68c3f14287cd..e89d31c7625d3129dad5ec40a6c0a8174abecdfd 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ c c++ 接口服务器 c c++ interface api service 这是一个信息查询的API接口服务,目前市面上的信息查询服务都需要收费,而我们这个信息查询服务属于免费开源的. +或者说他不光是一个查询服务,他还可以提供机器管理进程守护等功能 这个服务主要使用HTTP/V1.1实现各种接口服务. 这是一个不包含任何语言属性的通用信息查询服务. 你可以使用此代码实现自己的信息查询服务,支持查询任何信息 @@ -47,6 +48,7 @@ c c++ interface api service 28. 敏感词检测 29. 远程控制(后台管理) 30. 图像处理 +31. 进程守护 ## 安装教程 @@ -66,7 +68,7 @@ macos执行:./XEngine_LINEnv.sh -i 3 修改配置文件里面XSQL里面的数据库配置为你的 #### Windows -需要vcpkg配置第三方环境,具体参考vcpkg安装方式,安装好后执行:vcpkg.exe install lua lua:x64-windows opencc opencc:x64-windows opencv[contrib] libqrencode opencv[contrib]:x64-windows libqrencode:x64-windows +需要vcpkg配置第三方环境,具体参考vcpkg安装方式,安装好后执行:vcpkg.exe install lua:x84-windows lua:x64-windows opencc:x84-windows opencc:x64-windows opencv[contrib]:x84-windows libqrencode:x84-windows opencv[contrib]:x64-windows libqrencode:x64-windows 使用VS打开并且编译,支持WINDOWS 7SP1以上系统 直接运行即可 diff --git a/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.cpp b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.cpp new file mode 100644 index 0000000000000000000000000000000000000000..818ab6a29dc2fda559f8d901a338fa1986499a69 --- /dev/null +++ b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.cpp @@ -0,0 +1,64 @@ +#ifdef _MSC_BUILD +#include +#include +#pragma comment(lib,"Ws2_32") +#pragma comment(lib,"jsoncpp") +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient") +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//需要优先配置XEngine +//WINDOWS支持VS2022 x64 debug 编译调试 +//linux::g++ -std=c++17 -Wall -g APPClient_DeamonExample.cpp -o APPClient_DeamonExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIClient -ljsoncpp +//macos::g++ -std=c++17 -Wall -g APPClient_DeamonExample.cpp -o APPClient_DeamonExample.exe -lXEngine_BaseLib -lNetHelp_APIClient -ljsoncpp + + +int test_insert() +{ + int nCode = 0; + int nLen = 0; + LPCXSTR lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=deamon"); + XCHAR* ptszMsgBuffer = NULL; + + Json::Value st_JsonRoot; + st_JsonRoot["bEnable"] = true; + st_JsonRoot["nRetime"] = 3; + st_JsonRoot["tszAPPName"] = "1.exe"; + st_JsonRoot["tszAPPPath"] = "D:\\path\\"; + + if (!APIClient_Http_Request(_X("POST"), lpszAPIUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen)) + { + printf("发送投递失败!\n"); + return 0; + } + printf("接受到数据,大小:%d,内容:%s\n", nLen, ptszMsgBuffer); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + + return 0; +} + +int main() +{ +#ifdef _MSC_BUILD + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + test_insert(); + +#ifdef _MSC_BUILD + WSACleanup(); +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..da4b12f408836c046bfac9e8e4c3c193c33a358a --- /dev/null +++ b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {5d064fef-9b83-493a-b891-12e56b1b4c65} + APPClientDeamonExample + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib64);../../XEngine_Source/x64/Debug;$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj.filters b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..cc7778ce272737d846cf2fdd39013b8666a3acfa --- /dev/null +++ b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj.user b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_APPClient/APPClient_DeamonExample/APPClient_DeamonExample.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/XEngine_APPClient.sln b/XEngine_APPClient/XEngine_APPClient.sln index 87ee6b55e11d99e73280ea8e751db9a2493b56fc..dc1cce8fa743cf2f4ec93c8cc61081ff1bae036f 100644 --- a/XEngine_APPClient/XEngine_APPClient.sln +++ b/XEngine_APPClient/XEngine_APPClient.sln @@ -41,6 +41,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_ImageExample", "A EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_BackExample", "APPClient_BackExample\APPClient_BackExample.vcxproj", "{384BF475-8401-4ABD-8510-788592511FC1}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_DeamonExample", "APPClient_DeamonExample\APPClient_DeamonExample.vcxproj", "{5D064FEF-9B83-493A-B891-12E56B1B4C65}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -201,6 +203,14 @@ Global {384BF475-8401-4ABD-8510-788592511FC1}.Release|x64.Build.0 = Release|x64 {384BF475-8401-4ABD-8510-788592511FC1}.Release|x86.ActiveCfg = Release|Win32 {384BF475-8401-4ABD-8510-788592511FC1}.Release|x86.Build.0 = Release|Win32 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Debug|x64.ActiveCfg = Debug|x64 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Debug|x64.Build.0 = Debug|x64 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Debug|x86.ActiveCfg = Debug|Win32 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Debug|x86.Build.0 = Debug|Win32 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Release|x64.ActiveCfg = Release|x64 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Release|x64.Build.0 = Release|x64 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Release|x86.ActiveCfg = Release|Win32 + {5D064FEF-9B83-493A-B891-12E56B1B4C65}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 908b5217c9a03bb676625dff5bd47ae075fcb2fb..59c20101de29fe1b60f1df0078cc6099aae144f3 100644 Binary files a/XEngine_Docment/Docment_en.docx and b/XEngine_Docment/Docment_en.docx differ diff --git a/XEngine_Docment/Docment_zh.docx b/XEngine_Docment/Docment_zh.docx index c5a52ff44f5e7f156daee0e6a244a54f5aedd2b1..4872b5a3925d6be21a9ca83c201bdad0b16d63a1 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index c7a89c3143fac92fe3188cf49226d2aeeeb3bc02..502cb6b429331cc8364a94a234da48973bb4ada6 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -1,6 +1,8 @@ { "tszIPAddr":"192.168.1.8", - "bDeamon":0, + "bDeamon":false, + "bAutoStart":false, + "bHideWnd":false, "nHttpPort":5501, "XMax":{ "nMaxClient":10000, @@ -11,7 +13,8 @@ "XTime":{ "nTimeCheck":3, "nHttpTimeOut":5, - "nP2PTimeOut":60 + "nP2PTimeOut":60, + "nDeamonTime":3 }, "XLog":{ "MaxSize":1024000, @@ -43,10 +46,12 @@ }, "XVerification":{ "bBackService":false, + "bDeamon":false, "tszUserName":"xyry", "tszUserPass":"11" }, "XVer":[ + "3.0.0.1001 Build20230908", "2.11.0.1001 Build20230829", "2.10.0.1001 Build20230810", "2.9.0.1001 Build20230421", diff --git a/XEngine_Release/XEngine_Config/XEngine_DeamonConfig.json b/XEngine_Release/XEngine_Config/XEngine_DeamonConfig.json new file mode 100644 index 0000000000000000000000000000000000000000..04a0f2a946c4c320adbb91cfa82990b669a082dd --- /dev/null +++ b/XEngine_Release/XEngine_Config/XEngine_DeamonConfig.json @@ -0,0 +1,16 @@ +{ + "ListArray":[ + { + "bEnable":false, + "tszAPPName":"RadarVision_APPExample.exe", + "tszAPPPath":"D:\\radar-vision\\RV_Sdk\\RVRelease\\", + "nAPPReTime":5 + }, + { + "bEnable":false, + "tszAPPName":"ifconfig", + "tszAPPPath":"/usr/sbin/", + "nAPPReTime":0 + } + ] +} \ No newline at end of file diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index 9306b15dbd26f0ac24d2d3b78e0a8cf050404678..ee40b2b195ff0240057e59723ec6f2b168373879 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -9,6 +9,7 @@ THIRDPART_MODULE_JSONCPP = ./XEngine_ThirdPart/jsoncpp MODULE_CONFIGURE_PATH = ./XEngine_ModuleConfigure MODULE_DATABASE_PATH = ./XEngine_ModuleDatabase MODULE_PROTOCOL_PATH = ./XEngine_ModuleProtocol +MODULE_SYSTEM_PATH = ./XEngine_ModuleSystem MODULE_HELP_PATH = ./XEngine_ModuleHelp MODULE_PLUGIN_PATH = ./XEngine_ModulePlugin @@ -24,7 +25,7 @@ APP_CENTER_PATH = ./XEngine_ServiceApp/XEngine_CenterApp APP_HTTP_PATH = ./XEngine_ServiceApp/XEngine_HttpApp XENGINE_MODULES = libjsoncpp.so \ - libXEngine_ModuleConfigure.so libXEngine_ModuleDatabase.so libXEngine_ModuleProtocol.so libXEngine_ModuleHelp.so libXEngine_ModulePlugin.so \ + libXEngine_ModuleConfigure.so libXEngine_ModuleDatabase.so libXEngine_ModuleProtocol.so libXEngine_ModuleSystem.so libXEngine_ModuleHelp.so libXEngine_ModulePlugin.so \ libModulePlugin_Zodiac.so libModulePlugin_Password.so libModulePlugin_Timezone.so libModulePlugin_BMIndex.so libModulePlugin_Meter.so libModulePlugin_Phone.so libModulePlugin_IPAddr.so \ XEngine_HttpApp.exe @@ -40,6 +41,8 @@ libXEngine_ModuleDatabase.so: make -C $(MODULE_DATABASE_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libXEngine_ModuleProtocol.so: make -C $(MODULE_PROTOCOL_PATH) PLATFORM=$(PLATFORM) $(FLAGS) +libXEngine_ModuleSystem.so: + make -C $(MODULE_SYSTEM_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libXEngine_ModuleHelp.so: make -C $(MODULE_HELP_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libXEngine_ModulePlugin.so: diff --git a/XEngine_Source/VSCopy-Debug.bat b/XEngine_Source/VSCopy-Debug.bat index 1993acc84298b118c04b6a1102bf4cc8e5966e2e..c8a3fee0d2211fca5a87685d50eda959c6c935e1 100644 --- a/XEngine_Source/VSCopy-Debug.bat +++ b/XEngine_Source/VSCopy-Debug.bat @@ -16,6 +16,11 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_Authorize.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_HttpProtocol.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_AVHelp.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_VideoCodec.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_AudioCodec.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_AVCollect.dll" "./" + +copy /y "D:\XEngine\XEngine_SourceCode\Debug\StreamMedia_StreamClient.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\AVCodec\avcodec-59.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\AVCodec\avdevice-59.dll" "./" diff --git a/XEngine_Source/VSCopy-x64.bat b/XEngine_Source/VSCopy-x64.bat index 9f2eb3ea430373fc8ce28d4bf7465289a8329d96..5e11a8882adf56bb8e41de2b9adcac1129f1d2ed 100644 --- a/XEngine_Source/VSCopy-x64.bat +++ b/XEngine_Source/VSCopy-x64.bat @@ -16,6 +16,11 @@ copy /y "%XEngine_Lib64%\XEngine_HelpComponents\HelpComponents_Authorize.dll" ". copy /y "%XEngine_Lib64%\XEngine_RfcComponents\RfcComponents_HttpProtocol.dll" "./" copy /y "%XEngine_Lib64%\XEngine_AVCodec\XEngine_AVHelp.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_AVCodec\XEngine_VideoCodec.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_AVCodec\XEngine_AudioCodec.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_AVCodec\XEngine_AVCollect.dll" "./" + +copy /y "%XEngine_Lib64%\XEngine_StreamMedia\StreamMedia_StreamClient.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\bson-1.0.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\mongoc-1.0.dll" "./" diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy-x86.bat index 4813b5384184a694b50c8308a6c9f86ef3a95b1f..f7951cfe01d6ec48721ce627c4da2eebaaf19d74 100644 --- a/XEngine_Source/VSCopy-x86.bat +++ b/XEngine_Source/VSCopy-x86.bat @@ -16,6 +16,11 @@ copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_Authorize.dll" ". copy /y "%XEngine_Lib32%\XEngine_RfcComponents\RfcComponents_HttpProtocol.dll" "./" copy /y "%XEngine_Lib32%\XEngine_AVCodec\XEngine_AVHelp.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_AVCodec\XEngine_VideoCodec.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_AVCodec\XEngine_AudioCodec.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_AVCodec\XEngine_AVCollect.dll" "./" + +copy /y "%XEngine_Lib32%\XEngine_StreamMedia\StreamMedia_StreamClient.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\bson-1.0.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\mongoc-1.0.dll" "./" @@ -23,7 +28,6 @@ copy /y "%XEngine_Lib32%\XEngine_HelpComponents\libmariadb.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\libpq.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\sqlite3.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\zlib1.dll" "./" -copy /y "%XEngine_Lib32%\XEngine_HelpComponents\plugin\caching_sha2_password.dll" "./" copy /y "%XEngine_Lib32%\XEngine_NetHelp\libcurl.dll" "./" copy /y "%XEngine_Lib32%\XEngine_NetHelp\nghttp2.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\libcrypto-3.dll" "./" diff --git a/XEngine_Source/XEngine.sln b/XEngine_Source/XEngine.sln index a4d03990a212cf0ae96e5647b8ebea446532650f..7b6496aeeab08b669cb92b9bc6cafd6d8c0fef70 100644 --- a/XEngine_Source/XEngine.sln +++ b/XEngine_Source/XEngine.sln @@ -42,6 +42,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libModulePlugin_Phone", "XE EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libModulePlugin_IPAddr", "XEngine_PluginModule\ModulePlugin_IPAddr\ModulePlugin_IPAddr.vcxproj", "{D549160C-CC16-47F8-8345-1F4CF7A25CA2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ModuleSystem", "XEngine_ModuleSystem\XEngine_ModuleSystem.vcxproj", "{92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -162,6 +164,14 @@ Global {D549160C-CC16-47F8-8345-1F4CF7A25CA2}.Release|x64.Build.0 = Release|x64 {D549160C-CC16-47F8-8345-1F4CF7A25CA2}.Release|x86.ActiveCfg = Release|Win32 {D549160C-CC16-47F8-8345-1F4CF7A25CA2}.Release|x86.Build.0 = Release|Win32 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Debug|x64.ActiveCfg = Debug|x64 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Debug|x64.Build.0 = Debug|x64 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Debug|x86.ActiveCfg = Debug|Win32 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Debug|x86.Build.0 = Debug|Win32 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Release|x64.ActiveCfg = Release|x64 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Release|x64.Build.0 = Release|x64 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Release|x86.ActiveCfg = Release|Win32 + {92F971AB-CAC9-4D9B-A9CA-AFD9CA17E505}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h index cb53d3a823c07b45b9f9a847faafd3971816c0ff..7a929cbb19784009483063557ecca24614143afb 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -17,6 +17,8 @@ typedef struct { XCHAR tszIPAddr[128]; //本机IP地址,根据需要配置 bool bDeamon; //是否以守护进程启动,LINUX有效 + bool bAutoStart; //是否自动启动 + bool bHideWnd; //是否隐藏窗口启动 int nHttpPort; //HTTP服务端口 struct { @@ -30,6 +32,7 @@ typedef struct int nTimeCheck; //检测次数 int nHTTPTimeOut; //HTTP超时时间 int nP2PTimeOut; //P2P客户端超时时间 + int nDeamonTime; //进程守护失败执行次数 }st_XTime; //次数*时间=超时 struct { @@ -74,6 +77,7 @@ typedef struct struct { bool bBackService; + bool bDeamon; XCHAR tszUserName[MAX_PATH]; XCHAR tszUserPass[MAX_PATH]; }st_XVerifcation; @@ -132,6 +136,22 @@ typedef struct list stl_ListBase; }XENGINE_OPTIONLIST; ////////////////////////////////////////////////////////////////////////// +//用户进程列表 +typedef struct +{ + bool bEnable; //是否启用 + XCHAR tszAPPName[MAX_PATH]; //应用程序名称 + XCHAR tszAPPPath[MAX_PATH]; //应用程序路径 + int nReTime; //是否自动重启 + //自定义 + int nErrorTime; + __int64x nStartTime; +}XENGINE_DEAMONAPPINFO; +typedef struct +{ + list stl_ListDeamonApp; +}XENGINE_DEAMONAPPLIST; +////////////////////////////////////////////////////////////////////////// // 导出函数定义 ////////////////////////////////////////////////////////////////////////// extern "C" XLONG ModuleConfigure_GetLastError(int* pInt_ErrorCode = NULL); @@ -213,4 +233,23 @@ extern "C" bool ModuleConfigure_Json_QRCodeFile(LPCXSTR lpszConfigFile, XENGINE_ 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleConfigure_Json_PluginFile(LPCXSTR lpszConfigFile, XENGINE_PLUGINCONFIG* pSt_PluginConfig); \ No newline at end of file +extern "C" bool ModuleConfigure_Json_PluginFile(LPCXSTR lpszConfigFile, XENGINE_PLUGINCONFIG* pSt_PluginConfig); +/******************************************************************** +函数名称:ModuleConfigure_Json_DeamonList +函数功能:读取JSON配置文件 + 参数.一:lpszConfigFile + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要读取的配置文件 + 参数.二:pSt_AppConfig + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出守护进程列表 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleConfigure_Json_DeamonList(LPCXSTR lpszConfigFile, XENGINE_DEAMONAPPLIST* pSt_AppConfig); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp index 3fb49711653875f8bf8062975343f3e62f657a18..a97cda2c068b2057adfa87ad917682c726ce82ed 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -82,7 +82,9 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE return false; } _tcsxcpy(pSt_ServerConfig->tszIPAddr, st_JsonRoot["tszIPAddr"].asCString()); - pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asInt(); + pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asBool(); + pSt_ServerConfig->bAutoStart = st_JsonRoot["bAutoStart"].asBool(); + pSt_ServerConfig->bHideWnd = st_JsonRoot["bHideWnd"].asBool(); pSt_ServerConfig->nHttpPort = st_JsonRoot["nHttpPort"].asInt(); if (st_JsonRoot["XMax"].empty() || (4 != st_JsonRoot["XMax"].size())) @@ -97,7 +99,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XMax.nIOThread = st_JsonXMax["nIOThread"].asInt(); pSt_ServerConfig->st_XMax.nHTTPThread = st_JsonXMax["nHttpThread"].asInt(); - if (st_JsonRoot["XTime"].empty() || (3 != st_JsonRoot["XTime"].size())) + if (st_JsonRoot["XTime"].empty() || (4 != st_JsonRoot["XTime"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XTIME; @@ -107,6 +109,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XTime.nTimeCheck = st_JsonXTime["nTimeCheck"].asInt(); pSt_ServerConfig->st_XTime.nHTTPTimeOut = st_JsonXTime["nHttpTimeOut"].asInt(); pSt_ServerConfig->st_XTime.nP2PTimeOut = st_JsonXTime["nP2PTimeOut"].asInt(); + pSt_ServerConfig->st_XTime.nDeamonTime = st_JsonXTime["nDeamonTime"].asInt(); if (st_JsonRoot["XLog"].empty() || (3 != st_JsonRoot["XLog"].size())) { @@ -172,7 +175,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE _tcsxcpy(pSt_ServerConfig->st_XShortLink.tszHostUrl, st_JsonXShort["tszHostUrl"].asCString()); pSt_ServerConfig->st_XShortLink.nHTTPCode = st_JsonXShort["nHTTPCode"].asInt(); - if (st_JsonRoot["XVerification"].empty() || (3 != st_JsonRoot["XVerification"].size())) + if (st_JsonRoot["XVerification"].empty() || (4 != st_JsonRoot["XVerification"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XVERICATION; @@ -182,6 +185,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE _tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszUserName, st_JsonXVerifcation["tszUserName"].asCString()); _tcsxcpy(pSt_ServerConfig->st_XVerifcation.tszUserPass, st_JsonXVerifcation["tszUserPass"].asCString()); pSt_ServerConfig->st_XVerifcation.bBackService = st_JsonXVerifcation["bBackService"].asBool(); + pSt_ServerConfig->st_XVerifcation.bDeamon = st_JsonXVerifcation["bDeamon"].asBool(); if (st_JsonRoot["XVer"].empty()) { @@ -435,4 +439,79 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_PluginFile(LPCXSTR lpszConfigFi pSt_PluginConfig->pStl_ListPlugin->push_back(st_PluginInfo); } return true; +} +/******************************************************************** +函数名称:ModuleConfigure_Json_DeamonList +函数功能:读取JSON配置文件 + 参数.一:lpszConfigFile + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要读取的配置文件 + 参数.二:pSt_AppConfig + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出守护进程列表 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleConfigure_Json::ModuleConfigure_Json_DeamonList(LPCXSTR lpszConfigFile, XENGINE_DEAMONAPPLIST* pSt_AppConfig) +{ + Config_IsErrorOccur = false; + + if ((NULL == lpszConfigFile) || (NULL == pSt_AppConfig)) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT; + return false; + } + JSONCPP_STRING st_JsonError; + Json::Value st_JsonRoot; + Json::CharReaderBuilder st_JsonBuilder; + + FILE* pSt_File = fopen(lpszConfigFile, "rb"); + if (NULL == pSt_File) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE; + return false; + } + int nCount = 0; + XCHAR tszMsgBuffer[4096]; + while (1) + { + int nRet = fread(tszMsgBuffer + nCount, 1, 2048, pSt_File); + if (nRet <= 0) + { + break; + } + nCount += nRet; + } + fclose(pSt_File); + + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); + if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nCount, &st_JsonRoot, &st_JsonError)) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE; + return false; + } + + Json::Value st_JsonArray = st_JsonRoot["ListArray"]; + for (unsigned int i = 0; i < st_JsonRoot["ListArray"].size(); i++) + { + XENGINE_DEAMONAPPINFO st_APPInfo; + memset(&st_APPInfo, '\0', sizeof(XENGINE_DEAMONAPPINFO)); + + strcpy(st_APPInfo.tszAPPName, st_JsonArray[i]["tszAPPName"].asCString()); + strcpy(st_APPInfo.tszAPPPath, st_JsonArray[i]["tszAPPPath"].asCString()); + st_APPInfo.bEnable = st_JsonArray[i]["bEnable"].asBool(); + st_APPInfo.nReTime = st_JsonArray[i]["nAPPReTime"].asInt(); + + pSt_AppConfig->stl_ListDeamonApp.push_back(st_APPInfo); + } + return true; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h index 24495db0919c1a54d9919318fcb63dc549b699ab..a4ac9d0418d18132a8e18f24124dcdba95d3d852 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h @@ -21,6 +21,7 @@ public: bool ModuleConfigure_Json_OPenccFile(LPCXSTR lpszConfigFile, XENGINE_OPENCCCONFIG* pSt_OPenccConfig); bool ModuleConfigure_Json_QRCodeFile(LPCXSTR lpszConfigFile, XENGINE_QRCODECONFIG* pSt_QRCodeConfig); bool ModuleConfigure_Json_PluginFile(LPCXSTR lpszConfigFile, XENGINE_PLUGINCONFIG* pSt_PluginConfig); + bool ModuleConfigure_Json_DeamonList(LPCXSTR lpszConfigFile, XENGINE_DEAMONAPPLIST* pSt_AppConfig); protected: private: }; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def index 3983d3c5e6e0eaf2d775786871325e13f6597597..1680488f29f75f438876269cf383c964b8fcbaa8 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def @@ -6,4 +6,5 @@ EXPORTS ModuleConfigure_Json_File ModuleConfigure_Json_OPenccFile ModuleConfigure_Json_QRCodeFile - ModuleConfigure_Json_PluginFile \ No newline at end of file + ModuleConfigure_Json_PluginFile + ModuleConfigure_Json_DeamonList \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/pch.cpp b/XEngine_Source/XEngine_ModuleConfigure/pch.cpp index f3c383dfe65a34b53ab6c1092e1777f3c5d6fa6e..2711d70ea7fbd4b42b0b463ded0025b1fd2d5e80 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/pch.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/pch.cpp @@ -44,4 +44,8 @@ extern "C" bool ModuleConfigure_Json_QRCodeFile(LPCXSTR lpszConfigFile, XENGINE_ extern "C" bool ModuleConfigure_Json_PluginFile(LPCXSTR lpszConfigFile, XENGINE_PLUGINCONFIG * pSt_PluginConfig) { return m_ConfigJson.ModuleConfigure_Json_PluginFile(lpszConfigFile, pSt_PluginConfig); +} +extern "C" bool ModuleConfigure_Json_DeamonList(LPCXSTR lpszConfigFile, XENGINE_DEAMONAPPLIST * pSt_AppConfig) +{ + return m_ConfigJson.ModuleConfigure_Json_DeamonList(lpszConfigFile, pSt_AppConfig); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h index aff866bb5e1b679df389036c3439e0ada746ff7a..b2d84227441d6e887141e45bd2d4559d3d48666e 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h @@ -916,4 +916,43 @@ extern "C" bool ModuleProtocol_Parse_BackService(LPCXSTR lpszMsgBuffer, int nMsg 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleProtocol_Parse_Verifcation(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszUserName, XCHAR* ptszUserPass); \ No newline at end of file +extern "C" bool ModuleProtocol_Parse_Verifcation(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszUserName, XCHAR* ptszUserPass); +/******************************************************************** +函数名称:ModuleProtocol_Parse_Deamon +函数功能:守护进程协议 + 参数.一:lpszMsgBuffer + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要解析的数据 + 参数.二:nMsgLen + In/Out:In + 类型:整数型 + 可空:N + 意思:要解析的大小 + 参数.三:ptszAPPName + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出进程名称 + 参数.四:ptszAPPPath + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出进程路径 + 参数.五:pInt_Retime + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出重试次数 + 参数.六:pbEnable + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出是否启用 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleProtocol_Parse_Deamon(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszAPPName, XCHAR* ptszAPPPath, int* pInt_Retime, bool* pbEnable); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp index dd87866986915a43acc4b4b4f06b6f751ebc6d05..cc4244c6ec7dd9dec440a50acd6b857624ac640f 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp @@ -899,4 +899,94 @@ bool CModuleProtocol_Parse::ModuleProtocol_Parse_Verifcation(LPCXSTR lpszMsgBuff } } return true; +} +/******************************************************************** +函数名称:ModuleProtocol_Parse_Deamon +函数功能:守护进程协议 + 参数.一:lpszMsgBuffer + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要解析的数据 + 参数.二:nMsgLen + In/Out:In + 类型:整数型 + 可空:N + 意思:要解析的大小 + 参数.三:ptszAPPName + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出进程名称 + 参数.四:ptszAPPPath + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出进程路径 + 参数.五:pInt_Retime + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出重试次数 + 参数.六:pbEnable + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出是否启用 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleProtocol_Parse::ModuleProtocol_Parse_Deamon(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszAPPName, XCHAR* ptszAPPPath, int* pInt_Retime, bool* pbEnable) +{ + ModuleProtocol_IsErrorOccur = false; + + if ((NULL == lpszMsgBuffer) || (0 == nMsgLen)) + { + ModuleProtocol_IsErrorOccur = true; + ModuleProtocol_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PROTOCOL_PARSE_PARAMENT; + return false; + } + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_JsonBuilder; + + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); + if (!pSt_JsonReader->parse(lpszMsgBuffer, lpszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) + { + ModuleProtocol_IsErrorOccur = true; + ModuleProtocol_dwErrorCode = ERROR_XENGINE_APISERVICE_MODULE_PROTOCOL_PARSE_PARAMENT; + return false; + } + + if (!st_JsonRoot["tszAPPName"].isNull()) + { + if (NULL != ptszAPPName) + { + _tcsxcpy(ptszAPPName, st_JsonRoot["tszAPPName"].asCString()); + } + } + if (!st_JsonRoot["tszAPPPath"].isNull()) + { + if (NULL != ptszAPPPath) + { + _tcsxcpy(ptszAPPPath, st_JsonRoot["tszAPPPath"].asCString()); + } + } + if (!st_JsonRoot["nRetime"].isNull()) + { + if (NULL != pInt_Retime) + { + *pInt_Retime = st_JsonRoot["nRetime"].asInt(); + } + } + if (!st_JsonRoot["bEnable"].isNull()) + { + if (NULL != pbEnable) + { + *pbEnable = st_JsonRoot["bEnable"].asBool(); + } + } + return true; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h index 975015b3ae9f4bddc09469214b8b2353988b9580..85151b12dcdb30dada4275cf00bb408056498191 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h @@ -30,5 +30,6 @@ public: bool ModuleProtocol_Parse_WordFilter(LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_WORDFILTER* pSt_WordFilter); bool ModuleProtocol_Parse_BackService(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszSrcBuffer = NULL, XCHAR* ptszDstBuffer = NULL, int* pInt_BSType = NULL); bool ModuleProtocol_Parse_Verifcation(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszUserName, XCHAR* ptszUserPass); + bool ModuleProtocol_Parse_Deamon(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR* ptszAPPName, XCHAR* ptszAPPPath, int* pInt_Retime, bool* pbEnable); private: }; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def index 40c02f8e53d8faa51494aa4b8b1e9d170143e50f..162ee06c71deb3ceb7dea8d9014c802e1b52d633 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def @@ -35,4 +35,5 @@ EXPORTS ModuleProtocol_Parse_ShortLink ModuleProtocol_Parse_WordFilter ModuleProtocol_Parse_BackService - ModuleProtocol_Parse_Verifcation \ No newline at end of file + ModuleProtocol_Parse_Verifcation + ModuleProtocol_Parse_Deamon \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp index 23ea8d0528eb6b94c8937b9600698a7e98ced72c..7cb801167d904579437b9e342717db64c58ee2c0 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp +++ b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp @@ -161,4 +161,8 @@ extern "C" bool ModuleProtocol_Parse_BackService(LPCXSTR lpszMsgBuffer, int nMsg extern "C" bool ModuleProtocol_Parse_Verifcation(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR * ptszUserName, XCHAR * ptszUserPass) { return m_ProtocolParse.ModuleProtocol_Parse_Verifcation(lpszMsgBuffer, nMsgLen, ptszUserName, ptszUserPass); +} +extern "C" bool ModuleProtocol_Parse_Deamon(LPCXSTR lpszMsgBuffer, int nMsgLen, XCHAR * ptszAPPName, XCHAR * ptszAPPPath, int* pInt_Retime, bool* pbEnable) +{ + return m_ProtocolParse.ModuleProtocol_Parse_Deamon(lpszMsgBuffer, nMsgLen, ptszAPPName, ptszAPPPath, pInt_Retime, pbEnable); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/Makefile b/XEngine_Source/XEngine_ModuleSystem/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f70755fe28d858bec14a44d19976477d75806a78 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/Makefile @@ -0,0 +1,71 @@ +CC = g++ -Wall -std=c++17 -fPIC +PLATFORM = linux +PLATVER = +PLATDIR = +FILEEXT = +LIBFLAG = +RELEASE = 0 +UNICODE = 0 +LOADHDR = -I ./ +LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk +LIB = -lXEngine_BaseLib -lXEngine_SystemApi +LIBEX = +OBJECTS = ModuleSystem_API.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + +ifeq ($(PLATFORM),linux) + ifeq (/etc/redhat-release,$(wildcard /etc/redhat-release)) + PLATVER = -D __CENTOS__ + PLATDIR = XEngine_Linux/Centos + else + PLATVER = -D __UBUNTU__ + PLATDIR = XEngine_Linux/Ubuntu + endif + FILEEXT = so + LIBFLAG = -shared + LIBEX = -lpthread -lrt -ldl + LOADBIN = -Wl,-rpath=./,--disable-new-dtags +else ifeq ($(PLATFORM),mac) + CC += -Wno-deprecated-declarations + PLATVER = -D __MACOS__ + PLATDIR = XEngine_Mac + FILEEXT = dylib + LIBFLAG = -dynamiclib + LIBEX = -lpthread -ldl + LOADBIN = -Wl,-rpath,@loader_path/./ +endif + + +all:$(OBJECTS) + $(CC) $(DEBUG) $(OBJECTS) -o libXEngine_ModuleSystem.$(FILEEXT) $(LIBFLAG) $(LIB) $(LIBEX) $(LOADSO) $(LOADBIN) + +ModuleSystem_API.o:./ModuleSystem_API/ModuleSystem_API.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./ModuleSystem_API/ModuleSystem_API.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libXEngine_ModuleSystem.$(FILEEXT) + cp ./libXEngine_ModuleSystem.$(FILEEXT) ../../XEngine_Release/libXEngine_ModuleSystem.$(FILEEXT) + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.$(FILEEXT) diff --git a/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_API/ModuleSystem_API.cpp b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_API/ModuleSystem_API.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c4ea5a9e007cdef5a9597866c0d9e7332ca5cf59 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_API/ModuleSystem_API.cpp @@ -0,0 +1,185 @@ +#include "pch.h" +#include "ModuleSystem_API.h" +/******************************************************************** +// Created: 2023/09/06 13:50:15 +// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\ModuleSystem_API\ModuleSystem_API.cpp +// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\ModuleSystem_API +// File Base: ModuleSystem_API +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 系统API函数库 +// History: +*********************************************************************/ +CModuleSystem_API::CModuleSystem_API() +{ + +} +CModuleSystem_API::~CModuleSystem_API() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公用函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:ModuleSystem_API_AutoStart +函数功能:注册自动启动与服务函数 + 参数.一:bIsAuto + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否让其自动启动,默认为真,自动启动 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSystem_API::ModuleSystem_API_AutoStart(bool bIsAuto /* = true */) +{ + ModuleSystem_IsErrorOccur = false; + +#ifdef _MSC_BUILD + if (bIsAuto) + { + IShellLinkA* pSt_ILink = NULL; //IShellLink对象指针 + IPersistFile* pSt_IFile = NULL; //IPersisFil对象指针 + //创建IShellLink对象 + CoInitializeEx(NULL, COINIT_MULTITHREADED); + HRESULT hResult = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pSt_ILink); + if (FAILED(hResult)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_COINIT; + return false; + } + //从IShellLink对象中获取IPersistFile接口 + hResult = pSt_ILink->QueryInterface(IID_IPersistFile, (void**)&pSt_IFile); + if (FAILED(hResult)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_QUERY; + return false; + } + + XCHAR tszFilePath[MAX_PATH]; + XCHAR tszFileName[MAX_PATH]; + + memset(tszFilePath, '\0', MAX_PATH); + memset(tszFileName, '\0', MAX_PATH); + + GetCurrentDirectoryA(MAX_PATH, tszFilePath); + GetModuleFileNameA(NULL, tszFileName, MAX_PATH); + //目标 + pSt_ILink->SetPath(tszFileName); + //工作目录 + pSt_ILink->SetWorkingDirectory(tszFilePath); + //备注 + pSt_ILink->SetDescription(_X("XDeamon systemd service")); + //显示方式 + pSt_ILink->SetShowCmd(SW_SHOW); + //保存快捷方式到指定目录下 + + XCHAR tszAFile[MAX_PATH]; + WCHAR tszUFile[MAX_PATH]; + + memset(tszAFile, '\0', sizeof(tszAFile)); + memset(tszUFile, '\0', sizeof(tszUFile)); + + if (S_OK != SHGetFolderPathA(NULL, CSIDL_STARTUP, NULL, 0, tszAFile)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_GETFILENAME; + return false; + } + _tcsxcat(tszAFile, _X("\\XEngine_DeamonApp.lnk")); + BaseLib_OperatorCharset_AnsiToUnicode(tszAFile, tszUFile); + + hResult = pSt_IFile->Save(tszUFile, TRUE); + if (FAILED(hResult)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_SYSENABLE; + return false; + } + pSt_IFile->Release(); + pSt_ILink->Release(); + CoUninitialize(); + } + else + { + XCHAR tszAFile[MAX_PATH]; + memset(tszAFile, '\0', sizeof(tszAFile)); + + if (S_OK != SHGetFolderPathA(NULL, CSIDL_STARTUP, NULL, 0, tszAFile)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_SYSDISABLE; + return false; + } + _tcsxcat(tszAFile, _X("\\XEngine_DeamonApp.lnk")); + _xtremove(tszAFile); + } +#elif __linux__ + LPCXSTR lpszStartStr = _X("/usr/lib/systemd/system/xdeamon.service"); + if (bIsAuto) + { + if (0 != _xtaccess(lpszStartStr, F_OK)) + { + XCHAR tszMsgBuffer[2048]; + XCHAR tszFileDir[MAX_PATH]; + + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + memset(tszFileDir, '\0', sizeof(tszFileDir)); + + SystemApi_Process_GetPath(tszFileDir); + + int nRet = _xstprintf(tszMsgBuffer, _X("# XDeamon systemd service file\n" + "\n" + "[Unit]\n" + "Description=XEngine XDeamon Service\n" + "Documentation=http://www.xyry.org\n" + "After=network.target\n" + "\n" + "[Install]\n" + "WantedBy=multi-user.target\n" + "\n" + "[Service]\n" + "Type=forking\n" + "PIDFile=xdeamon.pid\n" + "ExecStart=%s\n" + "ExecStop=kill -s QUIT $MAINPID\n"), tszFileDir); + + if (!SystemApi_File_SaveBuffToFile(lpszStartStr, tszMsgBuffer, nRet)) + { + return false; + } + } + XCHAR tszServiceStr[MAX_PATH]; + memset(tszServiceStr, '\0', MAX_PATH); + + _xstprintf(tszServiceStr, _X("sudo systemctl enable xdeamon")); + if (-1 == system(tszServiceStr)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_SYSENABLE; + return false; + } + } + else + { + XCHAR tszServiceStr[MAX_PATH]; + memset(tszServiceStr, '\0', MAX_PATH); + + _xstprintf(tszServiceStr, _X("systemctl disable xdeamon")); + if (-1 == system(tszServiceStr)) + { + ModuleSystem_IsErrorOccur = true; + ModuleSystem_dwErrorCode = ERROR_MODULE_SYSTEM_API_SYSDISABLE; + return false; + } + _xtremove(lpszStartStr); + } +#endif + return true; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_API/ModuleSystem_API.h b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_API/ModuleSystem_API.h new file mode 100644 index 0000000000000000000000000000000000000000..8f2c9c3c1f7c95698eb9604b8aadd9f1bbc68087 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_API/ModuleSystem_API.h @@ -0,0 +1,23 @@ +#pragma once +/******************************************************************** +// Created: 2023/09/06 13:49:59 +// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\ModuleSystem_API\ModuleSystem_API.h +// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\ModuleSystem_API +// File Base: ModuleSystem_API +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 系统API函数库 +// History: +*********************************************************************/ + +class CModuleSystem_API +{ +public: + CModuleSystem_API(); + ~CModuleSystem_API(); +public: + bool ModuleSystem_API_AutoStart(bool bIsAuto = true); +protected: +private: +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_Define.h b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_Define.h new file mode 100644 index 0000000000000000000000000000000000000000..5c04cb562baf87f4fa77f7b4598d38aa9564fa9a --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_Define.h @@ -0,0 +1,33 @@ +#pragma once +/******************************************************************** +// Created: 2023/09/06 13:50:57 +// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\ModuleHelp_Define.h +// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem +// File Base: ModuleHelp_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 模块导出定义 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出函数定义 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG ModuleSystem_GetLastError(int* pInt_ErrorCode = NULL); +/************************************************************************/ +/* 系统函数库 */ +/************************************************************************/ +/******************************************************************** +函数名称:ModuleSystem_API_AutoStart +函数功能:注册自动启动与服务函数 + 参数.一:bIsAuto + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否让其自动启动,默认为真,自动启动 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSystem_API_AutoStart(bool bIsAuto = true); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_Error.h b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_Error.h new file mode 100644 index 0000000000000000000000000000000000000000..6d0ce419b2b2c10a0123ba830263eb7b64df051c --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/ModuleSystem_Error.h @@ -0,0 +1,21 @@ +#pragma once +/******************************************************************** +// Created: 2023/09/06 13:51:12 +// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\ModuleHelp_Error.h +// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem +// File Base: ModuleHelp_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 模块导出错误 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 系统函数错误表 +////////////////////////////////////////////////////////////////////////// +#define ERROR_MODULE_SYSTEM_API_PARAMENT 0xF0001 //参数错误 +#define ERROR_MODULE_SYSTEM_API_SYSENABLE 0xF0002 //自动启动服务启用失败 +#define ERROR_MODULE_SYSTEM_API_SYSDISABLE 0xF0003 //禁用自动启动服务失败 +#define ERROR_MODULE_SYSTEM_API_GETFILENAME 0xF0004 //获取自身文件名失败 +#define ERROR_MODULE_SYSTEM_API_COINIT 0xF0005 //打开OLD失败 +#define ERROR_MODULE_SYSTEM_API_QUERY 0xF0006 //查询接口失败 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.def b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.def new file mode 100644 index 0000000000000000000000000000000000000000..5216efd70f13bf7cbbf2f3740e53f17d0abb6c75 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.def @@ -0,0 +1,6 @@ +LIBRARY + +EXPORTS + ModuleSystem_GetLastError + + ModuleSystem_API_AutoStart \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..23dd52f06ab0cb2999f87181d2cfe885bab606a2 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj @@ -0,0 +1,184 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {92f971ab-cac9-4d9b-a9ca-afd9ca17e505} + XEngineModuleSystem + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;XENGINEMODULESYSTEM_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleSystem.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;XENGINEMODULESYSTEM_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleSystem.def + + + + + Level3 + true + _DEBUG;XENGINEMODULESYSTEM_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleSystem.def + + + + + Level3 + true + true + true + NDEBUG;XENGINEMODULESYSTEM_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleSystem.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj.filters b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..91def0c8e060a4f57555bea365140d358ecd43c0 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {37e818fa-b51c-4556-826d-5f9e044401ee} + + + {d2c17612-8a80-4a50-9153-2cab10cc56ce} + + + + + 头文件 + + + 头文件 + + + 头文件\ModuleSystem_API + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件\ModuleSystem_API + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj.user b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/XEngine_ModuleSystem.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/dllmain.cpp b/XEngine_Source/XEngine_ModuleSystem/dllmain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daed8c8f7ac50ca1466016a0529648d18125a7e7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/XEngine_ModuleSystem/framework.h b/XEngine_Source/XEngine_ModuleSystem/framework.h new file mode 100644 index 0000000000000000000000000000000000000000..80cbbc9b06a9b0141f92ee19eceaed71328caff4 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/XEngine_ModuleSystem/pch.cpp b/XEngine_Source/XEngine_ModuleSystem/pch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a68805de93c14c90035325131608ad324d443cf --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/pch.cpp @@ -0,0 +1,35 @@ +#include "pch.h" +#include "ModuleSystem_API/ModuleSystem_API.h" +/******************************************************************** +// Created: 2023/09/06 13:54:52 +// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\pch.cpp +// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +bool ModuleSystem_IsErrorOccur = false; +XLONG ModuleSystem_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CModuleSystem_API m_ModuleSystem; +////////////////////////////////////////////////////////////////////////// +// 导出函数定义 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG ModuleSystem_GetLastError(int* pInt_ErrorCode) +{ + if (NULL != pInt_ErrorCode) + { + *pInt_ErrorCode = errno; + } + return ModuleSystem_dwErrorCode; +} +/************************************************************************/ +/* 系统函数库 */ +/************************************************************************/ +extern "C" bool ModuleSystem_API_AutoStart(bool bIsAuto /* = true */) +{ + return m_ModuleSystem.ModuleSystem_API_AutoStart(bIsAuto); +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSystem/pch.h b/XEngine_Source/XEngine_ModuleSystem/pch.h new file mode 100644 index 0000000000000000000000000000000000000000..362e91aede87ef4d34caadc7b11bc62863397f15 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSystem/pch.h @@ -0,0 +1,51 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H +#ifdef _MSC_BUILD +// 添加要在此处预编译的标头 +#include "framework.h" +#include +#include +#include +#else +#include +#endif +#endif //PCH_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ModuleSystem_Define.h" +#include "ModuleSystem_Error.h" +/******************************************************************** +// Created: 2023/09/06 13:52:47 +// File Name: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem\pch.h +// File Path: D:\XEngine_APIService\XEngine_Source\XEngine_ModuleSystem +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头文件 +// History: +*********************************************************************/ +extern bool ModuleSystem_IsErrorOccur; +extern XLONG ModuleSystem_dwErrorCode; + +#ifdef _MSC_BUILD +#pragma comment(lib, "shell32.lib") +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi") +#endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/Makefile b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/Makefile index 4e45ce579ccd3c4b1cd9cb230cfc010f5ac614dd..78c930ab408c9bd727993a6d7616d050a2d51139 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/Makefile +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/Makefile @@ -7,16 +7,16 @@ LIBFLAG = RELEASE = 0 UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp -LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L /usr/local/lib/XEngine_Release/XEngine_AVCodec \ - -L ../../XEngine_ModuleConfigure -L ../../XEngine_ModuleDatabase -L ../../XEngine_ModuleProtocol -L ../../XEngine_ModuleHelp -L ../../XEngine_ModulePlugin \ +LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L /usr/local/lib/XEngine_Release/XEngine_SystemSdk -L /usr/local/lib/XEngine_Release/XEngine_AVCodec -L /usr/local/lib/XEngine_Release/XEngine_StreamMedia \ + -L ../../XEngine_ModuleConfigure -L ../../XEngine_ModuleDatabase -L ../../XEngine_ModuleProtocol -L ../../XEngine_ModuleSystem -L ../../XEngine_ModuleHelp -L ../../XEngine_ModulePlugin \ -L ../../XEngine_ThirdPart/jsoncpp -LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_OPenSsl -lHelpComponents_XLog -lRfcComponents_HttpProtocol -lNetHelp_APIClient -lXEngine_ProcFile -lXEngine_SystemApi -lXEngine_AVHelp \ - -lXEngine_ModuleConfigure -lXEngine_ModuleDatabase -lXEngine_ModuleProtocol -lXEngine_ModuleHelp -lXEngine_ModulePlugin \ +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_OPenSsl -lHelpComponents_XLog -lRfcComponents_HttpProtocol -lNetHelp_APIClient -lXEngine_ProcFile -lXEngine_SystemApi -lXEngine_AVHelp -lXEngine_VideoCodec -lXEngine_AudioCodec -lXEngine_AVCollect -lStreamMedia_StreamClient \ + -lXEngine_ModuleConfigure -lXEngine_ModuleDatabase -lXEngine_ModuleProtocol -lXEngine_ModuleSystem -lXEngine_ModuleHelp -lXEngine_ModulePlugin \ -ljsoncpp LIBEX = OBJECTS = XEngine_Configure.o XEngine_Network.o XEngine_HTTPTask.o XEngine_PluginTask.o XEngine_HttpApp.o \ TaskGet_Bank.o TaskGet_IDCard.o TaskGet_Language.o TaskGet_Locker.o TaskGet_Translation.o TaskGet_Reload.o \ - TaskPost_DTest.o TaskPost_Log.o TaskPost_P2PClient.o TaskPost_PostCode.o TaskPost_QRCode.o TaskPost_ShortLink.o TaskPost_SocketTest.o TaskPost_WordFilter.o TaskPost_Image.o TaskPost_BackService.o + TaskPost_DTest.o TaskPost_Log.o TaskPost_P2PClient.o TaskPost_PostCode.o TaskPost_QRCode.o TaskPost_ShortLink.o TaskPost_SocketTest.o TaskPost_WordFilter.o TaskPost_Image.o TaskPost_BackService.o TaskPost_Deamon.o ifeq ($(RELEASE),1) FLAGS = -c @@ -99,6 +99,8 @@ TaskPost_Image.o:./XEngine_TaskPost/TaskPost_Image.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_TaskPost/TaskPost_Image.cpp TaskPost_BackService.o:./XEngine_TaskPost/TaskPost_BackService.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_TaskPost/TaskPost_BackService.cpp +TaskPost_Deamon.o:./XEngine_TaskPost/TaskPost_Deamon.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_TaskPost/TaskPost_Deamon.cpp XEngine_HttpApp.o:./XEngine_HttpApp.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_HttpApp.cpp diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.cpp index dd2ade7c5fb83e15f850b446f73abc81dbea44b0..dcadc182b72b30e81cecdbdb58febda26cc9413e 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.cpp @@ -10,17 +10,17 @@ // Purpose: 配置文件操作代码 // History: *********************************************************************/ -bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pSt_Configure) +bool XEngine_Configure_Parament(int argc, char** argv) { LPCXSTR lpszConfigFile = _X("./XEngine_Config/XEngine_Config.json"); - - if (NULL != pSt_Configure->st_XVer.pStl_ListVer) + + if (NULL != st_ServiceConfig.st_XVer.pStl_ListVer) { - delete pSt_Configure->st_XVer.pStl_ListVer; - pSt_Configure->st_XVer.pStl_ListVer = NULL; + delete st_ServiceConfig.st_XVer.pStl_ListVer; + st_ServiceConfig.st_XVer.pStl_ListVer = NULL; } - memset(pSt_Configure, '\0', sizeof(XENGINE_SERVICECONFIG)); - if (!ModuleConfigure_Json_File(lpszConfigFile, pSt_Configure)) + memset(&st_ServiceConfig, '\0', sizeof(XENGINE_SERVICECONFIG)); + if (!ModuleConfigure_Json_File(lpszConfigFile, &st_ServiceConfig)) { printf("解析配置文件失败,ModuleConfigure_Json_File:%lX\n", ModuleConfigure_GetLastError()); return false; @@ -35,12 +35,12 @@ bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pS } else if (0 == _tcsxcmp("-d", argv[i])) { - pSt_Configure->bDeamon = _ttxoi(argv[i + 1]); + st_ServiceConfig.bDeamon = _ttxoi(argv[i + 1]); } else if (0 == _tcsxcmp("-r", argv[i])) { - pSt_Configure->st_XReload.bReload = true; - pSt_Configure->st_XReload.byCode = _ttxoi(argv[i + 1]); + st_ServiceConfig.st_XReload.bReload = true; + st_ServiceConfig.st_XReload.byCode = _ttxoi(argv[i + 1]); } } diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.h b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.h index 9a5060ffa2b42484163471ff8cb8b1cbf01b02e5..8f60c40ea50ef54c08ee04db05491796bbafd1d1 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Configure.h @@ -10,5 +10,5 @@ // Purpose: 配置文件操作代码 // History: *********************************************************************/ -bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pSt_Configure); +bool XEngine_Configure_Parament(int argc, char** argv); void XEngine_Configure_Help(); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HTTPTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HTTPTask.cpp index 9824be0d12f707d0c7cf82f0b01c3f2420be6823..8c4ec511b32cb55b85bc9f735427a9d29d1bd074 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HTTPTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HTTPTask.cpp @@ -113,6 +113,7 @@ bool HTTPTask_TastPost_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXST LPCXSTR lpszParamWordFilter = _X("wordfilter"); LPCXSTR lpszParamBack = _X("back"); LPCXSTR lpszParamImage = _X("image"); + LPCXSTR lpszParamDeamon = _X("deamon"); memset(tszKey, '\0', MAX_PATH); memset(tszValue, '\0', MAX_PATH); @@ -280,6 +281,11 @@ bool HTTPTask_TastPost_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXST //图像处理接口:http://app.xyry.org:5501/api?function=image¶ms1=0 HTTPTask_TaskPost_Image(lpszClientAddr, lpszRVBuffer, nRVLen, &pptszList, nListCount); } + else if (0 == _tcsxnicmp(lpszParamDeamon, tszValue, _tcsxlen(lpszParamDeamon))) + { + //守护进程接口:http://app.xyry.org:5501/api?function=deamon¶ms1=0 + HTTPTask_TaskPost_Deamon(lpszClientAddr, lpszRVBuffer, nRVLen); + } else { st_HDRParam.nHttpCode = 404; diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Hdr.h index 4759c0b38bd3b3e796f878ad2fb829c0058e0b51..420e11e82bb1fe2fef41d07e974adb497b2caa65 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_Hdr.h @@ -44,8 +44,13 @@ using namespace std; #include #include #include +#include +#include +#include #include #include +#include +#include //加载项目相关头文件 #include "../../XEngine_UserProtocol.h" #include "../../XEngine_ModuleConfigure/ModuleConfig_Define.h" @@ -54,6 +59,8 @@ using namespace std; #include "../../XEngine_ModuleDatabase/ModuleDB_Error.h" #include "../../XEngine_ModuleProtocol/ModuleProtocol_Define.h" #include "../../XEngine_ModuleProtocol/ModuleProtocol_Error.h" +#include "../../XEngine_ModuleSystem/ModuleSystem_Define.h" +#include "../../XEngine_ModuleSystem/ModuleSystem_Error.h" #include "../../XEngine_ModuleHelp/ModuleHelp_Define.h" #include "../../XEngine_ModuleHelp/ModuleHelp_Error.h" #include "../../XEngine_ModulePlugin/ModulePlugin_Define.h" @@ -74,6 +81,7 @@ using namespace std; #include "XEngine_TaskPost/TaskPost_WordFilter.h" #include "XEngine_TaskPost/TaskPost_BackService.h" #include "XEngine_TaskPost/TaskPost_Image.h" +#include "XEngine_TaskPost/TaskPost_Deamon.h" //get #include "XEngine_TaskGet/TaskGet_IDCard.h" #include "XEngine_TaskGet/TaskGet_Bank.h" @@ -101,12 +109,15 @@ extern XHANDLE xhHTTPSocket; extern XHANDLE xhHTTPHeart; extern XHANDLE xhHTTPPacket; extern XHANDLE xhHTTPPool; +//线程 +extern unique_ptr pSTDThread_Deamon; //配置文件 extern XENGINE_SERVICECONFIG st_ServiceConfig; extern XENGINE_OPENCCCONFIG st_OPenccConfig; extern XENGINE_QRCODECONFIG st_QRCodeConfig; extern XENGINE_PLUGINCONFIG st_PluginLibConfig; extern XENGINE_PLUGINCONFIG st_PluginLuaConfig; +extern XENGINE_DEAMONAPPLIST st_DeamonAppConfig; //连接库 #ifdef _MSC_BUILD #ifdef _WIN64 @@ -114,12 +125,14 @@ extern XENGINE_PLUGINCONFIG st_PluginLuaConfig; #pragma comment(lib,"../../x64/Debug/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../../x64/Debug/XEngine_ModuleDatabase.lib") #pragma comment(lib,"../../x64/Debug/XEngine_ModuleProtocol.lib") +#pragma comment(lib,"../../x64/Debug/XEngine_ModuleSystem.lib") #pragma comment(lib,"../../x64/Debug/XEngine_ModuleHelp.lib") #pragma comment(lib,"../../x64/Debug/XEngine_ModulePlugin.lib") #else #pragma comment(lib,"../../x64/Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../../x64/Release/XEngine_ModuleDatabase.lib") #pragma comment(lib,"../../x64/Release/XEngine_ModuleProtocol.lib") +#pragma comment(lib,"../../x64/Release/XEngine_ModuleSystem.lib") #pragma comment(lib,"../../x64/Release/XEngine_ModuleHelp.lib") #pragma comment(lib,"../../x64/Release/XEngine_ModulePlugin.lib") #endif @@ -128,12 +141,14 @@ extern XENGINE_PLUGINCONFIG st_PluginLuaConfig; #pragma comment(lib,"../../Debug/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../../Debug/XEngine_ModuleDatabase.lib") #pragma comment(lib,"../../Debug/XEngine_ModuleProtocol.lib") +#pragma comment(lib,"../../Debug/XEngine_ModuleSystem.lib") #pragma comment(lib,"../../Debug/XEngine_ModuleHelp.lib") #pragma comment(lib,"../../Debug/XEngine_ModulePlugin.lib") #else #pragma comment(lib,"../../Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../../Release/XEngine_ModuleDatabase.lib") #pragma comment(lib,"../../Release/XEngine_ModuleProtocol.lib") +#pragma comment(lib,"../../Release/XEngine_ModuleSystem.lib") #pragma comment(lib,"../../Release/XEngine_ModuleHelp.lib") #pragma comment(lib,"../../Release/XEngine_ModulePlugin.lib") #endif @@ -146,6 +161,10 @@ extern XENGINE_PLUGINCONFIG st_PluginLuaConfig; #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpProtocol.lib") #pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient.lib") #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi") +#pragma comment(lib,"XEngine_AVCodec/XEngine_AVCollect.lib") +#pragma comment(lib,"XEngine_AVCodec/XEngine_VideoCodec.lib") +#pragma comment(lib,"XEngine_AVCodec/XEngine_AudioCodec.lib") #pragma comment(lib,"XEngine_AVCodec/XEngine_AVHelp.lib") +#pragma comment(lib,"XEngine_StreamMedia/StreamMedia_StreamClient.lib") #pragma comment(lib,"Ws2_32.lib") #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.cpp index f686d933373f577aed34ce184844ad91fc934b25..dfe2a9cb5122fd8323e6afc04c9e18c3276f7a1b 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.cpp @@ -17,12 +17,15 @@ XHANDLE xhHTTPSocket = NULL; XHANDLE xhHTTPHeart = NULL; XHANDLE xhHTTPPacket = NULL; XHANDLE xhHTTPPool = 0; +//线程 +unique_ptr pSTDThread_Deamon; //配置文件 XENGINE_SERVICECONFIG st_ServiceConfig; XENGINE_OPENCCCONFIG st_OPenccConfig; XENGINE_QRCODECONFIG st_QRCodeConfig; XENGINE_PLUGINCONFIG st_PluginLibConfig; XENGINE_PLUGINCONFIG st_PluginLuaConfig; +XENGINE_DEAMONAPPLIST st_DeamonAppConfig; void ServiceApp_Stop(int signo) { @@ -47,6 +50,11 @@ void ServiceApp_Stop(int signo) ModuleHelp_P2PClient_Destory(); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); + //销毁线程 + if (NULL != pSTDThread_Deamon) + { + pSTDThread_Deamon->join(); + } } #ifdef _MSC_BUILD WSACleanup(); @@ -94,6 +102,7 @@ int main(int argc, char** argv) LPCXSTR lpszHTTPMime = _X("./XEngine_Config/HttpMime.types"); LPCXSTR lpszHTTPCode = _X("./XEngine_Config/HttpCode.types"); LPCXSTR lpszLogFile = _X("./XEngine_Log/XEngine_HttpApp.Log"); + LPCXSTR lpszConfigDeamon = _X("./XEngine_Config/XEngine_DeamonConfig.json"); HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig; THREADPOOL_PARAMENT** ppSt_ListHTTPParam; @@ -108,9 +117,9 @@ int main(int argc, char** argv) st_XLogConfig.XLog_MaxSize = 1024000; _tcsxcpy(st_XLogConfig.tszFileName, lpszLogFile); //初始化参数 - if (!XEngine_Configure_Parament(argc, argv, &st_ServiceConfig)) + if (!XEngine_Configure_Parament(argc, argv)) { - return -1; + goto XENGINE_SERVICEAPP_EXIT; } //配置重载 if (st_ServiceConfig.st_XReload.bReload) @@ -144,6 +153,35 @@ int main(int argc, char** argv) signal(SIGABRT, ServiceApp_Stop); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化信号量成功")); + if (!SystemApi_Process_IsAdmin()) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,启动权限不足,对于进程和后台服务任务可能会执行失败,请切换管理员权限")); + } + if (!ModuleSystem_API_AutoStart(st_ServiceConfig.bAutoStart)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,注册软件开机启动失败!错误:%lX"), ModuleHelp_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,设置软件开机启动标志成功,标志位:%d"), st_ServiceConfig.bAutoStart); + + if (st_ServiceConfig.bHideWnd) + { +#ifdef _MSC_BUILD + LPCXSTR lpszWndName = _X("XEngine_DeamonApp"); + SetConsoleTitleA(lpszWndName); + HWND hWnd = FindWindowA(NULL, lpszWndName); + + if (NULL == hWnd) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,设置窗口隐藏失败,没有找到句柄")); + } + else + { + ShowWindow(hWnd, SW_HIDE); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,设置窗口隐藏成功")); + } +#endif + } //初始化OPENCC配置 if (!ModuleConfigure_Json_OPenccFile(st_ServiceConfig.st_XConfig.tszConfigOPencc, &st_OPenccConfig)) { @@ -279,7 +317,32 @@ int main(int argc, char** argv) goto XENGINE_SERVICEAPP_EXIT; } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动P2P客户端管理器成功,超时时间设置:%d 秒"), st_ServiceConfig.st_XTime.nP2PTimeOut); - + //进程守护 + if (!ModuleConfigure_Json_DeamonList(lpszConfigDeamon, &st_DeamonAppConfig)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动加载进程守护配置文件失败,错误:%lX"), ModuleConfigure_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动加载进程守护配置文件成功")); + for (auto stl_ListIterator = st_DeamonAppConfig.stl_ListDeamonApp.begin(); stl_ListIterator != st_DeamonAppConfig.stl_ListDeamonApp.end(); stl_ListIterator++) + { + if (stl_ListIterator->bEnable) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,加载守护进程:%s,成功,开始守护进程"), stl_ListIterator->tszAPPName); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,加载守护进程:%s,成功,此项目未启用"), stl_ListIterator->tszAPPName); + } + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,加载守护进程列表成功,加载的列表个数:%d"), st_DeamonAppConfig.stl_ListDeamonApp.size()); + pSTDThread_Deamon = make_unique(HTTPTask_TaskPost_Thread); + if (NULL == pSTDThread_Deamon) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动进程管理线程失败")); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动进程管理线程成功")); //启动插件 if (!ModulePlugin_Loader_Init()) { @@ -334,7 +397,7 @@ int main(int argc, char** argv) //展示能力 XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,加载的Lib插件:%d 个,Lua插件:%d 个"), st_PluginLibConfig.pStl_ListPlugin->size(), st_PluginLuaConfig.pStl_ListPlugin->size()); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,服务运行中,XEngine版本:%s%s,发行版本次数:%d,当前版本:%s。。。"), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_ServiceConfig.st_XVer.pStl_ListVer->size(), st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,服务运行中,XEngine版本:%s%s,发行版本次数:%d,当前版本:%s。。。"), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_ServiceConfig.st_XVer.pStl_ListVer->size(), st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str()); while (true) { std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -362,9 +425,15 @@ XENGINE_SERVICEAPP_EXIT: ModuleHelp_P2PClient_Destory(); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); + //销毁线程 + if (NULL != pSTDThread_Deamon) + { + pSTDThread_Deamon->join(); + } } #ifdef _MSC_BUILD WSACleanup(); #endif + getchar(); return 0; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj index 311b88c927a13539e90bdc29a257be706537db97..22c2d5d501e19cafd585cccc04cdf6adefa6d49d 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj @@ -165,6 +165,7 @@ + @@ -188,6 +189,7 @@ + diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj.filters b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj.filters index 5f8a1ae0d9d55fae311fb5f7989c00b1d34e67d1..18debd402d4db9b937c24ea6225640693c44d242 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj.filters +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_HttpApp.vcxproj.filters @@ -90,6 +90,9 @@ 源文件\XEngine_TaskPost + + 源文件\XEngine_TaskPost + @@ -155,5 +158,8 @@ 头文件\XEngine_TaskPost + + 头文件\XEngine_TaskPost + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskGet/TaskGet_Reload.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskGet/TaskGet_Reload.cpp index 1c83bc3c016bb05fe73e1af4f472b080722bb812..08ec70d51257f80d07b5ebe943229142b0466e6b 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskGet/TaskGet_Reload.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskGet/TaskGet_Reload.cpp @@ -14,7 +14,7 @@ bool HTTPTask_TaskGet_Reload(LPCXSTR lpszClientAddr, LPCXSTR lpszOPCode) if (0 == _ttxoi(lpszOPCode)) { - XEngine_Configure_Parament(0, NULL, &st_ServiceConfig); + XEngine_Configure_Parament(0, NULL); HttpProtocol_Server_SendMsgEx(xhHTTPPacket, tszMsgBuffer, &nMsgLen, &st_HDRParam); XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nMsgLen); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求操作配置重载成功,操作的配置:%s"), lpszClientAddr, lpszOPCode); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.cpp index 1d38b6ac114ede6f196d50b8ab9f0c8475d2d0dd..fecc0d16a2ac5ebb8710823933777edc41f32abb 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.cpp @@ -1,5 +1,27 @@ #include "../XEngine_Hdr.h" +static bool bRecord = false; +static XHANDLE xhSound = NULL; +static XHANDLE xhScreen = NULL; +static XNETHANDLE xhAudio = 0; +static XNETHANDLE xhVideo = 0; +static XHANDLE xhStream = NULL; + +void CALLBACK HTTPTask_TaskPost_CBVideo(uint8_t* punStringY, int nYLen, uint8_t* punStringU, int nULen, uint8_t* punStringV, int nVLen, XPVOID lParam) +{ + if (!StreamClient_StreamPush_PushVideo(xhStream, punStringY, nYLen, punStringU, nULen, punStringV, nVLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("屏幕采集器,推流编码失败,需要关闭推流服务,错误码:%lX"), StreamClient_GetLastError()); + } +} +void CALLBACK HTTPTask_TaskPost_CBAudio(uint8_t* punStringAudio, int nVLen, XPVOID lParam) +{ + if (!StreamClient_StreamPush_PushAudio(xhStream, punStringAudio, nVLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("音频采集器,推流编码失败,需要关闭推流服务,错误码:%lX"), StreamClient_GetLastError()); + } +} + bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nType) { int nSDLen = 0; @@ -251,6 +273,124 @@ bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s:请求上报信息成功,上报类型:%d"), lpszClientAddr, nBSType); } break; + case XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_RECORDSTART: + { + if (bRecord) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求屏幕录制失败,因为已经在录制中了"), lpszClientAddr); + return false; + } + XENGINE_PROTOCOL_AVINFO st_AVInfo; + memset(&st_AVInfo, '\0', sizeof(XENGINE_PROTOCOL_AVINFO)); + //启用音频 + if (1 == nBSType) + { +#ifdef _MSC_BUILD + xhSound = AVCollect_Audio_Init("dshow", "virtual-audio-capturer", HTTPTask_TaskPost_CBAudio); +#elif __linux__ + xhSound = AVCollect_Audio_Init("alsa", "virtual-audio-capturer", HTTPTask_TaskPost_CBAudio); +#else + xhSound = AVCollect_Audio_Init("avfoundation", "virtual-audio-capturer", HTTPTask_TaskPost_CBAudio); +#endif + if (NULL == xhSound) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,初始化音频采集器请求失败,错误码:%lX"), lpszClientAddr, AVCollect_GetLastError()); + return false; + } + st_AVInfo.st_AudioInfo.bEnable = true; + AVCollect_Audio_GetInfo(xhSound, &st_AVInfo); + //音频编码参数 + st_AVInfo.st_AudioInfo.enAVCodec = ENUM_XENGINE_AVCODEC_AUDIO_TYPE_AAC; + st_AVInfo.st_AudioInfo.nSampleFmt = ENUM_AVCOLLECT_AUDIO_SAMPLE_FMT_FLTP; + if (!AudioCodec_Stream_EnInit(&xhAudio, &st_AVInfo.st_AudioInfo)) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,初始化音频编码器失败,错误码:%lX"), lpszClientAddr, AudioCodec_GetLastError()); + return false; + } + int nLen = 0; + if (!AudioCodec_Stream_SetResample(xhAudio, &nLen, st_AVInfo.st_AudioInfo.nSampleRate, st_AVInfo.st_AudioInfo.nSampleRate, (ENUM_AVCOLLECT_AUDIOSAMPLEFORMAT)st_AVInfo.st_AudioInfo.nSampleFmt, ENUM_AVCOLLECT_AUDIO_SAMPLE_FMT_FLTP, st_AVInfo.st_AudioInfo.nChannel, st_AVInfo.st_AudioInfo.nChannel)) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,初始化音频重采样工具失败,错误码:%lX"), lpszClientAddr, AudioCodec_GetLastError()); + return false; + } + } + //屏幕采集 + AVCOLLECT_SCREENINFO st_AVScreen; + memset(&st_AVScreen, '\0', sizeof(AVCOLLECT_SCREENINFO)); + + st_AVScreen.nFrameRate = 24; + st_AVScreen.nPosX = 0; + st_AVScreen.nPosY = 0; +#ifdef _MSC_BUILD + xhScreen = AVCollect_Video_Init("gdigrab", "desktop", &st_AVScreen, HTTPTask_TaskPost_CBVideo); +#else + xhScreen = AVCollect_Video_Init("x11grab", ":0", &st_AVScreen, HTTPTask_TaskPost_CBVideo); +#endif + if (NULL == xhScreen) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,屏幕采集器请求失败,错误码:%lX"), lpszClientAddr, AVCollect_GetLastError()); + return false; + } + AVCollect_Video_GetInfo(xhScreen, &st_AVInfo); + + st_AVInfo.st_VideoInfo.enAVCodec = ENUM_XENGINE_AVCODEC_VIDEO_TYPE_H264; + if (!VideoCodec_Stream_EnInit(&xhVideo, &st_AVInfo.st_VideoInfo)) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,初始化视频编码器失败,错误码:%lX"), lpszClientAddr, VideoCodec_GetLastError()); + return false; + } + + xhStream = StreamClient_StreamPush_Init(tszSrcBuffer, &st_AVInfo); + if (NULL == xhStream) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,推流:%s 请求失败,错误码:%lX"), lpszClientAddr, tszSrcBuffer, StreamClient_GetLastError()); + return false; + } + bRecord = true; + AVCollect_Audio_Start(xhSound); + AVCollect_Video_Start(xhScreen); + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,开始屏幕录制推流:%s 请求成功"), lpszClientAddr, tszSrcBuffer); + } + break; + case XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_RECORDSTOP: + { + if (bRecord) + { + AVCollect_Video_Destory(xhScreen); + AVCollect_Audio_Destory(xhSound); + StreamClient_StreamPush_Close(xhStream); + VideoCodec_Stream_Destroy(xhVideo); + AudioCodec_Stream_Destroy(xhAudio); + bRecord = false; + } + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,停止屏幕录制推流请求成功"), lpszClientAddr); + } + break; case XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_NOTHINGTODO: break; default: diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.h b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.h index ea6368c5e9d4ef99524c47cce4ab15ce29770e68..33d84304a0d9055670ee4b6a2c9610c346b5d8f0 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_BackService.h @@ -1,3 +1,5 @@ #pragma once +void CALLBACK HTTPTask_TaskPost_CBVideo(uint8_t* punStringY, int nYLen, uint8_t* punStringU, int nULen, uint8_t* punStringV, int nVLen, XPVOID lParam); +void CALLBACK HTTPTask_TaskPost_CBAudio(uint8_t* punStringAudio, int nVLen, XPVOID lParam); bool HTTPTask_TaskPost_BackService(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nType); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_Deamon.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_Deamon.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b5ce920e4c3483f5b5e760fa994c4338b4e3e37 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_Deamon.cpp @@ -0,0 +1,169 @@ +#include "../XEngine_Hdr.h" + +void CALLBACK HTTPTask_TaskPost_Thread() +{ + while (bIsRun) + { + //轮询检测进程列表 + for (auto stl_ListIterator = st_DeamonAppConfig.stl_ListDeamonApp.begin(); stl_ListIterator != st_DeamonAppConfig.stl_ListDeamonApp.end(); stl_ListIterator++) + { + //是否启用 + if (!stl_ListIterator->bEnable) + { + continue; + } + //重试次数判断 + if (stl_ListIterator->nErrorTime > st_ServiceConfig.st_XTime.nDeamonTime) + { + stl_ListIterator->bEnable = false; + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("服务名:%s,由于超过指定启动失败次数:%d,这个服务检测功能被关闭..."), stl_ListIterator->tszAPPName, st_ServiceConfig.st_XTime.nDeamonTime); + continue; + } + + if (stl_ListIterator->nReTime > 0) + { + //进程自动重启 + __int64x nNowTime = time(NULL); + if ((nNowTime - stl_ListIterator->nStartTime) > stl_ListIterator->nReTime) + { + XLONG dwProcessId = 0; + XCHAR tszCmdExe[1024]; + + memset(tszCmdExe, '\0', sizeof(tszCmdExe)); + sprintf(tszCmdExe, "%s%s", stl_ListIterator->tszAPPPath, stl_ListIterator->tszAPPName); + + SystemApi_Process_Stop(stl_ListIterator->tszAPPName); + if (SystemApi_Process_CreateProcess(&dwProcessId, tszCmdExe)) + { + stl_ListIterator->nStartTime = time(NULL); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("自动重启,重启进程:%s 成功,进程ID:%d..."), stl_ListIterator->tszAPPName, dwProcessId); + } + else + { + stl_ListIterator->nErrorTime++; + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("自动重启,重启进程:%s 失败,错误码:%lX..."), stl_ListIterator->tszAPPName, SystemApi_GetLastError()); + } + } + } + else + { + //进程不存在才启动 + SYSTEMAPI_PROCESS_INFOMATION st_ProcessInfo; + memset(&st_ProcessInfo, '\0', sizeof(SYSTEMAPI_PROCESS_INFOMATION)); + if (SystemApi_Process_GetProcessInfo(&st_ProcessInfo, stl_ListIterator->tszAPPName)) + { + if (ENUM_SYSTEMSDK_PROCFILE_PROCFILE_PROCESS_STATE_ZOMBIE == st_ProcessInfo.en_ProcessState) + { +#ifndef _MSC_BUILD + //僵尸进程必须使用waitpid退出 + int nStatus = 0; + waitpid(st_ProcessInfo.nPid, &nStatus, 0); +#endif + } + else + { + continue; + } + } + + XLONG dwProcessId = 0; + XCHAR tszCmdExe[1024]; + + memset(tszCmdExe, '\0', sizeof(tszCmdExe)); + sprintf(tszCmdExe, "%s%s", stl_ListIterator->tszAPPPath, stl_ListIterator->tszAPPName); + + if (SystemApi_Process_CreateProcess(&dwProcessId, tszCmdExe)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, "崩溃重启,检查到进程不存在,启动进程:%s 成功,进程ID:%d...", stl_ListIterator->tszAPPName, dwProcessId); + } + else + { + stl_ListIterator->nErrorTime++; + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, "崩溃重启,检查到进程不存在,启动进程:%s 失败,错误码:%lX...", stl_ListIterator->tszAPPName, SystemApi_GetLastError()); + } + } + } + //休眠用户配置的时间 + std::this_thread::sleep_for(std::chrono::seconds(st_ServiceConfig.st_XTime.nTimeCheck)); + } +} +bool HTTPTask_TaskPost_Deamon(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen) +{ + int nSDLen = 0; + int nRVLen = 0; + XCHAR* ptszRVBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX); + XCHAR* ptszSDBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX); + RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam; //发送给客户端的参数 + XENGINE_DEAMONAPPINFO st_DeamonApp; + + memset(ptszRVBuffer, '\0', XENGINE_MEMORY_SIZE_MAX); + memset(ptszSDBuffer, '\0', XENGINE_MEMORY_SIZE_MAX); + + memset(&st_HDRParam, '\0', sizeof(RFCCOMPONENTS_HTTP_HDRPARAM)); + memset(&st_DeamonApp, '\0', sizeof(XENGINE_DEAMONAPPINFO)); + + st_HDRParam.nHttpCode = 200; //HTTP CODE码 + st_HDRParam.bIsClose = true; //收到回复后就关闭 + + if (st_ServiceConfig.st_XVerifcation.bDeamon) + { + XCHAR tszUserName[MAX_PATH]; + XCHAR tszUserPass[MAX_PATH]; + + memset(tszUserName, '\0', sizeof(tszUserName)); + memset(tszUserPass, '\0', sizeof(tszUserPass)); + + ModuleProtocol_Parse_Verifcation(lpszMsgBuffer, nMsgLen, tszUserName, tszUserPass); + + if (0 != _tcsxnicmp(st_ServiceConfig.st_XVerifcation.tszUserName, tszUserName, _tcsxlen(st_ServiceConfig.st_XVerifcation.tszUserName))) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求守护协议失败,用户验证失败,用户名错误,提供的用户名:%s"), lpszClientAddr, tszUserName); + return false; + } + if (0 != _tcsxnicmp(st_ServiceConfig.st_XVerifcation.tszUserPass, tszUserPass, _tcsxlen(st_ServiceConfig.st_XVerifcation.tszUserPass))) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求守护协议失败,解析协议失败,错误码:%lX"), lpszClientAddr, tszUserPass); + return false; + } + } + + if (!ModuleProtocol_Parse_Deamon(lpszMsgBuffer, nMsgLen, st_DeamonApp.tszAPPName, st_DeamonApp.tszAPPPath, &st_DeamonApp.nReTime, &st_DeamonApp.bEnable)) + { + st_HDRParam.nHttpCode = 400; + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求解析守护协议失败,解析协议失败,错误码:%lX"), lpszClientAddr, ModuleProtocol_GetLastError()); + return false; + } + + if (st_DeamonApp.bEnable) + { + st_DeamonAppConfig.stl_ListDeamonApp.push_back(st_DeamonApp); + } + else + { + for (auto stl_ListIterator = st_DeamonAppConfig.stl_ListDeamonApp.begin(); stl_ListIterator != st_DeamonAppConfig.stl_ListDeamonApp.end(); stl_ListIterator++) + { + if (0 == _tcsxnicmp(stl_ListIterator->tszAPPName, stl_ListIterator->tszAPPName, _tcsxlen(stl_ListIterator->tszAPPName)) && (0 == _tcsxnicmp(stl_ListIterator->tszAPPPath, st_DeamonApp.tszAPPPath, _tcsxlen(stl_ListIterator->tszAPPPath)))) + { + st_DeamonAppConfig.stl_ListDeamonApp.erase(stl_ListIterator); + break; + } + } + } + HttpProtocol_Server_SendMsgEx(xhHTTPPacket, ptszSDBuffer, &nSDLen, &st_HDRParam); + XEngine_Network_Send(lpszClientAddr, ptszSDBuffer, nSDLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求解析守护协议成功,协议类型:%d,进程名称:%s"), lpszClientAddr, st_DeamonApp.bEnable, st_DeamonApp.tszAPPName); + + free(ptszRVBuffer); + free(ptszSDBuffer); + ptszSDBuffer = NULL; + ptszRVBuffer = NULL; + return true; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_Deamon.h b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_Deamon.h new file mode 100644 index 0000000000000000000000000000000000000000..999901cdbf7d12854df3f62c201969981aebaed7 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_HttpApp/XEngine_TaskPost/TaskPost_Deamon.h @@ -0,0 +1,4 @@ +#pragma once + +void CALLBACK HTTPTask_TaskPost_Thread(); +bool HTTPTask_TaskPost_Deamon(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen); \ No newline at end of file diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h index da503764bad0c3ce84203930a01a1dfecb05cf60..6159646b7b4a6de25a32e821a423980210924a52 100644 --- a/XEngine_Source/XEngine_UserProtocol.h +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -90,6 +90,8 @@ typedef enum #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_SHUTDOWN 0x5008 //远程关闭计算机 #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_ECMD 0x5009 //执行命令 #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_REPORT 0x5010 //报告信息 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_RECORDSTART 0x5011 //开始视频录制 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_BS_RECORDSTOP 0x5012 //停止视频录制 //P2XP协议 #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_P2XP_REQLOGIN 0x6001 //登录 #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_P2XP_REPLOGIN 0x6002