Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengtianzuo committed Apr 18, 2024
1 parent 8846a2f commit 8d14bb5
Show file tree
Hide file tree
Showing 121 changed files with 5,418 additions and 33 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.cpp linguist-language=C++
*.cs linguist-language=C#
*.go linguist-language=GO
*.java linguist-language=Java
*.js linguist-language=JavaScript
*.php linguist-language=PHP
*.py linguist-language=Python
*.rb linguist-language=Ruby
*.rust linguist-language=Rust
*.vb linguist-language=Visual Basic .NET
32 changes: 0 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +0,0 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
1,228 changes: 1,227 additions & 1 deletion README.md

Large diffs are not rendered by default.

1,226 changes: 1,226 additions & 0 deletions README_en.md

Large diffs are not rendered by default.

Binary file added bin/android/Debug/libtianzuo.Zhuiri.so
Binary file not shown.
Binary file added bin/android/Release/libtianzuo.Zhuiri.so
Binary file not shown.
Binary file added bin/ios/Release/libtianzuo.Zhuiri.dylib
Binary file not shown.
Binary file added bin/linux/Debug/libtianzuo.Zhuiri.so
Binary file not shown.
Binary file added bin/linux/Release/libtianzuo.Zhuiri.so
Binary file not shown.
Binary file added bin/mac/Debug/libtianzuo.Zhuiri.dylib
Binary file not shown.
Binary file added bin/mac/Release/libtianzuo.Zhuiri.dylib
Binary file not shown.
Binary file added bin/windows/msvc140/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc140/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc140/Release/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc140/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc140_64/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc140_64/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file not shown.
Binary file added bin/windows/msvc140_64/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc141/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc141/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc141/Release/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc141/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc141_64/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc141_64/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file not shown.
Binary file added bin/windows/msvc141_64/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc142/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc142/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc142/Release/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc142/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc142_64/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc142_64/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file not shown.
Binary file added bin/windows/msvc142_64/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc143/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc143/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc143/Release/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc143/Release/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file added bin/windows/msvc143_64/Debug/tianzuo.Zhuiri.dll
Binary file not shown.
Binary file added bin/windows/msvc143_64/Debug/tianzuo.Zhuiri.lib
Binary file not shown.
Binary file not shown.
Binary file added bin/windows/msvc143_64/Release/tianzuo.Zhuiri.lib
Binary file not shown.
119 changes: 119 additions & 0 deletions demo/cpp/tianzuo.ZhuiriTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <iostream>
#include <thread>
#include "../../include/tianzuo.ZhuiriInterface.h" // 接口头文件 interface heaher file

#include <winsock.h>
#pragma comment(lib, "ws2_32.lib")

// 数据回调函数
void msg_recv_callback(void* context, Zhuiri_data_pkg_pointer data_pkg) {
Zhuiri_data_pkg_struct data_new;
memcpy(&data_new, data_pkg, sizeof(Zhuiri_data_pkg_struct));
int send_size = data_pkg->m_data.get_send_size();
if (send_size > Zhuiri_content_size) {
char* send_data = new char[static_cast<unsigned int>(send_size)];
memcpy(send_data, data_pkg->get_send_data(), static_cast<unsigned int>(send_size));
data_new.set_send_data(send_data);
}
else {
data_new.set_send_data(data_new.m_data.m_data);
}
tianzuo_DataQueue* const dataQueue = reinterpret_cast<tianzuo_DataQueue*>(context);
dataQueue->push_back(&data_new);
}

// 接收线程
void recv_thread(tianzuo_DataQueue* data_queue_recv) {
while (1) {
Zhuiri_data_pkg_struct recv_msg;
if (data_queue_recv->pop_up(&recv_msg) != Zhuiri_queue_error_code_success) {
//std::cout << "pop_up no data" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(200));
continue;
}

std::cout << "recv data: " << recv_msg.m_data.m_data << std::endl;
if (strcmp(recv_msg.m_data.m_data, "send data 99") == 0) {
std::cout << "recv done" << std::endl;
return;
}
}
}

