From d8f7e2c076bf7165a06b8a9afadfb8adacde2035 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Sun, 28 Apr 2024 14:16:11 +0800 Subject: [PATCH] Backup:save file function. --- .../build/huntting_camera.cmake | 3 +- application/HunttingCamera/src/MainThread.cpp | 3 ++ application/MissionManager/CMakeLists.txt | 4 +- .../src/MissionManagerMakePtr.cpp | 1 + .../MissionManager/src/SdCardHandleState.cpp | 5 +- .../MissionManager/src/StorageHandleState.cpp | 11 ++++ .../MissionManager/src/StorageHandleState.h | 11 +++- doc/doxygen_user_guide.md | 13 +++++ middleware/FilesManager/CMakeLists.txt | 2 +- middleware/FilesManager/README.md | 25 ++++++++- .../FilesManager/include/IFilesManager.h | 10 ++++ .../FilesManager/src/FilesManagerImpl.cpp | 29 ++++++++++ .../FilesManager/src/FilesManagerImpl.h | 28 ++++++++++ .../FilesManager/src/FilesManagerMakePtr.cpp | 54 +++++++++++++++++++ .../FilesManager/src/FilesManagerMakePtr.h | 28 ++++++++++ middleware/FilesManager/src/IFilesManager.cpp | 15 ++++++ .../MediaManager/include/IMediaManager.h | 4 +- middleware/StorageManager/CMakeLists.txt | 1 + .../StorageManager/include/IStorageManager.h | 3 +- middleware/StorageManager/src/EmmcHandle.cpp | 15 ++++++ middleware/StorageManager/src/EmmcHandle.h | 25 +++++++++ .../StorageManager/src/IStorageManager.cpp | 9 ++++ .../StorageManager/src/SdCardHandle.cpp | 35 ++++++++++++ middleware/StorageManager/src/SdCardHandle.h | 32 +++++++++++ middleware/StorageManager/src/StorageBase.cpp | 15 ++++++ middleware/StorageManager/src/StorageBase.h | 28 ++++++++++ .../StorageManager/src/StorageManagerImpl.cpp | 18 ++++++- .../StorageManager/src/StorageManagerImpl.h | 6 ++- 28 files changed, 421 insertions(+), 12 deletions(-) create mode 100644 doc/doxygen_user_guide.md create mode 100644 middleware/FilesManager/src/FilesManagerImpl.cpp create mode 100644 middleware/FilesManager/src/FilesManagerImpl.h create mode 100644 middleware/FilesManager/src/FilesManagerMakePtr.cpp create mode 100644 middleware/FilesManager/src/FilesManagerMakePtr.h create mode 100644 middleware/StorageManager/src/EmmcHandle.cpp create mode 100644 middleware/StorageManager/src/EmmcHandle.h create mode 100644 middleware/StorageManager/src/SdCardHandle.cpp create mode 100644 middleware/StorageManager/src/SdCardHandle.h create mode 100644 middleware/StorageManager/src/StorageBase.cpp create mode 100644 middleware/StorageManager/src/StorageBase.h diff --git a/application/HunttingCamera/build/huntting_camera.cmake b/application/HunttingCamera/build/huntting_camera.cmake index c8621b2d..aac28580 100644 --- a/application/HunttingCamera/build/huntting_camera.cmake +++ b/application/HunttingCamera/build/huntting_camera.cmake @@ -4,8 +4,9 @@ set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_S set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/McuManager/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/AppManager/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/MediaManager/include") +set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${MIDDLEWARE_SOURCE_PATH}/FilesManager/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/StatusCode/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${UTILS_SOURCE_PATH}/Log/include") set(HUNTTING_MAIN_INCLUDE_PATH "${HUNTTING_MAIN_INCLUDE_PATH};${HAL_SOURCE_PATH}/include") -set(HUNTTING_LINK_LIB McuManager MissionManager StateMachine AppManager StatusCode Log Hal pthread dl) \ No newline at end of file +set(HUNTTING_LINK_LIB McuManager MissionManager StateMachine AppManager FilesManager StatusCode Log Hal pthread dl) \ No newline at end of file diff --git a/application/HunttingCamera/src/MainThread.cpp b/application/HunttingCamera/src/MainThread.cpp index df203532..8b3b9a72 100644 --- a/application/HunttingCamera/src/MainThread.cpp +++ b/application/HunttingCamera/src/MainThread.cpp @@ -14,6 +14,7 @@ */ #include "MainThread.h" #include "IAppManager.h" +#include "IFilesManager.h" #include "IHalCpp.h" #include "ILog.h" #include "IMcuManager.h" @@ -80,6 +81,7 @@ StatusCode MainThread::CreateAllModules(void) { CreateHalCppModule(); CreateMcuManager(); + CreateFilesManagerModule(); CreateMissionManagerModule(); CreateStateMachine(); CreateAppManagerModule(); @@ -92,6 +94,7 @@ void MainThread::DestoryAllModules(void) DestroyAppManagerModule(); DestroyStateMachine(); DestroyMissionManagerModule(); + DestroyFilesManagerModule(); DestroyMcuManager(); DestroyHalCppModule(); } diff --git a/application/MissionManager/CMakeLists.txt b/application/MissionManager/CMakeLists.txt index 8e626870..71596696 100644 --- a/application/MissionManager/CMakeLists.txt +++ b/application/MissionManager/CMakeLists.txt @@ -12,6 +12,8 @@ include_directories( ${MIDDLEWARE_SOURCE_PATH}/StateMachine/include ${MIDDLEWARE_SOURCE_PATH}/AppManager/include ${MIDDLEWARE_SOURCE_PATH}/MediaManager/include + ${MIDDLEWARE_SOURCE_PATH}/FilesManager/include + ${MIDDLEWARE_SOURCE_PATH}/StorageManager/include ${MIDDLEWARE_SOURCE_PATH}/McuManager/include ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include ) @@ -24,7 +26,7 @@ aux_source_directory(./src SRC_FILES) set(TARGET_NAME MissionManager) add_library(${TARGET_NAME} STATIC ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StatusCode Log) +target_link_libraries(${TARGET_NAME} McuAskBase StateMachine MediaManager StorageManager StatusCode Log) if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( diff --git a/application/MissionManager/src/MissionManagerMakePtr.cpp b/application/MissionManager/src/MissionManagerMakePtr.cpp index 9b3bfc01..ef1a112a 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.cpp +++ b/application/MissionManager/src/MissionManagerMakePtr.cpp @@ -68,6 +68,7 @@ std::shared_ptr MissionManagerMakePtr::CreateMissionState(const IpcMissio std::shared_ptr MissionManagerMakePtr::CreateStorageHandleState(void) { std::shared_ptr state = std::make_shared(); + std::dynamic_pointer_cast(state)->Init(); return state; } std::shared_ptr MissionManagerMakePtr::CreateSdCardHandleState(void) diff --git a/application/MissionManager/src/SdCardHandleState.cpp b/application/MissionManager/src/SdCardHandleState.cpp index 00f7a9a1..293b715c 100644 --- a/application/MissionManager/src/SdCardHandleState.cpp +++ b/application/MissionManager/src/SdCardHandleState.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include "SdCardHandleState.h" +#include "IFilesManager.h" #include "ILog.h" #include "IMediaManager.h" #include "MissionStateMachine.h" @@ -42,6 +43,8 @@ bool SdCardHandleState::MediaReportHandle(VStateMachineData *msg) LogError("nullptr pointer.\n"); return NOT_EXECUTED; } - LogInfo(" MediaReportHandle, file = %s, path = %s.\n", data->mData.mFileName.c_str(), data->mData.mFilePath.c_str()); + LogInfo("file = %s, path = %s.\n", data->mData.mFileName.c_str(), data->mData.mFilePath.c_str()); + SaveFileInfo saveFileInfo(data->mData.mFileName); + IFilesManager::GetInstance()->SaveFile(saveFileInfo); return EXECUTED; } \ No newline at end of file diff --git a/application/MissionManager/src/StorageHandleState.cpp b/application/MissionManager/src/StorageHandleState.cpp index 6e243fdd..6c39ce78 100644 --- a/application/MissionManager/src/StorageHandleState.cpp +++ b/application/MissionManager/src/StorageHandleState.cpp @@ -31,4 +31,15 @@ void StorageHandleState::GoOutState() bool StorageHandleState::ExecuteStateMsg(VStateMachineData *msg) { return DataProcessing::EventHandle(msg); +} +void StorageHandleState::Init(void) +{ + std::shared_ptr monitor = shared_from_this(); + IStorageManager::GetInstance()->SetMonitor(monitor); +} +void StorageHandleState::UnInit(void) +{ +} +void StorageHandleState::ReportEvent(const StorageEvent &event) +{ } \ No newline at end of file diff --git a/application/MissionManager/src/StorageHandleState.h b/application/MissionManager/src/StorageHandleState.h index 9eb509e5..9876dfb8 100644 --- a/application/MissionManager/src/StorageHandleState.h +++ b/application/MissionManager/src/StorageHandleState.h @@ -17,7 +17,11 @@ #include "DataProcessing.h" #include "IMediaManager.h" #include "IStateMachine.h" -class StorageHandleState : public State, public DataProcessing, public std::enable_shared_from_this +#include "IStorageManager.h" +class StorageHandleState : public State, + public DataProcessing, + public VStorageMoniter, + public std::enable_shared_from_this { public: StorageHandleState(); @@ -25,5 +29,10 @@ public: void GoInState() override; void GoOutState() override; bool ExecuteStateMsg(VStateMachineData *msg) override; + void Init(void); + void UnInit(void); + +private: // About VStorageMoniter + void ReportEvent(const StorageEvent &event) override; }; #endif \ No newline at end of file diff --git a/doc/doxygen_user_guide.md b/doc/doxygen_user_guide.md new file mode 100644 index 00000000..aa8aaef9 --- /dev/null +++ b/doc/doxygen_user_guide.md @@ -0,0 +1,13 @@ +# 1. Linux嵌入式项目使用Doxygen生成API文档 + +## 1.1 Doxygen简介 + +  Doxygen是一个开源的文档生成工具,可以用来生成项目源代码的API文档。 + +## 1.2 Doxygen安装 + +  Doxygen安装非常简单,直接在官网下载最新版本即可。 + +``` + +``` \ No newline at end of file diff --git a/middleware/FilesManager/CMakeLists.txt b/middleware/FilesManager/CMakeLists.txt index a58db72d..ad0b3cd2 100644 --- a/middleware/FilesManager/CMakeLists.txt +++ b/middleware/FilesManager/CMakeLists.txt @@ -6,7 +6,7 @@ set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) include_directories( ./src ./include - # ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include + ${MIDDLEWARE_SOURCE_PATH}/StorageManager/include ${UTILS_SOURCE_PATH}/StatusCode/include ${UTILS_SOURCE_PATH}/Log/include # ${UTILS_SOURCE_PATH}/McuProtocol/include diff --git a/middleware/FilesManager/README.md b/middleware/FilesManager/README.md index 7d8edaae..2cb735da 100644 --- a/middleware/FilesManager/README.md +++ b/middleware/FilesManager/README.md @@ -2,4 +2,27 @@ ## 1.1. 概述 -  IPC产品的文件管理模块。抓拍的图片或者视频的保存/删除/查询等操作通过该模块实现。 \ No newline at end of file +  IPC产品的文件管理模块。抓拍的图片或者视频的保存/删除/查询等操作通过该模块实现。 + +## 1.2. 文件夹管理 + +``` +DCIM/ // 根目录 +├── picture // 图片目录 +│   └── 2024 // 年份记录 +│   ├── 01 // 月份记录 +│   │   └── xxx.jpg +│   └── 02 +└── video // 视频目录 + └── 2024 // 年份记录 + └── 01 // 月份记录 + └── xxx.MP4 +``` + +## 1.3. 文件命名规则 + +**文件类型** + +1. PIR抓拍; +2. 定时抓拍; +3. 手动抓拍; \ No newline at end of file diff --git a/middleware/FilesManager/include/IFilesManager.h b/middleware/FilesManager/include/IFilesManager.h index 6aa1d2f5..1e086bda 100644 --- a/middleware/FilesManager/include/IFilesManager.h +++ b/middleware/FilesManager/include/IFilesManager.h @@ -16,11 +16,21 @@ #define I_FILES_MANAGER_H #include "StatusCode.h" #include +typedef struct save_file_info +{ + save_file_info(const std::string &fileName); + const std::string mFileName; +} SaveFileInfo; +bool CreateFilesManagerModule(void); +bool DestroyFilesManagerModule(void); class IFilesManager { public: IFilesManager() = default; virtual ~IFilesManager() = default; static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual StatusCode Init(void); + virtual StatusCode UnInit(void); + virtual StatusCode SaveFile(const SaveFileInfo &fileInfo); }; #endif \ No newline at end of file diff --git a/middleware/FilesManager/src/FilesManagerImpl.cpp b/middleware/FilesManager/src/FilesManagerImpl.cpp new file mode 100644 index 00000000..6b8d8100 --- /dev/null +++ b/middleware/FilesManager/src/FilesManagerImpl.cpp @@ -0,0 +1,29 @@ +/* + * 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 "FilesManagerImpl.h" +#include "IStorageManager.h" +StatusCode FilesManagerImpl::Init(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode FilesManagerImpl::UnInit(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode FilesManagerImpl::SaveFile(const SaveFileInfo &fileInfo) +{ + IStorageManager::GetInstance()->SaveFile(fileInfo.mFileName, "/DCIM/picture/2024/04/28/test.jpg"); + return CreateStatusCode(STATUS_CODE_OK); +} \ No newline at end of file diff --git a/middleware/FilesManager/src/FilesManagerImpl.h b/middleware/FilesManager/src/FilesManagerImpl.h new file mode 100644 index 00000000..895490e1 --- /dev/null +++ b/middleware/FilesManager/src/FilesManagerImpl.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 FILES_MANAGER_IMPL_H +#define FILES_MANAGER_IMPL_H +#include "IFilesManager.h" +#include +class FilesManagerImpl : public IFilesManager +{ +public: + FilesManagerImpl() = default; + virtual ~FilesManagerImpl() = default; + StatusCode Init(void) override; + StatusCode UnInit(void) override; + StatusCode SaveFile(const SaveFileInfo &fileInfo) override; +}; +#endif \ No newline at end of file diff --git a/middleware/FilesManager/src/FilesManagerMakePtr.cpp b/middleware/FilesManager/src/FilesManagerMakePtr.cpp new file mode 100644 index 00000000..0ced43bd --- /dev/null +++ b/middleware/FilesManager/src/FilesManagerMakePtr.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 "FilesManagerMakePtr.h" +#include "ILog.h" +#include "FilesManagerImpl.h" +bool CreateFilesManagerModule(void) +{ + auto instance = std::make_shared(); + StatusCode code = FilesManagerMakePtr::GetInstance()->CreateFilesManagerModule(instance); + if (IsCodeOK(code)) { + LogInfo("CreateFilesManagerModule is ok.\n"); + IFilesManager::GetInstance(&instance); + return true; + } + return false; +} +bool DestroyFilesManagerModule(void) +{ + auto instance = std::make_shared(); + IFilesManager::GetInstance(&instance); + return true; +} +std::shared_ptr &FilesManagerMakePtr::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 FilesManagerMakePtr::CreateFilesManagerModule(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/FilesManager/src/FilesManagerMakePtr.h b/middleware/FilesManager/src/FilesManagerMakePtr.h new file mode 100644 index 00000000..cab52955 --- /dev/null +++ b/middleware/FilesManager/src/FilesManagerMakePtr.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 FILES_MANAGER_MAKE_PTR_H +#define FILES_MANAGER_MAKE_PTR_H +#include "IFilesManager.h" +#include "StatusCode.h" +#include +class FilesManagerMakePtr +{ +public: + FilesManagerMakePtr() = default; + virtual ~FilesManagerMakePtr() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + virtual const StatusCode CreateFilesManagerModule(std::shared_ptr &impl); +}; +#endif // !FILES_MANAGER_MAKE_PTR_H \ No newline at end of file diff --git a/middleware/FilesManager/src/IFilesManager.cpp b/middleware/FilesManager/src/IFilesManager.cpp index 60cdec99..c65e86de 100644 --- a/middleware/FilesManager/src/IFilesManager.cpp +++ b/middleware/FilesManager/src/IFilesManager.cpp @@ -14,6 +14,9 @@ */ #include "IFilesManager.h" #include "ILog.h" +save_file_info::save_file_info(const std::string &fileName) : mFileName(fileName) +{ +} std::shared_ptr &IFilesManager::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); @@ -27,4 +30,16 @@ std::shared_ptr &IFilesManager::GetInstance(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); + virtual StatusCode SetMonitor(std::shared_ptr &monitor); + virtual StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht); }; #endif \ No newline at end of file diff --git a/middleware/StorageManager/src/EmmcHandle.cpp b/middleware/StorageManager/src/EmmcHandle.cpp new file mode 100644 index 00000000..36e2f070 --- /dev/null +++ b/middleware/StorageManager/src/EmmcHandle.cpp @@ -0,0 +1,15 @@ +/* + * 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 "EmmcHandle.h" \ No newline at end of file diff --git a/middleware/StorageManager/src/EmmcHandle.h b/middleware/StorageManager/src/EmmcHandle.h new file mode 100644 index 00000000..944d1058 --- /dev/null +++ b/middleware/StorageManager/src/EmmcHandle.h @@ -0,0 +1,25 @@ +/* + * 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 EMMC_HANDLE_H +#define EMMC_HANDLE_H +#include "StatusCode.h" +#include "StorageBase.h" +class EmmcHandle : virtual public StorageBase +{ +public: + EmmcHandle() = default; + virtual ~EmmcHandle() = default; +}; +#endif \ No newline at end of file diff --git a/middleware/StorageManager/src/IStorageManager.cpp b/middleware/StorageManager/src/IStorageManager.cpp index 184f82cd..3635c7b8 100644 --- a/middleware/StorageManager/src/IStorageManager.cpp +++ b/middleware/StorageManager/src/IStorageManager.cpp @@ -38,4 +38,13 @@ StatusCode IStorageManager::Init(void) StatusCode IStorageManager::UnInit(void) { return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode IStorageManager::SetMonitor(std::shared_ptr &monitor) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode IStorageManager::SaveFile(const std::string &sourceFile, const std::string &savePaht) +{ + LogInfo("SaveFile: %s to %s\n", sourceFile.c_str(), savePaht.c_str()); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/middleware/StorageManager/src/SdCardHandle.cpp b/middleware/StorageManager/src/SdCardHandle.cpp new file mode 100644 index 00000000..8701a203 --- /dev/null +++ b/middleware/StorageManager/src/SdCardHandle.cpp @@ -0,0 +1,35 @@ +/* + * 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 "SdCardHandle.h" +#include "ILog.h" +void SdCardHandle::Init(void) +{ + IHalCpp::GetInstance()->GetSdCardHal(mSdCardHal); + if (nullptr == mSdCardHal) { + LogWarning("SdCardHal is nullptr.\n"); + return; + } + std::shared_ptr sdMonitor = + std::dynamic_pointer_cast(StorageBase::shared_from_this()); + if (nullptr == sdMonitor) { + LogWarning("sdMonitor is nullptr.\n"); + return; + } + mSdCardHal->SetSdCardMonitor(sdMonitor); +} +void SdCardHandle::UnInit(void) +{ + mSdCardHal.reset(); +} \ No newline at end of file diff --git a/middleware/StorageManager/src/SdCardHandle.h b/middleware/StorageManager/src/SdCardHandle.h new file mode 100644 index 00000000..b5bae96b --- /dev/null +++ b/middleware/StorageManager/src/SdCardHandle.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 SD_CARD_HANDLE_H +#define SD_CARD_HANDLE_H +#include "IHalCpp.h" +#include "StatusCode.h" +#include "StorageBase.h" +#include +class SdCardHandle : public VSdCardHalMonitor, virtual public StorageBase +{ +public: + SdCardHandle() = default; + virtual ~SdCardHandle() = default; + void Init(void); + void UnInit(void); + +protected: + std::shared_ptr mSdCardHal; +}; +#endif \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageBase.cpp b/middleware/StorageManager/src/StorageBase.cpp new file mode 100644 index 00000000..6c97811e --- /dev/null +++ b/middleware/StorageManager/src/StorageBase.cpp @@ -0,0 +1,15 @@ +/* + * 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 "StorageBase.h" \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageBase.h b/middleware/StorageManager/src/StorageBase.h new file mode 100644 index 00000000..4bcef2de --- /dev/null +++ b/middleware/StorageManager/src/StorageBase.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_BASE_H +#define STORAGE_BASE_H +#include "IStorageManager.h" +#include +class StorageBase : public std::enable_shared_from_this +{ +public: + StorageBase() = default; + virtual ~StorageBase() = default; + +protected: + std::weak_ptr mStorageMonitor; +}; +#endif \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageManagerImpl.cpp b/middleware/StorageManager/src/StorageManagerImpl.cpp index b7532d41..2b1a9254 100644 --- a/middleware/StorageManager/src/StorageManagerImpl.cpp +++ b/middleware/StorageManager/src/StorageManagerImpl.cpp @@ -15,9 +15,23 @@ #include "StorageManagerImpl.h" StatusCode StorageManagerImpl::Init(void) { - return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + SdCardHandle::Init(); + return CreateStatusCode(STATUS_CODE_OK); } StatusCode StorageManagerImpl::UnInit(void) { - return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); + SdCardHandle::UnInit(); + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode StorageManagerImpl::SetMonitor(std::shared_ptr &monitor) +{ + mStorageMonitor = monitor; + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode StorageManagerImpl::SaveFile(const std::string &sourceFile, const std::string &savePaht) +{ + constexpr int CMD_BUF_SIZE = 128; + char cmd[CMD_BUF_SIZE] = {0}; + snprintf(cmd, CMD_BUF_SIZE, "cp %s %s", sourceFile.c_str(), savePaht.c_str()); + return CreateStatusCode(STATUS_CODE_OK); } \ No newline at end of file diff --git a/middleware/StorageManager/src/StorageManagerImpl.h b/middleware/StorageManager/src/StorageManagerImpl.h index 604c2251..95e0ee63 100644 --- a/middleware/StorageManager/src/StorageManagerImpl.h +++ b/middleware/StorageManager/src/StorageManagerImpl.h @@ -14,14 +14,18 @@ */ #ifndef STORAGE_MANAGER_IMPL_H #define STORAGE_MANAGER_IMPL_H +#include "EmmcHandle.h" #include "IStorageManager.h" +#include "SdCardHandle.h" #include -class StorageManagerImpl : public IStorageManager, public std::enable_shared_from_this +class StorageManagerImpl : public IStorageManager, public SdCardHandle, public EmmcHandle { public: StorageManagerImpl() = default; virtual ~StorageManagerImpl() = default; StatusCode Init(void) override; StatusCode UnInit(void) override; + StatusCode SetMonitor(std::shared_ptr &monitor) override; + StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht) override; }; #endif \ No newline at end of file