diff --git a/ipc.sln b/ipc.sln new file mode 100644 index 0000000..0ac205d --- /dev/null +++ b/ipc.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32002.261 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ipc", "ipc\ipc.vcxproj", "{439884C2-9C07-434F-8B84-B51378F4A83E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x64.ActiveCfg = Debug|x64 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x64.Build.0 = Debug|x64 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x86.ActiveCfg = Debug|Win32 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Debug|x86.Build.0 = Debug|Win32 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x64.ActiveCfg = Release|x64 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x64.Build.0 = Release|x64 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x86.ActiveCfg = Release|Win32 + {439884C2-9C07-434F-8B84-B51378F4A83E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E136A803-5D70-4B88-B6DD-063E35B4710E} + EndGlobalSection +EndGlobal diff --git a/ipc/3rdparty/include/libipc/buffer.h b/ipc/3rdparty/include/libipc/buffer.h new file mode 100644 index 0000000..3f8c229 --- /dev/null +++ b/ipc/3rdparty/include/libipc/buffer.h @@ -0,0 +1,68 @@ +#pragma once + +#include +#include +#include +#include + +#include "libipc/export.h" +#include "libipc/def.h" + +namespace ipc { + +class IPC_EXPORT buffer { +public: + using destructor_t = void (*)(void*, std::size_t); + + buffer(); + + buffer(void* p, std::size_t s, destructor_t d); + buffer(void* p, std::size_t s, destructor_t d, void* additional); + buffer(void* p, std::size_t s); + + template + explicit buffer(byte_t const (& data)[N]) + : buffer(data, sizeof(data)) { + } + explicit buffer(char const & c); + + buffer(buffer&& rhs); + ~buffer(); + + void swap(buffer& rhs); + buffer& operator=(buffer rhs); + + bool empty() const noexcept; + + void * data() noexcept; + void const * data() const noexcept; + + template + T get() const { return T(data()); } + + std::size_t size() const noexcept; + + std::tuple to_tuple() { + return std::make_tuple(data(), size()); + } + + std::tuple to_tuple() const { + return std::make_tuple(data(), size()); + } + + std::vector to_vector() const { + return { + get(), + get() + size() + }; + } + + friend IPC_EXPORT bool operator==(buffer const & b1, buffer const & b2); + friend IPC_EXPORT bool operator!=(buffer const & b1, buffer const & b2); + +private: + class buffer_; + buffer_* p_; +}; + +} // namespace ipc diff --git a/ipc/3rdparty/include/libipc/condition.h b/ipc/3rdparty/include/libipc/condition.h new file mode 100644 index 0000000..d3b3a59 --- /dev/null +++ b/ipc/3rdparty/include/libipc/condition.h @@ -0,0 +1,39 @@ +#pragma once + +#include // std::uint64_t + +#include "libipc/export.h" +#include "libipc/def.h" +#include "libipc/mutex.h" + +namespace ipc { +namespace sync { + +class IPC_EXPORT condition { + condition(condition const &) = delete; + condition &operator=(condition const &) = delete; + +public: + condition(); + explicit condition(char const *name); + ~condition(); + + void const *native() const noexcept; + void *native() noexcept; + + bool valid() const noexcept; + + bool open(char const *name) noexcept; + void close() noexcept; + + bool wait(ipc::sync::mutex &mtx, std::uint64_t tm = ipc::invalid_value) noexcept; + bool notify() noexcept; + bool broadcast() noexcept; + +private: + class condition_; + condition_* p_; +}; + +} // namespace sync +} // namespace ipc diff --git a/ipc/3rdparty/include/libipc/def.h b/ipc/3rdparty/include/libipc/def.h new file mode 100644 index 0000000..8c1a72b --- /dev/null +++ b/ipc/3rdparty/include/libipc/def.h @@ -0,0 +1,68 @@ +#pragma once + +#include +#include +#include // std::numeric_limits +#include +#include + +namespace ipc { + +// types + +using byte_t = std::uint8_t; + +template +struct uint; + +template <> struct uint<8 > { using type = std::uint8_t ; }; +template <> struct uint<16> { using type = std::uint16_t; }; +template <> struct uint<32> { using type = std::uint32_t; }; +template <> struct uint<64> { using type = std::uint64_t; }; + +template +using uint_t = typename uint::type; + +// constants + +enum : std::uint32_t { + invalid_value = (std::numeric_limits::max)(), + default_timeout = 100, // ms +}; + +enum : std::size_t { + data_length = 64, + large_msg_limit = data_length, + large_msg_align = 1024, + large_msg_cache = 32, +}; + +enum class relat { // multiplicity of the relationship + single, + multi +}; + +enum class trans { // transmission + unicast, + broadcast +}; + +// producer-consumer policy flag + +template +struct wr {}; + +template +struct relat_trait; + +template +struct relat_trait> { + constexpr static bool is_multi_producer = (Rp == relat::multi); + constexpr static bool is_multi_consumer = (Rc == relat::multi); + constexpr static bool is_broadcast = (Ts == trans::broadcast); +}; + +template