From 29188f939c1c4b6629d9abe1d85465ba972abb64 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 15 May 2022 19:35:58 +0800 Subject: [PATCH] add: [mmap] add interface declarations --- include/libipc/def.h | 3 ++- include/libipc/mmap.h | 21 ++++++++++++++++++- ...tect_plat.cpp => test_imp_detect_plat.cpp} | 0 test/{test_result.cpp => test_imp_result.cpp} | 0 ...{test_utility.cpp => test_imp_utility.cpp} | 0 test/test_ipc_mmap.cpp | 7 +++++++ 6 files changed, 29 insertions(+), 2 deletions(-) rename test/{test_detect_plat.cpp => test_imp_detect_plat.cpp} (100%) rename test/{test_result.cpp => test_imp_result.cpp} (100%) rename test/{test_utility.cpp => test_imp_utility.cpp} (100%) create mode 100644 test/test_ipc_mmap.cpp diff --git a/include/libipc/def.h b/include/libipc/def.h index 2ce94db..dd04e07 100755 --- a/include/libipc/def.h +++ b/include/libipc/def.h @@ -19,7 +19,8 @@ LIBIPC_NAMESPACE_BEG_ // constants struct prot { - enum : std::uint32_t { + using type = std::uint32_t; + enum : type { none = 0x00, read = 0x01, write = 0x02, diff --git a/include/libipc/mmap.h b/include/libipc/mmap.h index 3b266a5..2f9e921 100644 --- a/include/libipc/mmap.h +++ b/include/libipc/mmap.h @@ -6,6 +6,9 @@ */ #pragma once +#include +#include + #include "libimp/export.h" #include "libimp/result.h" @@ -19,6 +22,22 @@ using mmap_t = mmap_handle *; /** * @brief Creates a new mapping in the virtual address space of the calling process. */ -LIBIMP_EXPORT ::LIBIMP_::result mmap_open(); +LIBIMP_EXPORT ::LIBIMP_::result mmap_open(std::string const &file, + std::size_t size = 0, + prot::type = prot::read | prot::write) noexcept; + +/** + * @brief Close the memory mapping handle. + */ +LIBIMP_EXPORT ::LIBIMP_::result_code mmap_close(mmap_t) noexcept; + +/** + * @brief Synchronize a file with a memory map. + */ +LIBIMP_EXPORT ::LIBIMP_::result_code mmap_sync(mmap_t) noexcept; + +LIBIMP_EXPORT void * mmap_get (mmap_t) noexcept; +LIBIMP_EXPORT std::size_t mmap_size(mmap_t) noexcept; +LIBIMP_EXPORT std::string mmap_file(mmap_t) noexcept; LIBIPC_NAMESPACE_END_ diff --git a/test/test_detect_plat.cpp b/test/test_imp_detect_plat.cpp similarity index 100% rename from test/test_detect_plat.cpp rename to test/test_imp_detect_plat.cpp diff --git a/test/test_result.cpp b/test/test_imp_result.cpp similarity index 100% rename from test/test_result.cpp rename to test/test_imp_result.cpp diff --git a/test/test_utility.cpp b/test/test_imp_utility.cpp similarity index 100% rename from test/test_utility.cpp rename to test/test_imp_utility.cpp diff --git a/test/test_ipc_mmap.cpp b/test/test_ipc_mmap.cpp new file mode 100644 index 0000000..40ed6bb --- /dev/null +++ b/test/test_ipc_mmap.cpp @@ -0,0 +1,7 @@ + +#include "gtest/gtest.h" + +#include "libipc/mmap.h" + +TEST(mmap, create_close) { +} \ No newline at end of file