From 6c5379565bd41d264d32985913f885d00b141d26 Mon Sep 17 00:00:00 2001 From: fancy <258828110.@qq.com> Date: Tue, 31 Oct 2023 09:09:21 -0700 Subject: [PATCH] Add shared data module. --- test/utils/CMakeLists.txt | 1 + test/utils/LogC/CMakeLists.txt | 34 -------- test/utils/LogC/src/LogCTest.cpp | 20 ----- test/utils/SharedData/CMakeLists.txt | 54 +++++++++++++ test/utils/{LogC => SharedData}/mainTest.cpp | 0 test/utils/SharedData/src/SharedDataTest.cpp | 34 ++++++++ tools/README.md | 4 + utils/CMakeLists.txt | 2 + utils/SharedData/CMakeLists.txt | 44 +++++++++++ utils/SharedData/README.md | 16 ++++ utils/SharedData/include/SharedData.h | 41 ++++++++++ utils/SharedData/src/SharedData.cpp | 20 +++++ utils/SharedData/src/SharedDataImpl.cpp | 82 ++++++++++++++++++++ utils/SharedData/src/SharedDataImpl.h | 52 +++++++++++++ utils/SharedData/src/SharedMemory.cpp | 65 ++++++++++++++++ utils/SharedData/src/SharedMemory.h | 32 ++++++++ 16 files changed, 447 insertions(+), 54 deletions(-) delete mode 100644 test/utils/LogC/CMakeLists.txt delete mode 100644 test/utils/LogC/src/LogCTest.cpp create mode 100644 test/utils/SharedData/CMakeLists.txt rename test/utils/{LogC => SharedData}/mainTest.cpp (100%) create mode 100644 test/utils/SharedData/src/SharedDataTest.cpp create mode 100644 tools/README.md create mode 100644 utils/SharedData/CMakeLists.txt create mode 100644 utils/SharedData/README.md create mode 100644 utils/SharedData/include/SharedData.h create mode 100644 utils/SharedData/src/SharedData.cpp create mode 100644 utils/SharedData/src/SharedDataImpl.cpp create mode 100644 utils/SharedData/src/SharedDataImpl.h create mode 100644 utils/SharedData/src/SharedMemory.cpp create mode 100644 utils/SharedData/src/SharedMemory.h diff --git a/test/utils/CMakeLists.txt b/test/utils/CMakeLists.txt index 0f84be85..fe883631 100644 --- a/test/utils/CMakeLists.txt +++ b/test/utils/CMakeLists.txt @@ -1,5 +1,6 @@ #Compile gtest for test code. add_subdirectory(Config) add_subdirectory(Log) +add_subdirectory(SharedData) diff --git a/test/utils/LogC/CMakeLists.txt b/test/utils/LogC/CMakeLists.txt deleted file mode 100644 index 2b82d2b4..00000000 --- a/test/utils/LogC/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) -include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) -set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) - -include_directories( - ${UTILS_SOURCE_PATH}/LogC/include - ${UTILS_SOURCE_PATH}/LogC/src - ${UTILS_SOURCE_PATH}/ReturnCode/include - ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include - ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include -) - -link_directories( - ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/lib - ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/lib - ${LIBS_OUTPUT_PATH} -) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -aux_source_directory(./ SRC_FILES) -aux_source_directory(./src SRC_FILES) - -set(TARGET_NAME LogCTest) -add_executable(${TARGET_NAME} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} gtest gmock pthread ReturnCode LogCAbstract) -# target_link_libraries(${TARGET_NAME} gtest gmock pthread ReturnCode LogCAbstract LogCUb) -if(${TEST_COVERAGE} MATCHES "true") - target_link_libraries(${TARGET_NAME} gcov) -endif() \ No newline at end of file diff --git a/test/utils/LogC/src/LogCTest.cpp b/test/utils/LogC/src/LogCTest.cpp deleted file mode 100644 index e7533eda..00000000 --- a/test/utils/LogC/src/LogCTest.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "iLog.h" - -#include -#include -namespace LogCTest -{ - // ../output_files/test/bin/LogCTest --gtest_filter=LogCTest.Demo - TEST(LogCTest, Demo) - { - create_log_module(); - i_log_init(); - - LogInfo("hello world."); - LogError("create ... failed."); - LogDebug("a = %d b = %s", 124, "apple"); - - i_log_unInit(); - destroy_log_module(); - } -} \ No newline at end of file diff --git a/test/utils/SharedData/CMakeLists.txt b/test/utils/SharedData/CMakeLists.txt new file mode 100644 index 00000000..70c875b0 --- /dev/null +++ b/test/utils/SharedData/CMakeLists.txt @@ -0,0 +1,54 @@ +# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake) +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin) + +include_directories( + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + ${UTILS_SOURCE_PATH}/SharedData/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include +) + +link_directories( + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/lib + ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/lib + ${LIBS_OUTPUT_PATH} +) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +aux_source_directory(. SRC_FILES) +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME SharedDataTest) +add_executable(${TARGET_NAME} ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} SharedData gtest gmock pthread Log) +if(${TEST_COVERAGE} MATCHES "true") + target_link_libraries(${TARGET_NAME} gcov) +endif() +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + SharedDataTest_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + # --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/gtest.h\"}]' + --line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]' + -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell + WORKING_DIRECTORY ${TEST_SOURCE_PATH}/utils/SharedData +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make SharedDataTest_code_check + WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/ +) +endif() \ No newline at end of file diff --git a/test/utils/LogC/mainTest.cpp b/test/utils/SharedData/mainTest.cpp similarity index 100% rename from test/utils/LogC/mainTest.cpp rename to test/utils/SharedData/mainTest.cpp diff --git a/test/utils/SharedData/src/SharedDataTest.cpp b/test/utils/SharedData/src/SharedDataTest.cpp new file mode 100644 index 00000000..f9bf1c9e --- /dev/null +++ b/test/utils/SharedData/src/SharedDataTest.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "SharedData.h" +#include "ILog.h" +#include +#include +namespace SharedDataTest +{ + // ../output_files/test/bin/SharedDataTest --gtest_filter=SharedDataTest.Demo + TEST(SharedDataTest, Demo) + { + CreateLogModule(); + ILogInit(LOG_INSTANCE_TYPE_END); + SharedData *sharedData = CreateSharedData(SHARER_NAME_PRIMARY, "./shared_file", 9); + if (nullptr != sharedData) + { + sharedData->mMakeSharedData(sharedData, sizeof(int), sizeof(int)); + sharedData->mFree(sharedData); + } + ILogUnInit(); + } +} // namespace SharedDataTest \ No newline at end of file diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 00000000..6b002f6f --- /dev/null +++ b/tools/README.md @@ -0,0 +1,4 @@ +# 1. 工具 + +## 1.1. 概述 +  该目录存放使用到的工具。 \ No newline at end of file diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 922507ff..8a312530 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -3,3 +3,5 @@ add_subdirectory(Config) add_subdirectory(StatusCode) add_subdirectory(Log) +add_subdirectory(SharedData) +add_subdirectory(SharedMemory) diff --git a/utils/SharedData/CMakeLists.txt b/utils/SharedData/CMakeLists.txt new file mode 100644 index 00000000..5be3f40c --- /dev/null +++ b/utils/SharedData/CMakeLists.txt @@ -0,0 +1,44 @@ +include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) +set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) +set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) + +include_directories( + ./src + ./include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include +) +# link_directories( +# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs +# ) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME SharedData) +add_library(${TARGET_NAME} STATIC ${SRC_FILES}) +target_link_libraries(${TARGET_NAME} StatusCode Log) + +if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") +add_custom_target( + SharedData_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell + WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/SharedData +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make SharedData_code_check + WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) \ No newline at end of file diff --git a/utils/SharedData/README.md b/utils/SharedData/README.md new file mode 100644 index 00000000..63e9fe03 --- /dev/null +++ b/utils/SharedData/README.md @@ -0,0 +1,16 @@ +# 1. Linux跨进程共享数据 + +## 1.1. 概述 + +  用于跨进程进行数据共享的中间件。 + +## 1.2. UML类图 + +```mermaid +classDiagram + i_ipc_config <.. ipc_config:实现 + ipc_config --> i_config_manager:依赖 + ipc_config --> IHal:依赖 + i_config_manager <.. config_manager:实现 + config_manager --> libconfig开源库:依赖 +``` \ No newline at end of file diff --git a/utils/SharedData/include/SharedData.h b/utils/SharedData/include/SharedData.h new file mode 100644 index 00000000..d52da376 --- /dev/null +++ b/utils/SharedData/include/SharedData.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SHARED_DATA_H +#define SHARED_DATA_H +#include "StatusCode.h" +#ifdef __cplusplus +extern "C" +{ +#endif + enum SHARER_NAME + { + SHARER_NAME_PRIMARY = 0, + SHARER_NAME_MINOR, + SHARER_NAME_END + }; + typedef struct shared_data SharedData; + typedef struct shared_data + { + const StatusCode (*mMakeSharedData)(SharedData *, const int, const int); + const StatusCode (*mCleanSharedData)(SharedData *); + void *(*mGetReadableDataPointer)(SharedData *); + void *(*mGetWritableDataPointer)(SharedData *); + void (*mFree)(void *); + } SharedData; + SharedData *CreateSharedData(const SHARER_NAME name, const char *path, const int projectId); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/utils/SharedData/src/SharedData.cpp b/utils/SharedData/src/SharedData.cpp new file mode 100644 index 00000000..38cfce3d --- /dev/null +++ b/utils/SharedData/src/SharedData.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "SharedData.h" +#include "SharedDataImpl.h" +SharedData *CreateSharedData(const SHARER_NAME name, const char *path, const int projectId) +{ + return (SharedData *)NewSharedDataImpl(name, path, projectId); +} \ No newline at end of file diff --git a/utils/SharedData/src/SharedDataImpl.cpp b/utils/SharedData/src/SharedDataImpl.cpp new file mode 100644 index 00000000..ef36ba82 --- /dev/null +++ b/utils/SharedData/src/SharedDataImpl.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "SharedDataImpl.h" +#include "ILog.h" +#include +static const char *SHARED_DATA_NAME = "shared_data"; +constexpr short THERE_TWO_USER_DATA_HEADER = 2; +SharedDataCpp::SharedDataCpp(const SHARER_NAME &sharerName, const char *path, const int &projectId) + : SharedMemory(path, projectId), mSharerName(sharerName) +{ + mReadableSize = 0; + mWritableSize = 0; + mSharedMemeory = nullptr; +} +void SharedDataCpp::MakeSharedMemory(const int readableSize, const int writableSize) +{ + mReadableSize = readableSize; + mWritableSize = writableSize; + const int SHARED_MEMORY_SIZE = readableSize + writableSize + sizeof(UserDataHeader) * THERE_TWO_USER_DATA_HEADER; + SharedMemory::MakeSharedMemory(SHARED_MEMORY_SIZE); + mSharedMemeory = SharedMemory::GetMemory(); +} +void *SharedDataCpp::GetReadableMemory(void) +{ + if (SHARER_NAME_PRIMARY == mSharerName) + { + return (char *)mSharedMemeory + sizeof(UserDataHeader); + } + if (SHARER_NAME_MINOR == mSharerName) + { + return (char *)mSharedMemeory + sizeof(UserDataHeader) * THERE_TWO_USER_DATA_HEADER + mReadableSize; + } + return nullptr; +} +static const StatusCode MakeSharedData(SharedData *object, const int readableSize, const int writableSize) +{ + SharedDataImpl *impl = ((SharedDataImpl *)(((char *)object) - sizeof(SharedDataHeader))); + impl->mSharedData->MakeSharedMemory(readableSize, writableSize); + return CreateStatusCode(STATUS_CODE_OK); +} +static void *GetSharedReadableMemory(SharedData *object) +{ + SharedDataImpl *impl = ((SharedDataImpl *)(((char *)object) - sizeof(SharedDataHeader))); + return impl->mSharedData->GetReadableMemory(); +} +static void SharedDataImplFree(void *ptr) +{ + SharedDataImpl *object = ((SharedDataImpl *)(((char *)ptr) - sizeof(SharedDataHeader))); + if (SHARED_DATA_NAME == object->mHeader.mCheckName) + { + object->mSharedData = nullptr; + free(((char *)ptr) - sizeof(SharedDataHeader)); + } + else + { + LogError("Unknow ptr.\n"); + } +} +SharedData *NewSharedDataImpl(const SHARER_NAME &name, const char *path, const int &projectId) +{ + SharedDataImpl *impl = (SharedDataImpl *)malloc(sizeof(SharedDataImpl)); + SharedDataImpl tmp; + memcpy((void *)impl, (void *)&tmp, sizeof(SharedDataImpl)); + impl->mHeader.mCheckName = SHARED_DATA_NAME; + impl->mBase.mMakeSharedData = MakeSharedData; + impl->mBase.mGetReadableDataPointer = GetSharedReadableMemory; + impl->mBase.mFree = SharedDataImplFree; + impl->mSharedData = std::make_shared(name, path, projectId); + return (SharedData *)(((char *)impl) + sizeof(SharedDataHeader)); +} \ No newline at end of file diff --git a/utils/SharedData/src/SharedDataImpl.h b/utils/SharedData/src/SharedDataImpl.h new file mode 100644 index 00000000..eea36041 --- /dev/null +++ b/utils/SharedData/src/SharedDataImpl.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SHARED_DATA_IMPL_H +#define SHARED_DATA_IMPL_H +#include "SharedData.h" +#include "SharedMemory.h" +#include +typedef struct shared_data_header +{ + const char *mCheckName; +} SharedDataHeader; +typedef struct user_data_header +{ + int mIsInit; +} UserDataHeader; +class SharedDataCpp : public SharedMemory +{ +public: + SharedDataCpp(const SHARER_NAME &sharerName, const char *path, const int &projectId); + virtual ~SharedDataCpp() = default; + void MakeSharedMemory(const int readableSize, const int writableSize); + void *GetReadableMemory(void); + +private: + const SHARER_NAME mSharerName; + // std::shared_ptr mReadableMemory; + // std::shared_ptr mWritableMemory; + unsigned int mReadableSize; + unsigned int mWritableSize; + void *mSharedMemeory; +}; +typedef struct shared_data_impl SharedDataImpl; +typedef struct shared_data_impl +{ + SharedDataHeader mHeader; + SharedData mBase; + std::shared_ptr mSharedData; +} SharedDataImpl; +SharedData *NewSharedDataImpl(const SHARER_NAME &name, const char *path, const int &projectId); +#endif \ No newline at end of file diff --git a/utils/SharedData/src/SharedMemory.cpp b/utils/SharedData/src/SharedMemory.cpp new file mode 100644 index 00000000..8b236308 --- /dev/null +++ b/utils/SharedData/src/SharedMemory.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "SharedMemory.h" +#include "ILog.h" +#include +#include +#include +#include +#include +#include +#include +constexpr int SHMGET_FAILED = -1; +SharedMemory::SharedMemory(const char *path, const int &projectId) + : mPath(path), mProjectId(projectId) +{ + mId = SHMGET_FAILED; +} +StatusCode SharedMemory::MakeSharedMemory(const int &size) +{ + char touchPath[128] = {0}; + if (access(mPath, F_OK) != 0) + { + sprintf(touchPath, "%s %s", "touch", mPath); + system(touchPath); + } + key_t key = ftok(mPath, mProjectId); + if (key < 0) + { + LogError("ftok failed.\n"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + mId = shmget(key, size, IPC_CREAT | 0666); + if (mId == SHMGET_FAILED) + { + LogError("shmget failed.\n"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + LogInfo("Make shared memory succeed.\n"); + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode SharedMemory::CleanSharedMemory(void) +{ + if (shmctl(mId, IPC_RMID, NULL) < 0) + { + LogError("shmctl failed.\n"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + return CreateStatusCode(STATUS_CODE_OK); +} +void *SharedMemory::GetMemory(void) +{ + return shmat(mId, NULL, 0); +} \ No newline at end of file diff --git a/utils/SharedData/src/SharedMemory.h b/utils/SharedData/src/SharedMemory.h new file mode 100644 index 00000000..c2c3675b --- /dev/null +++ b/utils/SharedData/src/SharedMemory.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SHARED_MEMORY_H +#define SHARED_MEMORY_H +#include "StatusCode.h" +class SharedMemory +{ +public: + SharedMemory(const char *path, const int &projectId); + virtual ~SharedMemory() = default; + StatusCode MakeSharedMemory(const int &size); + StatusCode CleanSharedMemory(void); + void *GetMemory(void); + +private: + const char *mPath; + const int mProjectId; + int mId; +}; +#endif // !SHARED_MEMORY_H \ No newline at end of file