modify ipc

This commit is contained in:
jiegeaiai 2024-12-04 02:04:57 +08:00
parent 8082b9b003
commit 63b89172c0
26 changed files with 176 additions and 12 deletions

22
ipc.sln
View File

@ -1,9 +1,9 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 17
VisualStudioVersion = 16.0.32002.261 VisualStudioVersion = 17.12.35521.163 d17.12
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ipc", "ipc\ipc.vcxproj", "{439884C2-9C07-434F-8B84-B51378F4A83E}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ipc", "ipc\ipc.vcxproj", "{DD8845F5-6D92-41D8-992A-593BC8DB9FF5}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -13,14 +13,14 @@ Global
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x64.ActiveCfg = Debug|x64 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Debug|x64.ActiveCfg = Debug|x64
{439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x64.Build.0 = Debug|x64 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Debug|x64.Build.0 = Debug|x64
{439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x86.ActiveCfg = Debug|Win32 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Debug|x86.ActiveCfg = Debug|Win32
{439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x86.Build.0 = Debug|Win32 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Debug|x86.Build.0 = Debug|Win32
{439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x64.ActiveCfg = Release|x64 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Release|x64.ActiveCfg = Release|x64
{439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x64.Build.0 = Release|x64 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Release|x64.Build.0 = Release|x64
{439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x86.ActiveCfg = Release|Win32 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Release|x86.ActiveCfg = Release|Win32
{439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x86.Build.0 = Release|Win32 {DD8845F5-6D92-41D8-992A-593BC8DB9FF5}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -16,7 +16,7 @@ Ipc::Ipc(const char* reader_name, const char* writer_name) noexcept
: reader_name_(reader_name) : reader_name_(reader_name)
, writer_name_(writer_name) { , writer_name_(writer_name) {
sender_ = std::make_unique<ipc::channel>(reader_name_.c_str(), ipc::sender); sender_ = std::make_unique<ipc::channel>(reader_name_.c_str(), ipc::sender);
printf("%s, %s", reader_name, writer_name); fprintf(stderr, "%s, %s\n", reader_name, writer_name);
} }
Ipc::~Ipc() { Ipc::~Ipc() {
@ -58,6 +58,14 @@ bool Ipc::send(const char* data, unsigned int size) {
return sender_->send(data, size); return sender_->send(data, size);
} }
void Ipc::reConnect() {
sender_->reconnect(ipc::sender);
if (receiver_) {
receiver_->disconnect();
receiver_->reconnect(ipc::receiver);
}
}
void Ipc::registReadCallback(const std::shared_ptr<IReaderCallback>& reader) { void Ipc::registReadCallback(const std::shared_ptr<IReaderCallback>& reader) {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);

View File

@ -18,6 +18,7 @@ public:
bool listen(); bool listen();
void stop(); void stop();
bool send(const char* data, unsigned int size); bool send(const char* data, unsigned int size);
void reConnect();
void registReadCallback(const std::shared_ptr<IReaderCallback>& reader); void registReadCallback(const std::shared_ptr<IReaderCallback>& reader);
void unregistReadCallback(const std::shared_ptr<IReaderCallback>& reader); void unregistReadCallback(const std::shared_ptr<IReaderCallback>& reader);

View File

@ -12,6 +12,7 @@ extern "C" {
IPC_EXPORT bool __stdcall initialize(const char* sender_name, const char* receiver_name); IPC_EXPORT bool __stdcall initialize(const char* sender_name, const char* receiver_name);
IPC_EXPORT void __stdcall uninitialize(); IPC_EXPORT void __stdcall uninitialize();
IPC_EXPORT void __stdcall reConnect();
IPC_EXPORT bool __stdcall listen(); IPC_EXPORT bool __stdcall listen();
IPC_EXPORT bool __stdcall send(const char* data, unsigned int size); IPC_EXPORT bool __stdcall send(const char* data, unsigned int size);
IPC_EXPORT bool __stdcall setReaderCallback(ReaderCallbackFunc callback); IPC_EXPORT bool __stdcall setReaderCallback(ReaderCallbackFunc callback);

149
ipc/ipc.vcxproj Normal file
View File

@ -0,0 +1,149 @@
<?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>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{dd8845f5-6d92-41d8-992a-593bc8db9ff5}</ProjectGuid>
<RootNamespace>ipc</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>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</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>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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|x64'">
<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>
</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>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;WIN32;_IPC_EXPORT_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>D:\Learn\ipc\ipc\3rdparty\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>D:\Learn\ipc\ipc\3rdparty\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ipcd.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WIN32;_IPC_EXPORT_;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>D:\Learn\ipc\ipc\3rdparty\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>D:\Learn\ipc\ipc\3rdparty\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ipc.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ipc.cpp" />
<ClCompile Include="ipclib.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\config.h" />
<ClInclude Include="include\ipclib.h" />
<ClInclude Include="Ipc.h" />
<ClInclude Include="ReadCallback.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -48,6 +48,11 @@ bool __stdcall initialize(const char* sender_name, const char* receiver_name) {
g_ipc.reset(); g_ipc.reset();
} }
void __stdcall reConnect() {
assert(g_ipc);
return g_ipc->reConnect();
}
bool __stdcall listen() { bool __stdcall listen() {
assert(g_ipc); assert(g_ipc);
return g_ipc->listen(); return g_ipc->listen();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.