Skip to content

Commit 36b5944

Browse files
committed
added:log exmaple
1 parent 86e8b27 commit 36b5944

File tree

6 files changed

+315
-1
lines changed

6 files changed

+315
-1
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#ifdef _MSC_BUILD
2+
#include <Windows.h>
3+
#include <tchar.h>
4+
#pragma comment(lib,"Ws2_32")
5+
#pragma comment(lib,"jsoncpp")
6+
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
7+
#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient")
8+
#endif
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
#include <inttypes.h>
13+
#include <json/json.h>
14+
#include <XEngine_Include/XEngine_CommHdr.h>
15+
#include <XEngine_Include/XEngine_ProtocolHdr.h>
16+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
17+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
18+
#include <XEngine_Include/XEngine_NetHelp/APIClient_Define.h>
19+
#include <XEngine_Include/XEngine_NetHelp/APIClient_Error.h>
20+
21+
//需要优先配置XEngine
22+
//WINDOWS支持VS2022 x64 debug 编译调试
23+
//linux::g++ -std=c++17 -Wall -g APPClient_XLogExample.cpp -o APPClient_XLogExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIClient
24+
//macos::g++ -std=c++17 -Wall -g APPClient_XLogExample.cpp -o APPClient_XLogExample.exe -lXEngine_BaseLib -lNetHelp_APIClient
25+
26+
LPCTSTR lpszTableName = _T("xengine");
27+
28+
int test_create()
29+
{
30+
int nLen = 0;
31+
int nCode = 0;
32+
LPCTSTR lpszAPIUrl = _T("http://127.0.0.1:5501/api?function=log&params1=0");
33+
34+
Json::Value st_JsonRoot;
35+
st_JsonRoot["tszTableName"] = lpszTableName;
36+
37+
TCHAR* ptszMsgBuffer = NULL;
38+
if (!APIClient_Http_Request(_T("POST"), lpszAPIUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
39+
{
40+
printf("发送投递失败!\n");
41+
return 0;
42+
}
43+
printf("接受到数据,大小:%d,内容:%s\n", nLen, ptszMsgBuffer);
44+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
45+
46+
return 0;
47+
}
48+
int test_insert()
49+
{
50+
int nLen = 0;
51+
int nCode = 0;
52+
LPCTSTR lpszAPIUrl = _T("http://127.0.0.1:5501/api?function=log&params1=1");
53+
LPCTSTR lpszMsgBuffer = _T("adwdad12d21d123d132rd213d32f23df23rf");
54+
55+
Json::Value st_JsonRoot;
56+
Json::StreamWriterBuilder st_JsonBuilder;
57+
st_JsonRoot["tszTableName"] = lpszTableName;
58+
st_JsonRoot["tszLogBuffer"] = lpszMsgBuffer;
59+
st_JsonRoot["nLogSize"] = _tcslen(lpszMsgBuffer);
60+
61+
st_JsonRoot["tszFileName"] = "file.cpp";
62+
st_JsonRoot["tszFuncName"] = "xengine_file_insert";
63+
st_JsonRoot["tszLogTimer"] = "2023-01-13 22:10:01";
64+
st_JsonRoot["nLogLine"] = 102;
65+
st_JsonRoot["nLogLevel"] = 4;
66+
67+
st_JsonBuilder["emitUTF8"] = true;
68+
69+
TCHAR* ptszMsgBuffer = NULL;
70+
if (!APIClient_Http_Request(_T("POST"), lpszAPIUrl, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), &nCode, &ptszMsgBuffer, &nLen))
71+
{
72+
printf("发送投递失败!\n");
73+
return 0;
74+
}
75+
printf("接受到数据,大小:%d,内容:%s\n", nLen, ptszMsgBuffer);
76+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
77+
78+
return 0;
79+
}
80+
int test_query()
81+
{
82+
int nLen = 0;
83+
int nCode = 0;
84+
LPCTSTR lpszAPIUrl = _T("http://127.0.0.1:5501/api?function=log&params1=2");
85+
86+
Json::Value st_JsonRoot;
87+
st_JsonRoot["tszTableName"] = lpszTableName;
88+
st_JsonRoot["tszTimeStart"] = "2023-01-13 22:10:00";
89+
st_JsonRoot["tszTimeEnd"] = "2023-01-13 22:10:02";
90+
91+
TCHAR* ptszMsgBuffer = NULL;
92+
if (!APIClient_Http_Request(_T("POST"), lpszAPIUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
93+
{
94+
printf("发送投递失败!\n");
95+
return 0;
96+
}
97+
printf("接受到数据,大小:%d,内容:%s\n", nLen, ptszMsgBuffer);
98+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
99+
100+
return 0;
101+
}
102+
int test_delete()
103+
{
104+
int nLen = 0;
105+
int nCode = 0;
106+
LPCTSTR lpszAPIUrl = _T("http://127.0.0.1:5501/api?function=log&params1=3");
107+
108+
Json::Value st_JsonRoot;
109+
st_JsonRoot["tszTableName"] = lpszTableName;
110+
111+
TCHAR* ptszMsgBuffer = NULL;
112+
if (!APIClient_Http_Request(_T("POST"), lpszAPIUrl, st_JsonRoot.toStyledString().c_str(), &nCode, &ptszMsgBuffer, &nLen))
113+
{
114+
printf("发送投递失败!\n");
115+
return 0;
116+
}
117+
printf("接受到数据,大小:%d,内容:%s\n", nLen, ptszMsgBuffer);
118+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
119+
120+
return 0;
121+
}
122+
123+
int main()
124+
{
125+
#ifdef _MSC_BUILD
126+
WSADATA st_WSAData;
127+
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
128+
#endif
129+
test_create();
130+
test_insert();
131+
test_insert();
132+
test_query();
133+
test_delete();
134+
135+
#ifdef _MSC_BUILD
136+
WSACleanup();
137+
#endif
138+
return 0;
139+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{ff3ef369-c7a8-4866-8cf3-fc38a36ee6af}</ProjectGuid>
25+
<RootNamespace>APPClientXLogExample</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>MultiByte</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
74+
<IncludePath>$(XEngine_Include);../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(IncludePath)</IncludePath>
75+
<LibraryPath>$(XEngine_Lib64);../../XEngine_Source/x64/Debug;$(LibraryPath)</LibraryPath>
76+
</PropertyGroup>
77+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
78+
<ClCompile>
79+
<WarningLevel>Level3</WarningLevel>
80+
<SDLCheck>true</SDLCheck>
81+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
82+
<ConformanceMode>true</ConformanceMode>
83+
</ClCompile>
84+
<Link>
85+
<SubSystem>Console</SubSystem>
86+
<GenerateDebugInformation>true</GenerateDebugInformation>
87+
</Link>
88+
</ItemDefinitionGroup>
89+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
90+
<ClCompile>
91+
<WarningLevel>Level3</WarningLevel>
92+
<FunctionLevelLinking>true</FunctionLevelLinking>
93+
<IntrinsicFunctions>true</IntrinsicFunctions>
94+
<SDLCheck>true</SDLCheck>
95+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
96+
<ConformanceMode>true</ConformanceMode>
97+
</ClCompile>
98+
<Link>
99+
<SubSystem>Console</SubSystem>
100+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
101+
<OptimizeReferences>true</OptimizeReferences>
102+
<GenerateDebugInformation>true</GenerateDebugInformation>
103+
</Link>
104+
</ItemDefinitionGroup>
105+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
106+
<ClCompile>
107+
<WarningLevel>Level3</WarningLevel>
108+
<SDLCheck>true</SDLCheck>
109+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
110+
<ConformanceMode>true</ConformanceMode>
111+
</ClCompile>
112+
<Link>
113+
<SubSystem>Console</SubSystem>
114+
<GenerateDebugInformation>true</GenerateDebugInformation>
115+
</Link>
116+
</ItemDefinitionGroup>
117+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
118+
<ClCompile>
119+
<WarningLevel>Level3</WarningLevel>
120+
<FunctionLevelLinking>true</FunctionLevelLinking>
121+
<IntrinsicFunctions>true</IntrinsicFunctions>
122+
<SDLCheck>true</SDLCheck>
123+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124+
<ConformanceMode>true</ConformanceMode>
125+
</ClCompile>
126+
<Link>
127+
<SubSystem>Console</SubSystem>
128+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
129+
<OptimizeReferences>true</OptimizeReferences>
130+
<GenerateDebugInformation>true</GenerateDebugInformation>
131+
</Link>
132+
</ItemDefinitionGroup>
133+
<ItemGroup>
134+
<ClCompile Include="APPClient_XLogExample.cpp" />
135+
</ItemGroup>
136+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
137+
<ImportGroup Label="ExtensionTargets">
138+
</ImportGroup>
139+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="APPClient_XLogExample.cpp">
19+
<Filter>源文件</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

XEngine_APPClient/VSCopy-x64.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_BaseLib.dll" "./"
22
copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_OPenSsl.dll" "./"
3-
copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIHelp.dll" "./"
3+
copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIClient.dll" "./"
44

55
copy /y "%XEngine_Lib64%\XEngine_HelpComponents\zlib1.dll" "./"
66
copy /y "%XEngine_Lib64%\XEngine_LibEx\libssl-1_1-x64.dll" "./"

XEngine_APPClient/XEngine_APPClient.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_LuaPluginExample"
2727
EndProject
2828
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_LibPluginExample", "APPClient_LibPluginExample\APPClient_LibPluginExample.vcxproj", "{0464EA5F-1E86-40BF-B692-394CF9F5CC67}"
2929
EndProject
30+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_XLogExample", "APPClient_XLogExample\APPClient_XLogExample.vcxproj", "{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|x64 = Debug|x64
@@ -131,6 +133,14 @@ Global
131133
{0464EA5F-1E86-40BF-B692-394CF9F5CC67}.Release|x64.Build.0 = Release|x64
132134
{0464EA5F-1E86-40BF-B692-394CF9F5CC67}.Release|x86.ActiveCfg = Release|Win32
133135
{0464EA5F-1E86-40BF-B692-394CF9F5CC67}.Release|x86.Build.0 = Release|Win32
136+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Debug|x64.ActiveCfg = Debug|x64
137+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Debug|x64.Build.0 = Debug|x64
138+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Debug|x86.ActiveCfg = Debug|Win32
139+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Debug|x86.Build.0 = Debug|Win32
140+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Release|x64.ActiveCfg = Release|x64
141+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Release|x64.Build.0 = Release|x64
142+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Release|x86.ActiveCfg = Release|Win32
143+
{FF3EF369-C7A8-4866-8CF3-FC38A36EE6AF}.Release|x86.Build.0 = Release|Win32
134144
EndGlobalSection
135145
GlobalSection(SolutionProperties) = preSolution
136146
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)