int main() {

// 初始化接口 initialize the interface
std::unique_ptr<tianzuo_ZhuiriInterface> zhuiri_interface(new tianzuo_ZhuiriInterface());

// 创建实例 create an instance
tianzuo_ZhuiriInt* zhuiri = zhuiri_interface->initialize();

// 初始化数据队列接口 initialize the data queue interface
std::unique_ptr<tianzuo_DataQueueInterface> data_queue_interface(new tianzuo_DataQueueInterface());

// 创建数据队列实例 create an data queue instance
tianzuo_DataQueue* data_queue_recv = data_queue_interface->initialize();

// 初始化实例 initialize the instance
int port = 6666;
int error_code = zhuiri->initialize(
nullptr, port, reinterpret_cast<void*>(msg_recv_callback),
data_queue_recv, 6000, false);
if (error_code != Zhuiri_error_code_success) {
std::cout << "initialize error: " << error_code;

// 释放接口 terminate the interface
if (data_queue_interface != nullptr && data_queue_recv != nullptr) {
data_queue_interface->terminate(&data_queue_recv);
}
if (zhuiri_interface != nullptr && zhuiri != nullptr) {
zhuiri_interface->terminate(&zhuiri);
}
return -1;
}

// 设置默认参数 set default parameters
Zhuiri_param_struct param(0, 5168, 1024, 2280, 3, 5, 600);
zhuiri->set_param(&param);

// 启动接收线程 start receiving thread
std::thread recv_th(recv_thread, data_queue_recv);

// 开始发送数据 start sending data
int data_size = 1024;
char data[1024];
memset(data, 0, data_size);
int ip = ntohl(inet_addr("127.0.0.1"));
for (size_t i = 0; i < 100; i++) {
//std::cout << "start send index: " << i << std::endl;
sprintf_s(data, data_size, "send data %d", i);
int data_len = strlen(data);
Zhuiri_send_param_struct send_param(0, ip, port, Zhuiri_data_sign_reliable, 7788, data, data_len);
error_code = zhuiri->send(&send_param);
if (error_code != Zhuiri_error_code_success) {
std::cout << "send error: " << error_code;

// 释放接口 terminate the interface
if (data_queue_interface != nullptr && data_queue_recv != nullptr) {
data_queue_interface->terminate(&data_queue_recv);
}
if (zhuiri_interface != nullptr && zhuiri != nullptr) {
zhuiri_interface->terminate(&zhuiri);
}
return -1;
}
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
std::cout << "send done" << std::endl;
recv_th.join();

// 释放接口 terminate the interface
if (data_queue_interface != nullptr && data_queue_recv != nullptr) {
data_queue_interface->terminate(&data_queue_recv);
}
if (zhuiri_interface != nullptr && zhuiri != nullptr) {
zhuiri_interface->terminate(&zhuiri);
}

return 0;
}
25 changes: 25 additions & 0 deletions demo/cpp/tianzuo.ZhuiriTest.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tianzuo.ZhuiriTest", "tianzuo.ZhuiriTest.vcxproj", "{8C4CFB40-973E-4E8D-A34F-CB3DBEEE5663}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8C4CFB40-973E-4E8D-A34F-CB3DBEEE5663}.Debug|x86.ActiveCfg = Debug|Win32
{8C4CFB40-973E-4E8D-A34F-CB3DBEEE5663}.Debug|x86.Build.0 = Debug|Win32
{8C4CFB40-973E-4E8D-A34F-CB3DBEEE5663}.Release|x86.ActiveCfg = Release|Win32
{8C4CFB40-973E-4E8D-A34F-CB3DBEEE5663}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08A088A8-FCB0-4535-BC8B-541A9679F3F0}
EndGlobalSection
EndGlobal
84 changes: 84 additions & 0 deletions demo/cpp/tianzuo.ZhuiriTest.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{8c4cfb40-973e-4e8d-a34f-cb3dbeee5663}</ProjectGuid>
<RootNamespace>tianzuoZhuiriTest</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>tianzuo.Zhuiri.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\bin\windows\msvc143\Debug\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>tianzuo.Zhuiri.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\..\bin\windows\msvc143\Release\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="tianzuo.ZhuiriTest.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
6 changes: 6 additions & 0 deletions demo/cpp/tianzuo.ZhuiriTest.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="tianzuo.ZhuiriTest.cpp" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions demo/cpp/tianzuo.ZhuiriTest.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
Loading

0 comments on commit 8d14bb5

Please sign in to comment.