mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Backup.
This commit is contained in:
parent
ef0a94eb55
commit
40b5a835f8
|
@ -75,5 +75,6 @@ set(APP_MANAGER_TCP_SERVER_PORT "9876")
|
||||||
# ------------ build AppManager end ------------ #
|
# ------------ build AppManager end ------------ #
|
||||||
|
|
||||||
# ------------ build sd card ------------ #
|
# ------------ 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 ------------ #
|
# ------------ build sd card end ------------ #
|
|
@ -17,6 +17,7 @@ include_directories(
|
||||||
# )
|
# )
|
||||||
|
|
||||||
add_definitions(-DSD_CARD_DEV=\"${SD_CARD_DEV}\")
|
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(./abstract ABSTRACT_SRC_FILES)
|
||||||
aux_source_directory(./src IMPL_SRC_FILES)
|
aux_source_directory(./src IMPL_SRC_FILES)
|
||||||
|
|
|
@ -61,6 +61,9 @@ std::shared_ptr<IHalCpp> &IHalCpp::GetInstance(std::shared_ptr<IHalCpp> *impl)
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
void VSdCardHal::SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor)
|
||||||
|
{
|
||||||
|
}
|
||||||
StatusCode IHalCpp::Init(void)
|
StatusCode IHalCpp::Init(void)
|
||||||
{
|
{
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
|
|
@ -111,6 +111,7 @@ class VSdCardHal
|
||||||
public:
|
public:
|
||||||
VSdCardHal() = default;
|
VSdCardHal() = default;
|
||||||
virtual ~VSdCardHal() = default;
|
virtual ~VSdCardHal() = default;
|
||||||
|
virtual void SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor);
|
||||||
};
|
};
|
||||||
class IHalCpp
|
class IHalCpp
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,10 @@ SdCardHal::SdCardHal()
|
||||||
{
|
{
|
||||||
mThreadRuning = false;
|
mThreadRuning = false;
|
||||||
}
|
}
|
||||||
|
void SdCardHal::SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor)
|
||||||
|
{
|
||||||
|
mMonitor = monitor;
|
||||||
|
}
|
||||||
void SdCardHal::Init(void)
|
void SdCardHal::Init(void)
|
||||||
{
|
{
|
||||||
auto detectThread = [](std::shared_ptr<SdCardHal> sdCardHal) {
|
auto detectThread = [](std::shared_ptr<SdCardHal> sdCardHal) {
|
||||||
|
@ -47,7 +51,8 @@ void SdCardHal::DevDetectingThread(void)
|
||||||
constexpr int SLEEP_TIME_MS = 100;
|
constexpr int SLEEP_TIME_MS = 100;
|
||||||
SdCardHalStatus status = SdCardHalStatus::END;
|
SdCardHalStatus status = SdCardHalStatus::END;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
const char *dev = "/dev/mmcblk0";
|
// const char *dev = "/dev/mmcblk1p1";
|
||||||
|
const char *dev = SD_CARD_DEV;
|
||||||
mThreadRuning = true;
|
mThreadRuning = true;
|
||||||
while (mThreadRuning) {
|
while (mThreadRuning) {
|
||||||
fd = open(dev, O_RDONLY);
|
fd = open(dev, O_RDONLY);
|
||||||
|
@ -55,7 +60,7 @@ void SdCardHal::DevDetectingThread(void)
|
||||||
LogInfo("sdCardHal: %s open failed.\n", dev);
|
LogInfo("sdCardHal: %s open failed.\n", dev);
|
||||||
if (SdCardHalStatus::PULL_OUT != status) {
|
if (SdCardHalStatus::PULL_OUT != status) {
|
||||||
status = SdCardHalStatus::PULL_OUT;
|
status = SdCardHalStatus::PULL_OUT;
|
||||||
// TODO: pull out
|
ReportDetecedChangedResult(status);
|
||||||
}
|
}
|
||||||
goto CONTINUE;
|
goto CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +69,7 @@ void SdCardHal::DevDetectingThread(void)
|
||||||
LogInfo("sdCardHal: %s fstat failed.\n", dev);
|
LogInfo("sdCardHal: %s fstat failed.\n", dev);
|
||||||
if (SdCardHalStatus::ERROR != status) {
|
if (SdCardHalStatus::ERROR != status) {
|
||||||
status = SdCardHalStatus::ERROR;
|
status = SdCardHalStatus::ERROR;
|
||||||
// TODO: error
|
ReportDetecedChangedResult(status);
|
||||||
}
|
}
|
||||||
goto CONTINUE;
|
goto CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -72,17 +77,33 @@ void SdCardHal::DevDetectingThread(void)
|
||||||
LogInfo("sdCardHal: %s is not block device.\n", dev);
|
LogInfo("sdCardHal: %s is not block device.\n", dev);
|
||||||
if (SdCardHalStatus::PULL_OUT != status) {
|
if (SdCardHalStatus::PULL_OUT != status) {
|
||||||
status = SdCardHalStatus::PULL_OUT;
|
status = SdCardHalStatus::PULL_OUT;
|
||||||
// TODO: pull out
|
ReportDetecedChangedResult(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogInfo("sdCardHal: %s is inserted.\n", dev);
|
LogInfo("sdCardHal: %s is inserted.\n", dev);
|
||||||
if (SdCardHalStatus::INSERTED != status) {
|
if (SdCardHalStatus::INSERTED != status) {
|
||||||
status = SdCardHalStatus::INSERTED;
|
status = SdCardHalStatus::INSERTED;
|
||||||
// TODO: inserted
|
ReportDetecedChangedResult(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CONTINUE:
|
CONTINUE:
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,12 +21,17 @@ class SdCardHal : public VSdCardHal, public std::enable_shared_from_this<SdCardH
|
||||||
public:
|
public:
|
||||||
SdCardHal();
|
SdCardHal();
|
||||||
virtual ~SdCardHal() = default;
|
virtual ~SdCardHal() = default;
|
||||||
|
void SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor) override;
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
void DevDetectingThread(void);
|
void DevDetectingThread(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ReportDetecedChangedResult(const SdCardHalStatus &status);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mThreadRuning;
|
bool mThreadRuning;
|
||||||
std::thread mDevDetectingThread;
|
std::thread mDevDetectingThread;
|
||||||
|
std::weak_ptr<VSdCardHalMonitor> mMonitor;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -6,3 +6,4 @@ add_subdirectory(McuAskBase)
|
||||||
add_subdirectory(MediaManager)
|
add_subdirectory(MediaManager)
|
||||||
add_subdirectory(AppManager)
|
add_subdirectory(AppManager)
|
||||||
add_subdirectory(StorageManager)
|
add_subdirectory(StorageManager)
|
||||||
|
add_subdirectory(FilesManager)
|
64
middleware/FilesManager/CMakeLists.txt
Normal file
64
middleware/FilesManager/CMakeLists.txt
Normal file
|
@ -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)
|
5
middleware/FilesManager/README.md
Normal file
5
middleware/FilesManager/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# 1. 文件管理
|
||||||
|
|
||||||
|
## 1.1. 概述
|
||||||
|
|
||||||
|
  IPC产品的文件管理模块。抓拍的图片或者视频的保存/删除/查询等操作通过该模块实现。
|
26
middleware/FilesManager/include/IFilesManager.h
Normal file
26
middleware/FilesManager/include/IFilesManager.h
Normal file
|
@ -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 <memory>
|
||||||
|
class IFilesManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IFilesManager() = default;
|
||||||
|
virtual ~IFilesManager() = default;
|
||||||
|
static std::shared_ptr<IFilesManager> &GetInstance(std::shared_ptr<IFilesManager> *impl = nullptr);
|
||||||
|
};
|
||||||
|
#endif
|
30
middleware/FilesManager/src/IFilesManager.cpp
Normal file
30
middleware/FilesManager/src/IFilesManager.cpp
Normal file
|
@ -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> &IFilesManager::GetInstance(std::shared_ptr<IFilesManager> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<IFilesManager>();
|
||||||
|
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;
|
||||||
|
}
|
|
@ -40,6 +40,7 @@ void MediaManagerImpl::ReportEvent(const CameraReportEvent &event)
|
||||||
auto monitor = mMediaMonitor.lock();
|
auto monitor = mMediaMonitor.lock();
|
||||||
if (mMediaMonitor.expired())
|
if (mMediaMonitor.expired())
|
||||||
{
|
{
|
||||||
|
LogWarning("MediaMonitor is expired.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
monitor->ReportEvent(reprot);
|
monitor->ReportEvent(reprot);
|
||||||
|
|
5
middleware/StorageManager/README.md
Normal file
5
middleware/StorageManager/README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# 1. 存储管理
|
||||||
|
|
||||||
|
## 1.1. 概述
|
||||||
|
|
||||||
|
  对设备的存储进行管理,包括SD卡,EMMC等。
|
|
@ -14,5 +14,32 @@
|
||||||
*/
|
*/
|
||||||
#ifndef I_STORAGE_MANAGER_H
|
#ifndef I_STORAGE_MANAGER_H
|
||||||
#define I_STORAGE_MANAGER_H
|
#define I_STORAGE_MANAGER_H
|
||||||
|
#include "StatusCode.h"
|
||||||
|
#include <memory>
|
||||||
|
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<IStorageManager> &GetInstance(std::shared_ptr<IStorageManager> *impl = nullptr);
|
||||||
|
virtual StatusCode Init(void);
|
||||||
|
virtual StatusCode UnInit(void);
|
||||||
|
virtual StatusCode SaveFile(const std::string &path, const std::string &content);
|
||||||
|
};
|
||||||
#endif
|
#endif
|
|
@ -13,3 +13,29 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "IStorageManager.h"
|
#include "IStorageManager.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
void VStorageMoniter::ReportEvent(const StorageEvent &event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
std::shared_ptr<IStorageManager> &IStorageManager::GetInstance(std::shared_ptr<IStorageManager> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<IStorageManager>();
|
||||||
|
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);
|
||||||
|
}
|
23
middleware/StorageManager/src/StorageManagerImpl.cpp
Normal file
23
middleware/StorageManager/src/StorageManagerImpl.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
27
middleware/StorageManager/src/StorageManagerImpl.h
Normal file
27
middleware/StorageManager/src/StorageManagerImpl.h
Normal file
|
@ -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 <map>
|
||||||
|
class StorageManagerImpl : public IStorageManager, public std::enable_shared_from_this<StorageManagerImpl>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StorageManagerImpl() = default;
|
||||||
|
virtual ~StorageManagerImpl() = default;
|
||||||
|
StatusCode Init(void) override;
|
||||||
|
StatusCode UnInit(void) override;
|
||||||
|
};
|
||||||
|
#endif
|
54
middleware/StorageManager/src/StorageManagerMakePtr.cpp
Normal file
54
middleware/StorageManager/src/StorageManagerMakePtr.cpp
Normal file
|
@ -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<IStorageManager>();
|
||||||
|
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>();
|
||||||
|
IStorageManager::GetInstance(&instance);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
std::shared_ptr<StorageManagerMakePtr> &StorageManagerMakePtr::GetInstance(std::shared_ptr<StorageManagerMakePtr> *impl)
|
||||||
|
{
|
||||||
|
static auto instance = std::make_shared<StorageManagerMakePtr>();
|
||||||
|
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<IStorageManager> &impl)
|
||||||
|
{
|
||||||
|
auto tmp = std::make_shared<StorageManagerImpl>();
|
||||||
|
impl = tmp;
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
28
middleware/StorageManager/src/StorageManagerMakePtr.h
Normal file
28
middleware/StorageManager/src/StorageManagerMakePtr.h
Normal file
|
@ -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 <memory>
|
||||||
|
class StorageManagerMakePtr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StorageManagerMakePtr() = default;
|
||||||
|
virtual ~StorageManagerMakePtr() = default;
|
||||||
|
static std::shared_ptr<StorageManagerMakePtr> &GetInstance(std::shared_ptr<StorageManagerMakePtr> *impl = nullptr);
|
||||||
|
virtual const StatusCode CreateStorageManagerModule(std::shared_ptr<IStorageManager> &impl);
|
||||||
|
};
|
||||||
|
#endif // !STORAGE_MANAGER_MAKE_PTR_H
|
Loading…
Reference in New Issue
Block a user