From cc493b6c3d20c6fd94f5ea9df8dbafa422c60b16 Mon Sep 17 00:00:00 2001 From: xiaojiazhu <258828110.@qq.com> Date: Sun, 5 May 2024 08:45:45 -0700 Subject: [PATCH] Backup. --- .../sqlite3/sqlite-3430000/CMakeLists.txt | 2 - middleware/FilesManager/CMakeLists.txt | 4 +- middleware/FilesManager/README.md | 10 +++- middleware/FilesManager/src/FilesDatabase.h | 2 + .../FilesManager/src/FilesManagerImpl.cpp | 1 + .../src/sqlite3/FilesDatabase.cpp | 9 ++++ .../FilesManager/src/sqlite3/SqliteHandle.cpp | 46 +++++++++++++++++++ .../FilesManager/src/sqlite3/SqliteHandle.h | 27 +++++++++++ 8 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 middleware/FilesManager/src/sqlite3/SqliteHandle.cpp create mode 100644 middleware/FilesManager/src/sqlite3/SqliteHandle.h diff --git a/external/sqlite3/sqlite-3430000/CMakeLists.txt b/external/sqlite3/sqlite-3430000/CMakeLists.txt index 1ddcb116..f29b00b1 100644 --- a/external/sqlite3/sqlite-3430000/CMakeLists.txt +++ b/external/sqlite3/sqlite-3430000/CMakeLists.txt @@ -9,8 +9,6 @@ include_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) - - file(GLOB_RECURSE SRC_FILES ./sqlite3.c) set(TARGET_NAME sqlite3) diff --git a/middleware/FilesManager/CMakeLists.txt b/middleware/FilesManager/CMakeLists.txt index 914d16f9..66522da3 100644 --- a/middleware/FilesManager/CMakeLists.txt +++ b/middleware/FilesManager/CMakeLists.txt @@ -6,10 +6,10 @@ set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) include_directories( ./src ./include + ${EXTERNAL_SOURCE_PATH}/sqlite3/sqlite-3430000 ${MIDDLEWARE_SOURCE_PATH}/StorageManager/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 @@ -22,7 +22,7 @@ aux_source_directory(./src/sqlite3 SRC_FILES) set(TARGET_NAME FilesManager) add_library(${TARGET_NAME} STATIC ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} StatusCode Log) +target_link_libraries(${TARGET_NAME} sqlite3 StatusCode Log) if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( diff --git a/middleware/FilesManager/README.md b/middleware/FilesManager/README.md index 2cb735da..eda03733 100644 --- a/middleware/FilesManager/README.md +++ b/middleware/FilesManager/README.md @@ -4,7 +4,13 @@   IPC产品的文件管理模块。抓拍的图片或者视频的保存/删除/查询等操作通过该模块实现。 -## 1.2. 文件夹管理 +## 1.2. 数据库管理设计 + +  考虑到拓展性,使用数据库salite3对文件的各种属性进行管理。 + +### 1.2.1. 数据库表 + +## 1.3. 文件夹管理 ``` DCIM/ // 根目录 @@ -19,7 +25,7 @@ DCIM/ // 根目录 └── xxx.MP4 ``` -## 1.3. 文件命名规则 +## 1.4. 文件命名规则 **文件类型** diff --git a/middleware/FilesManager/src/FilesDatabase.h b/middleware/FilesManager/src/FilesDatabase.h index 16aae5dc..0cc2f04d 100644 --- a/middleware/FilesManager/src/FilesDatabase.h +++ b/middleware/FilesManager/src/FilesDatabase.h @@ -22,6 +22,8 @@ class FilesDatabase : public FilesHandle public: FilesDatabase() = default; virtual ~FilesDatabase() = default; + void Init(void); + void UnInit(void); StatusCode DatabaseSaveFile(const SaveFileInfo &fileInfo); }; #endif \ No newline at end of file diff --git a/middleware/FilesManager/src/FilesManagerImpl.cpp b/middleware/FilesManager/src/FilesManagerImpl.cpp index 289910fa..aa3dc8fb 100644 --- a/middleware/FilesManager/src/FilesManagerImpl.cpp +++ b/middleware/FilesManager/src/FilesManagerImpl.cpp @@ -16,6 +16,7 @@ #include "IStorageManager.h" StatusCode FilesManagerImpl::Init(void) { + FilesDatabase::Init(); return CreateStatusCode(STATUS_CODE_OK); } StatusCode FilesManagerImpl::UnInit(void) diff --git a/middleware/FilesManager/src/sqlite3/FilesDatabase.cpp b/middleware/FilesManager/src/sqlite3/FilesDatabase.cpp index 95a0fc24..1c19e0d6 100644 --- a/middleware/FilesManager/src/sqlite3/FilesDatabase.cpp +++ b/middleware/FilesManager/src/sqlite3/FilesDatabase.cpp @@ -15,6 +15,15 @@ #include "FilesDatabase.h" #include "ILog.h" #include "IStorageManager.h" +#include "SqliteHandle.h" +void FilesDatabase::Init(void) +{ + SqliteHandle::GetInstance()->Init(); +} +void FilesDatabase::UnInit(void) +{ + SqliteHandle::GetInstance()->UnInit(); +} StatusCode FilesDatabase::DatabaseSaveFile(const SaveFileInfo &fileInfo) { std::string saveFile = FilesHandle::CreateFilePathName(fileInfo.mFileName); diff --git a/middleware/FilesManager/src/sqlite3/SqliteHandle.cpp b/middleware/FilesManager/src/sqlite3/SqliteHandle.cpp new file mode 100644 index 00000000..f67be8f2 --- /dev/null +++ b/middleware/FilesManager/src/sqlite3/SqliteHandle.cpp @@ -0,0 +1,46 @@ +/* + * 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 "SqliteHandle.h" +#include "ILog.h" +#include "sqlite3.h" +std::shared_ptr &SqliteHandle::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; +} +void SqliteHandle::Init(void) +{ + sqlite3 *db; + int rc; + rc = sqlite3_open("test.db", &db); + if (rc) { + fprintf(stderr, "无法打开数据库: %s\n", sqlite3_errmsg(db)); + sqlite3_close(db); + return; + } +} +void SqliteHandle::UnInit(void) +{ + +} \ No newline at end of file diff --git a/middleware/FilesManager/src/sqlite3/SqliteHandle.h b/middleware/FilesManager/src/sqlite3/SqliteHandle.h new file mode 100644 index 00000000..2aae728e --- /dev/null +++ b/middleware/FilesManager/src/sqlite3/SqliteHandle.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 SQLITE_HANDLE_H +#define SQLITE_HANDLE_H +#include +class SqliteHandle +{ +public: + SqliteHandle() = default; + virtual ~SqliteHandle() = default; + static std::shared_ptr &GetInstance(std::shared_ptr *impl = nullptr); + void Init(void); + void UnInit(void); +}; +#endif \ No newline at end of file