mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Improve:sd card hal.
This commit is contained in:
parent
ae9e0a67c1
commit
385884baec
|
@ -49,9 +49,11 @@ StatusCode AppMonitor::GetMediaInfo(AppGetMediaInfo ¶m)
|
|||
StatusCode AppMonitor::GetSdCardInfo(AppGetSdCardInfo ¶m)
|
||||
{
|
||||
LogInfo("AppMonitor::GetSdCardInfo.\n");
|
||||
param.mStatus = SdCardStatus::NORMAL;
|
||||
param.mFree = 1024 * 32;
|
||||
param.mTotal = 1024 * 32;
|
||||
SdCardInfo info;
|
||||
IStorageManager::GetInstance()->GetSdCardInfo(info);
|
||||
param.mStatus = SdCardStatusConvert(info.mEvent);
|
||||
param.mFree = info.mFreeSizeMB;
|
||||
param.mTotal = info.mTotalSizeMB;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppMonitor::GetBatteryInfo(AppGetBatteryInfo ¶m)
|
||||
|
@ -140,3 +142,16 @@ StatusCode AppMonitor::GetThumbnail(AppGetThumbnail ¶m)
|
|||
param.mThumbnail = "./34a396526922a33e97906920dbfef2a5.jpg";
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
SdCardStatus AppMonitor::SdCardStatusConvert(const StorageEvent &event)
|
||||
{
|
||||
switch (event) {
|
||||
case StorageEvent::SD_CARD_INSERT:
|
||||
return SdCardStatus::NORMAL;
|
||||
case StorageEvent::SD_CARD_REMOVE:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
case StorageEvent::SD_ABNORMAL:
|
||||
return SdCardStatus::NOT_INSERTED;
|
||||
default:
|
||||
return SdCardStatus::END;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
#ifndef APP_MONITOR_H
|
||||
#define APP_MONITOR_H
|
||||
#include "IAppManager.h"
|
||||
#include "IStorageManager.h"
|
||||
class AppMonitor : public VAppMonitor
|
||||
{
|
||||
public:
|
||||
|
@ -37,5 +38,8 @@ public:
|
|||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||
StatusCode GetThumbnail(AppGetThumbnail ¶m) override;
|
||||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
};
|
||||
#endif
|
|
@ -73,6 +73,10 @@ SdCardHalStatus VSdCardHal::GetSdCardStatus(void)
|
|||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return SdCardHalStatus::END;
|
||||
}
|
||||
StatusCode VSdCardHal::GetCapacity(unsigned long long &totalSizeMB, unsigned long long &freeSizeMB)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IHalCpp::Init(void)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
virtual ~VSdCardHal() = default;
|
||||
virtual void SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor);
|
||||
virtual SdCardHalStatus GetSdCardStatus(void);
|
||||
virtual StatusCode GetCapacity(unsigned long long &totalSizeMB, unsigned long long &freeSizeMB);
|
||||
};
|
||||
class IHalCpp
|
||||
{
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
const char *SD_CARD_DEVICE = SD_CARD_DEV;
|
||||
|
@ -37,6 +38,22 @@ SdCardHalStatus SdCardHal::GetSdCardStatus(void)
|
|||
{
|
||||
return mStatus;
|
||||
}
|
||||
StatusCode SdCardHal::GetCapacity(unsigned long long &totalSizeMB, unsigned long long &freeSizeMB)
|
||||
{
|
||||
constexpr int ONE_MB = 1024 * 1024;
|
||||
struct statvfs stat;
|
||||
if (statvfs(SD_CARD_DEVICE, &stat) != 0) {
|
||||
perror("statvfs");
|
||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||
}
|
||||
|
||||
totalSizeMB = (stat.f_frsize * stat.f_blocks) / ONE_MB;
|
||||
freeSizeMB = (stat.f_frsize * stat.f_bfree) / ONE_MB;
|
||||
|
||||
LogInfo("Total size: %llu MB\n", totalSizeMB);
|
||||
LogInfo("Free size: %llu MB\n", freeSizeMB);
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void SdCardHal::Init(void)
|
||||
{
|
||||
auto detectThread = [](std::shared_ptr<SdCardHal> sdCardHal) {
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
virtual ~SdCardHal() = default;
|
||||
void SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor) override;
|
||||
SdCardHalStatus GetSdCardStatus(void) override;
|
||||
StatusCode GetCapacity(unsigned long long &totalSizeMB, unsigned long long &freeSizeMB) override;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
void DevDetectingThread(void);
|
||||
|
|
|
@ -201,8 +201,8 @@ typedef struct app_get_sd_card_info
|
|||
{
|
||||
app_get_sd_card_info();
|
||||
SdCardStatus mStatus;
|
||||
int mFree;
|
||||
int mTotal;
|
||||
unsigned long long mFree;
|
||||
unsigned long long mTotal;
|
||||
} AppGetSdCardInfo;
|
||||
typedef struct app_get_battery_info
|
||||
{
|
||||
|
|
|
@ -26,6 +26,13 @@ enum class StorageEvent
|
|||
EMMC_NORMAL,
|
||||
END
|
||||
};
|
||||
typedef struct sd_card_info
|
||||
{
|
||||
sd_card_info();
|
||||
StorageEvent mEvent;
|
||||
unsigned long long mTotalSizeMB;
|
||||
unsigned long long mFreeSizeMB;
|
||||
} SdCardInfo;
|
||||
class VStorageMoniter
|
||||
{
|
||||
public:
|
||||
|
@ -44,5 +51,6 @@ public:
|
|||
virtual StatusCode SetMonitor(std::shared_ptr<VStorageMoniter> &monitor);
|
||||
virtual StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht);
|
||||
virtual const char *PrintStringStorageEvent(const StorageEvent &event);
|
||||
virtual StatusCode GetSdCardInfo(SdCardInfo &info);
|
||||
};
|
||||
#endif
|
|
@ -14,6 +14,9 @@
|
|||
*/
|
||||
#include "IStorageManager.h"
|
||||
#include "ILog.h"
|
||||
sd_card_info::sd_card_info() : mEvent(StorageEvent::END), mTotalSizeMB(0), mFreeSizeMB(0)
|
||||
{
|
||||
}
|
||||
void VStorageMoniter::ReportEvent(const StorageEvent &event)
|
||||
{
|
||||
}
|
||||
|
@ -51,3 +54,7 @@ const char *IStorageManager::PrintStringStorageEvent(const StorageEvent &event)
|
|||
{
|
||||
return "STATUS_CODE_VIRTUAL_FUNCTION";
|
||||
}
|
||||
StatusCode IStorageManager::GetSdCardInfo(SdCardInfo &info)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -25,7 +25,12 @@ void SdCardHandle::ReportEvent(const SdCardHalStatus &status)
|
|||
}
|
||||
monitor->ReportEvent(StorageEventConvert(status));
|
||||
}
|
||||
void SdCardHandle::Init(void)
|
||||
StatusCode SdCardHandle::GetSdCardInfo(SdCardInfo &info)
|
||||
{
|
||||
info.mEvent = StorageEventConvert(mSdCardHal->GetSdCardStatus());
|
||||
return mSdCardHal->GetCapacity(info.mTotalSizeMB, info.mFreeSizeMB);
|
||||
}
|
||||
void SdCardHandle::SdCardInit(void)
|
||||
{
|
||||
IHalCpp::GetInstance()->GetSdCardHal(mSdCardHal);
|
||||
if (nullptr == mSdCardHal) {
|
||||
|
@ -40,7 +45,7 @@ void SdCardHandle::Init(void)
|
|||
}
|
||||
mSdCardHal->SetSdCardMonitor(sdMonitor);
|
||||
}
|
||||
void SdCardHandle::UnInit(void)
|
||||
void SdCardHandle::SdCardUnInit(void)
|
||||
{
|
||||
mSdCardHal.reset();
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@ public:
|
|||
SdCardHandle() = default;
|
||||
virtual ~SdCardHandle() = default;
|
||||
void ReportEvent(const SdCardHalStatus &status) override;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
StatusCode GetSdCardInfo(SdCardInfo &info) override;
|
||||
void SdCardInit(void);
|
||||
void SdCardUnInit(void);
|
||||
|
||||
protected:
|
||||
StatusCode SdSaveFile(const std::string &sourceFile, const std::string &savePaht);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define STORAGE_BASE_H
|
||||
#include "IStorageManager.h"
|
||||
#include <memory>
|
||||
class StorageBase : public std::enable_shared_from_this<StorageBase>
|
||||
class StorageBase : public IStorageManager, public std::enable_shared_from_this<StorageBase>
|
||||
{
|
||||
public:
|
||||
StorageBase() = default;
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#include "ILog.h"
|
||||
StatusCode StorageManagerImpl::Init(void)
|
||||
{
|
||||
SdCardHandle::Init();
|
||||
SdCardHandle::SdCardInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode StorageManagerImpl::UnInit(void)
|
||||
{
|
||||
SdCardHandle::UnInit();
|
||||
SdCardHandle::SdCardUnInit();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode StorageManagerImpl::SetMonitor(std::shared_ptr<VStorageMoniter> &monitor)
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "IStorageManager.h"
|
||||
#include "SdCardHandle.h"
|
||||
#include <map>
|
||||
class StorageManagerImpl : public IStorageManager, public SdCardHandle, public EmmcHandle
|
||||
class StorageManagerImpl : public SdCardHandle, public EmmcHandle
|
||||
{
|
||||
public:
|
||||
StorageManagerImpl() = default;
|
||||
|
|
|
@ -77,7 +77,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_Demo)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetProductInfo();
|
||||
AppManagerTestTool::MockGetProductInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetDeviceAttr)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetDeviceAttr();
|
||||
AppManagerTestTool::MockGetDeviceAttr();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetMediaInfo)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetMediaInfo();
|
||||
AppManagerTestTool::MockGetMediaInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetSdCardInfo)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetSdCardInfo();
|
||||
AppManagerTestTool::MockGetSdCardInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetBatteryInfo)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetBatteryInfo();
|
||||
AppManagerTestTool::MockGetBatteryInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamValue)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetParamValue();
|
||||
AppManagerTestTool::MockGetParamValue();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetCapability)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetCapability();
|
||||
AppManagerTestTool::MockGetCapability();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetLockVideoStatus)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetLockVideoStatus();
|
||||
AppManagerTestTool::MockGetLockVideoStatus();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetStorageInfo)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageInfo();
|
||||
AppManagerTestTool::MockGetStorageInfo();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetStorageFileList)
|
|||
IAppManager::GetInstance()->Init(mAppParam);
|
||||
IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockGetStorageFileList();
|
||||
AppManagerTestTool::MockGetStorageFileList();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IAppManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user