diff --git a/build/cmake/toolchain/linux.toolchain.cmake b/build/cmake/toolchain/linux.toolchain.cmake index 16d0c27b..615b736a 100755 --- a/build/cmake/toolchain/linux.toolchain.cmake +++ b/build/cmake/toolchain/linux.toolchain.cmake @@ -75,5 +75,6 @@ set(APP_MANAGER_TCP_SERVER_PORT "9876") # ------------ build AppManager end ------------ # # ------------ build sd card ------------ # -# set(SD_CARD_DEV "dev/test") +set(SD_CARD_DEV "/dev/test") +set(SD_CARD_MOUNT_PATH "/mnt/test") # ------------ build sd card end ------------ # \ No newline at end of file diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index bb9499b2..22fc61f6 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -17,6 +17,7 @@ include_directories( # ) add_definitions(-DSD_CARD_DEV=\"${SD_CARD_DEV}\") +add_definitions(-DSD_CARD_MOUNT_PATH=\"${SD_CARD_MOUNT_PATH}\") aux_source_directory(./abstract ABSTRACT_SRC_FILES) aux_source_directory(./src IMPL_SRC_FILES) diff --git a/hal/abstract/IHalCpp.cpp b/hal/abstract/IHalCpp.cpp index 0665dfd1..a80354e9 100644 --- a/hal/abstract/IHalCpp.cpp +++ b/hal/abstract/IHalCpp.cpp @@ -61,6 +61,9 @@ std::shared_ptr &IHalCpp::GetInstance(std::shared_ptr *impl) } return instance; } +void VSdCardHal::SetSdCardMonitor(std::shared_ptr &monitor) +{ +} StatusCode IHalCpp::Init(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); diff --git a/hal/include/IHalCpp.h b/hal/include/IHalCpp.h index 67cb03c9..2197df09 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -111,6 +111,7 @@ class VSdCardHal public: VSdCardHal() = default; virtual ~VSdCardHal() = default; + virtual void SetSdCardMonitor(std::shared_ptr &monitor); }; class IHalCpp { diff --git a/hal/src/SdCardHal.cpp b/hal/src/SdCardHal.cpp index 1cf64e77..01c3191b 100644 --- a/hal/src/SdCardHal.cpp +++ b/hal/src/SdCardHal.cpp @@ -27,6 +27,10 @@ SdCardHal::SdCardHal() { mThreadRuning = false; } +void SdCardHal::SetSdCardMonitor(std::shared_ptr &monitor) +{ + mMonitor = monitor; +} void SdCardHal::Init(void) { auto detectThread = [](std::shared_ptr sdCardHal) { @@ -47,7 +51,8 @@ void SdCardHal::DevDetectingThread(void) constexpr int SLEEP_TIME_MS = 100; SdCardHalStatus status = SdCardHalStatus::END; int fd = -1; - const char *dev = "/dev/mmcblk0"; + // const char *dev = "/dev/mmcblk1p1"; + const char *dev = SD_CARD_DEV; mThreadRuning = true; while (mThreadRuning) { fd = open(dev, O_RDONLY); @@ -55,7 +60,7 @@ void SdCardHal::DevDetectingThread(void) LogInfo("sdCardHal: %s open failed.\n", dev); if (SdCardHalStatus::PULL_OUT != status) { status = SdCardHalStatus::PULL_OUT; - // TODO: pull out + ReportDetecedChangedResult(status); } goto CONTINUE; } @@ -64,7 +69,7 @@ void SdCardHal::DevDetectingThread(void) LogInfo("sdCardHal: %s fstat failed.\n", dev); if (SdCardHalStatus::ERROR != status) { status = SdCardHalStatus::ERROR; - // TODO: error + ReportDetecedChangedResult(status); } goto CONTINUE; } @@ -72,17 +77,33 @@ void SdCardHal::DevDetectingThread(void) LogInfo("sdCardHal: %s is not block device.\n", dev); if (SdCardHalStatus::PULL_OUT != status) { status = SdCardHalStatus::PULL_OUT; - // TODO: pull out + ReportDetecedChangedResult(status); } } else { LogInfo("sdCardHal: %s is inserted.\n", dev); if (SdCardHalStatus::INSERTED != status) { status = SdCardHalStatus::INSERTED; - // TODO: inserted + ReportDetecedChangedResult(status); } } CONTINUE: std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); } +} +void SdCardHal::ReportDetecedChangedResult(const SdCardHalStatus &status) +{ + auto monitor = mMonitor.lock(); + if (mMonitor.expired()) { + LogWarning("SdCardHal: monitor is expired.\n"); + return; + } + monitor->ReportEvent(status); + if (SdCardHalStatus::INSERTED == status) { + LogInfo("mount sd dev %s.\n", SD_CARD_MOUNT_PATH); + constexpr int BUF_LENGTH = 128; + char cmd[BUF_LENGTH] = {0}; + snprintf(cmd, BUF_LENGTH, "mount %s %s", SD_CARD_DEV, SD_CARD_MOUNT_PATH); + fx_system(cmd); + } } \ No newline at end of file diff --git a/hal/src/SdCardHal.h b/hal/src/SdCardHal.h index c85c25f4..91d0ebbe 100644 --- a/hal/src/SdCardHal.h +++ b/hal/src/SdCardHal.h @@ -21,12 +21,17 @@ class SdCardHal : public VSdCardHal, public std::enable_shared_from_this &monitor) override; void Init(void); void UnInit(void); void DevDetectingThread(void); +private: + void ReportDetecedChangedResult(const SdCardHalStatus &status); + private: bool mThreadRuning; std::thread mDevDetectingThread; + std::weak_ptr mMonitor; }; #endif \ No newline at end of file diff --git a/middleware/CMakeLists.txt b/middleware/CMakeLists.txt index ddf905a8..12ea5226 100644 --- a/middleware/CMakeLists.txt +++ b/middleware/CMakeLists.txt @@ -5,4 +5,5 @@ add_subdirectory(McuManager) add_subdirectory(McuAskBase) add_subdirectory(MediaManager) add_subdirectory(AppManager) -add_subdirectory(StorageManager) \ No newline at end of file +add_subdirectory(StorageManager) +add_subdirectory(FilesManager) \ No newline at end of file diff --git a/middleware/FilesManager/CMakeLists.txt b/middleware/FilesManager/CMakeLists.txt new file mode 100644 index 00000000..a58db72d --- /dev/null +++ b/middleware/FilesManager/CMakeLists.txt @@ -0,0 +1,64 @@ + +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 + # ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include + ${UTILS_SOURCE_PATH}/StatusCode/include + ${UTILS_SOURCE_PATH}/Log/include + # ${UTILS_SOURCE_PATH}/McuProtocol/include + # ${UTILS_SOURCE_PATH}/UartDevice/include +) +#do not rely on any other library +#link_directories( +#) + +aux_source_directory(./src SRC_FILES) + +set(TARGET_NAME FilesManager) +add_library(${TARGET_NAME} STATIC ${SRC_FILES}) + +target_link_libraries(${TARGET_NAME} StatusCode Log) + +if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") +add_custom_target( + FilesManager_code_check + COMMAND ${CLANG_TIDY_EXE} + -checks='${CLANG_TIDY_CHECKS}' + --header-filter=.* + --system-headers=false + ${SRC_FILES} + ${CLANG_TIDY_CONFIG} + -p ${PLATFORM_PATH}/cmake-shell + WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/FilesManager +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make FilesManager_code_check + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + FilesManager_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/FilesManager +) +add_custom_command( + TARGET ${TARGET_NAME} + PRE_BUILD + COMMAND make FilesManager_code_check + COMMAND make FilesManager_code_format + WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/ +) +endif() + +define_file_name(${TARGET_NAME}) + +file(GLOB_RECURSE INSTALL_HEADER_FILES include/*.h) +install(FILES ${INSTALL_HEADER_FILES} DESTINATION include) \ No newline at end of file diff --git a/middleware/FilesManager/README.md b/middleware/FilesManager/README.md new file mode 100644 index 00000000..7d8edaae --- /dev/null +++ b/middleware/FilesManager/README.md @@ -0,0 +1,5 @@ +# 1. 文件管理 + +## 1.1. 概述 + +  IPC产品的文件管理模块。抓拍的图片或者视频的保存/删除/查询等操作通过该模块实现。 \ No newline at end of file diff --git a/middleware/FilesManager/include/IFilesManager.h b/middleware/FilesManager/include/IFilesManager.h new file mode 100644 index 00000000..6aa1d2f5 --- /dev/null +++ b/middleware/FilesManager/include/IFilesManager.h @@ -0,0 +1,26 @@ +/* + * 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 I_FILES_MANAGER_H +#define I_FILES_MANAGER_H +#include "StatusCode.h" +#include +class IFilesManager +{ +public: + IFilesManager() = default; + virtual ~IFilesManager() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); +}; +#endif \ No newline at end of file diff --git a/middleware/FilesManager/src/IFilesManager.cpp b/middleware/FilesManager/src/IFilesManager.cpp new file mode 100644 index 00000000..60cdec99 --- /dev/null +++ b/middleware/FilesManager/src/IFilesManager.cpp @@ -0,0 +1,30 @@ +/* + * 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 "IFilesManager.h" +#include "ILog.h" +std::shared_ptr &IFilesManager::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + if (impl) { + if (instance.use_count() == 1) { + LogInfo("Instance changed succeed.\n"); + instance = *impl; + } + else { + LogError("Can't changing the instance becase of using by some one.\n"); + } + } + return instance; +} \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaManagerImpl.cpp b/middleware/MediaManager/src/MediaManagerImpl.cpp index 386f664a..08ac05aa 100644 --- a/middleware/MediaManager/src/MediaManagerImpl.cpp +++ b/middleware/MediaManager/src/MediaManagerImpl.cpp @@ -40,6 +40,7 @@ void MediaManagerImpl::ReportEvent(const CameraReportEvent &event) auto monitor = mMediaMonitor.lock(); if (mMediaMonitor.expired()) { + LogWarning("MediaMonitor is expired.\n"); return; } monitor->ReportEvent(reprot); diff --git a/middleware/StorageManager/README.md b/middleware/StorageManager/README.md new file mode 100644 index 00000000..9defdad8 --- /dev/null +++ b/middleware/StorageManager/README.md @@ -0,0 +1,5 @@ +# 1. 存储管理 + +## 1.1. 概述 + +  对设备的存储进行管理,包括SD卡,EMMC等。 \ No newline at end of file diff --git a/middleware/StorageManager/include/IStorageManager.h b/middleware/StorageManager/include/IStorageManager.h index e188e5e8..d8213b02 100644 --- a/middleware/StorageManager/include/IStorageManager.h +++ b/middleware/StorageManager/include/IStorageManager.h @@ -14,5 +14,32 @@ */ #ifndef I_STORAGE_MANAGER_H #define I_STORAGE_MANAGER_H - +#include "StatusCode.h" +#include +bool CreateStorageManagerModule(void); +bool DestroyStorageManagerModule(void); +enum class StorageEvent +{ + SD_CARD_INSERT = 0, + SD_CARD_REMOVE, + EMMC_NORMAL, + END +}; +class VStorageMoniter +{ +public: + VStorageMoniter() = default; + virtual ~VStorageMoniter() = default; + virtual void ReportEvent(const StorageEvent &event); +}; +class IStorageManager +{ +public: + IStorageManager() = default; + virtual ~IStorageManager() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual StatusCode Init(void); + virtual StatusCode UnInit(void); + virtual StatusCode SaveFile(const std::string &path, const std::string &content); +}; #endif \ No newline at end of file diff --git a/middleware/StorageManager/src/IStorageManager.cpp b/middleware/StorageManager/src/IStorageManager.cpp index bdfbe0da..184f82cd 100644 --- a/middleware/StorageManager/src/IStorageManager.cpp +++ b/middleware/StorageManager/src/IStorageManager.cpp @@ -12,4 +12,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "IStorageManager.h" \ No newline at end of file +#include "IStorageManager.h" +#include "ILog.h" +void VStorageMoniter::ReportEvent(const StorageEvent &event) +{ +} +std::shared_ptr &IStorageManager::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + if (impl) { + if (instance.use_count() == 1) { + LogInfo("Instance changed succeed.\n"); + instance = *impl; + } + else { + LogError("Can't changing the instance becase of using by some one.\n"); + } + } + return instance; +} +StatusCode IStorageManager::Init(void) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode IStorageManager::UnInit(void) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageManagerImpl.cpp b/middleware/StorageManager/src/StorageManagerImpl.cpp new file mode 100644 index 00000000..b7532d41 --- /dev/null +++ b/middleware/StorageManager/src/StorageManagerImpl.cpp @@ -0,0 +1,23 @@ +/* + * 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 "StorageManagerImpl.h" +StatusCode StorageManagerImpl::Init(void) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode StorageManagerImpl::UnInit(void) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageManagerImpl.h b/middleware/StorageManager/src/StorageManagerImpl.h new file mode 100644 index 00000000..604c2251 --- /dev/null +++ b/middleware/StorageManager/src/StorageManagerImpl.h @@ -0,0 +1,27 @@ +/* + * 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 STORAGE_MANAGER_IMPL_H +#define STORAGE_MANAGER_IMPL_H +#include "IStorageManager.h" +#include +class StorageManagerImpl : public IStorageManager, public std::enable_shared_from_this +{ +public: + StorageManagerImpl() = default; + virtual ~StorageManagerImpl() = default; + StatusCode Init(void) override; + StatusCode UnInit(void) override; +}; +#endif \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageManagerMakePtr.cpp b/middleware/StorageManager/src/StorageManagerMakePtr.cpp new file mode 100644 index 00000000..3f9243cb --- /dev/null +++ b/middleware/StorageManager/src/StorageManagerMakePtr.cpp @@ -0,0 +1,54 @@ +/* + * 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 "StorageManagerMakePtr.h" +#include "ILog.h" +#include "StorageManagerImpl.h" +bool CreateStorageManagerModule(void) +{ + auto instance = std::make_shared(); + StatusCode code = StorageManagerMakePtr::GetInstance()->CreateStorageManagerModule(instance); + if (IsCodeOK(code)) { + LogInfo("CreateStorageManagerModule is ok.\n"); + IStorageManager::GetInstance(&instance); + return true; + } + return false; +} +bool DestroyStorageManagerModule(void) +{ + auto instance = std::make_shared(); + IStorageManager::GetInstance(&instance); + return true; +} +std::shared_ptr &StorageManagerMakePtr::GetInstance(std::shared_ptr *impl) +{ + static auto instance = std::make_shared(); + if (impl) { + if (instance.use_count() == 1) { + LogInfo("Instance changed succeed.\n"); + instance = *impl; + } + else { + LogError("Can't changing the instance becase of using by some one.\n"); + } + } + return instance; +} +const StatusCode StorageManagerMakePtr::CreateStorageManagerModule(std::shared_ptr &impl) +{ + auto tmp = std::make_shared(); + impl = tmp; + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageManagerMakePtr.h b/middleware/StorageManager/src/StorageManagerMakePtr.h new file mode 100644 index 00000000..83efc9e7 --- /dev/null +++ b/middleware/StorageManager/src/StorageManagerMakePtr.h @@ -0,0 +1,28 @@ +/* + * 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 STORAGE_MANAGER_MAKE_PTR_H +#define STORAGE_MANAGER_MAKE_PTR_H +#include "IStorageManager.h" +#include "StatusCode.h" +#include +class StorageManagerMakePtr +{ +public: + StorageManagerMakePtr() = default; + virtual ~StorageManagerMakePtr() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual const StatusCode CreateStorageManagerModule(std::shared_ptr &impl); +}; +#endif // !STORAGE_MANAGER_MAKE_PTR_H \ No newline at end of file