diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d9b2a5..1eb24a0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,29 +10,31 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") if(NOT MSVC) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() +add_definitions(-DLIBIPC_CPP_14 -DLIBIPC_CPP_17) + if (MSVC) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - if (LIBIPC_USE_STATIC_CRT) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() - else() - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}") - string(REPLACE "/MTd" "/MDd" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() - endif() + set(CompilerFlags + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + ) + if (LIBIPC_USE_STATIC_CRT) + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") + string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() + else() + foreach(CompilerFlag ${CompilerFlags}) + string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}") + string(REPLACE "/MTd" "/MDd" ${CompilerFlag} "${${CompilerFlag}}") + endforeach() + endif() endif() set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) @@ -45,23 +47,23 @@ add_definitions(-DUNICODE -D_UNICODE) add_subdirectory(src) if (LIBIPC_BUILD_TESTS) - set(GOOGLETEST_VERSION 1.10.0) - if (LIBIPC_USE_STATIC_CRT) - set(gtest_force_shared_crt OFF) - else() - set(gtest_force_shared_crt ON) - endif() - add_subdirectory(3rdparty/gtest) - add_subdirectory(test) + set(GOOGLETEST_VERSION 1.10.0) + if (LIBIPC_USE_STATIC_CRT) + set(gtest_force_shared_crt OFF) + else() + set(gtest_force_shared_crt ON) + endif() + add_subdirectory(3rdparty/gtest) + add_subdirectory(test) endif() -if (LIBIPC_BUILD_DEMOS) - add_subdirectory(demo/chat) - add_subdirectory(demo/msg_que) - add_subdirectory(demo/send_recv) -endif() +# if (LIBIPC_BUILD_DEMOS) +# add_subdirectory(demo/chat) +# add_subdirectory(demo/msg_que) +# add_subdirectory(demo/send_recv) +# endif() install( - DIRECTORY "include/" - DESTINATION "include" + DIRECTORY "include/" + DESTINATION "include" ) diff --git a/include/libipc/buffer.h b/include/libipc/buffer.h deleted file mode 100755 index 3f8c229..0000000 --- a/include/libipc/buffer.h +++ /dev/null @@ -1,68 +0,0 @@ -#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/include/libipc/condition.h b/include/libipc/condition.h deleted file mode 100644 index a4e2ac3..0000000 --- a/include/libipc/condition.h +++ /dev/null @@ -1,39 +0,0 @@ -#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(ipc::sync::mutex &mtx) noexcept; - bool broadcast(ipc::sync::mutex &mtx) noexcept; - -private: - class condition_; - condition_* p_; -}; - -} // namespace sync -} // namespace ipc diff --git a/include/libipc/def.h b/include/libipc/def.h index 8c1a72b..b3ebd6f 100755 --- a/include/libipc/def.h +++ b/include/libipc/def.h @@ -1,68 +1,19 @@ +/** + * @file def.h + * @author mutouyun (orz@orzz.org) + * @brief Define the trivial configuration information + * @date 2022-02-27 + */ #pragma once #include #include -#include // std::numeric_limits -#include -#include -namespace ipc { +#define LIBIPC_NAMESPACE_BEG_ namespace ipc { +#define LIBIPC_NAMESPACE_END_ } -// 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; +LIBIPC_NAMESPACE_BEG_ // 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