Add sqlite3 function.
This commit is contained in:
parent
cf16b8bca8
commit
4706bfa7dd
|
@ -16,11 +16,14 @@
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "IStateMachine.h"
|
#include "IStateMachine.h"
|
||||||
|
#include "MissionStateMachine.h"
|
||||||
|
#include <functional>
|
||||||
IdleState::IdleState() : State("IdleState")
|
IdleState::IdleState() : State("IdleState")
|
||||||
{
|
{
|
||||||
// mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&IdleState::MediaReportHandle, this, _1);
|
// mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&IdleState::MediaReportHandle, this, _1);
|
||||||
// mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
// mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||||
// std::bind(&IdleState::SdCardEventHandle, this, _1);
|
// std::bind(&IdleState::SdCardEventHandle, this, _1);
|
||||||
|
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] = std::bind(&IdleState::ResetKeyMediaTaskHandle, this, _1);
|
||||||
}
|
}
|
||||||
void IdleState::GoInState()
|
void IdleState::GoInState()
|
||||||
{
|
{
|
||||||
|
@ -33,4 +36,10 @@ void IdleState::GoOutState()
|
||||||
bool IdleState::ExecuteStateMsg(VStateMachineData *msg)
|
bool IdleState::ExecuteStateMsg(VStateMachineData *msg)
|
||||||
{
|
{
|
||||||
return DataProcessing::EventHandle(msg);
|
return DataProcessing::EventHandle(msg);
|
||||||
|
}
|
||||||
|
bool IdleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||||
|
{
|
||||||
|
MissionStateMachine::GetInstance()->DelayMessage(msg);
|
||||||
|
MissionStateMachine::GetInstance()->SwitchState(SystemState::STORAGE_HANDLE_STATE);
|
||||||
|
return EXECUTED;
|
||||||
}
|
}
|
|
@ -25,6 +25,9 @@ public:
|
||||||
void GoOutState() override;
|
void GoOutState() override;
|
||||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -16,9 +16,11 @@
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
#include "IMediaManager.h"
|
#include "IMediaManager.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||||
const std::weak_ptr<VMediaTaskIniator> &iniator)
|
const std::weak_ptr<VMediaTaskIniator> &iniator, const unsigned long &serialNumber,
|
||||||
: mType(type), mBindEvent(bindEvent), mIniator(iniator)
|
const std::string &savePath)
|
||||||
|
: mType(type), mBindEvent(bindEvent), mIniator(iniator), mSerialNumber(serialNumber), mSavePath(savePath)
|
||||||
{
|
{
|
||||||
mResponseData.reset();
|
mResponseData.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ class MediaTask : public VMediaTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent,
|
||||||
const std::weak_ptr<VMediaTaskIniator> &iniator);
|
const std::weak_ptr<VMediaTaskIniator> &iniator, const unsigned long &serialNumber,
|
||||||
|
const std::string &savePath);
|
||||||
virtual ~MediaTask() = default;
|
virtual ~MediaTask() = default;
|
||||||
virtual unsigned int GetTaskTimeOutMs(void);
|
virtual unsigned int GetTaskTimeOutMs(void);
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ private:
|
||||||
const MediaTaskType mType;
|
const MediaTaskType mType;
|
||||||
const InternalStateEvent mBindEvent;
|
const InternalStateEvent mBindEvent;
|
||||||
const std::weak_ptr<VMediaTaskIniator> mIniator;
|
const std::weak_ptr<VMediaTaskIniator> mIniator;
|
||||||
|
const unsigned long mSerialNumber;
|
||||||
|
const std::string mSavePath;
|
||||||
bool mFinished = false;
|
bool mFinished = false;
|
||||||
std::shared_ptr<MediaTaskResponse> mResponseData;
|
std::shared_ptr<MediaTaskResponse> mResponseData;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
#include "MediaTaskHandle.h"
|
#include "MediaTaskHandle.h"
|
||||||
#include "DataProcessing.h"
|
#include "DataProcessing.h"
|
||||||
|
#include "IFilesManager.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "IMediaManager.h"
|
#include "IMediaManager.h"
|
||||||
#include "IMissionManager.h"
|
#include "IMissionManager.h"
|
||||||
|
@ -38,7 +39,9 @@ void MediaTaskHandle::UnInit(void)
|
||||||
void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent,
|
void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent,
|
||||||
const std::shared_ptr<VMediaTaskIniator> &iniator)
|
const std::shared_ptr<VMediaTaskIniator> &iniator)
|
||||||
{
|
{
|
||||||
std::shared_ptr<VMediaTask> task = std::make_shared<MediaTask>(MediaTaskType::END, bindEvent, iniator);
|
InfoToBeSaved info = IFilesManager::GetInstance()->GetInfoForSavingFiles(1);
|
||||||
|
std::shared_ptr<VMediaTask> task =
|
||||||
|
std::make_shared<MediaTask>(MediaTaskType::END, bindEvent, iniator, info.mSerialNumber, info.mSavingPath);
|
||||||
if (!mMediaHandle) {
|
if (!mMediaHandle) {
|
||||||
LogError("MediaHandle is null");
|
LogError("MediaHandle is null");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
const bool NOT_EXECUTED = false;
|
const bool NOT_EXECUTED = false;
|
||||||
const bool EXECUTED = true;
|
const bool EXECUTED = true;
|
||||||
|
constexpr bool FATHER_HANDLE_MESSAGE = NOT_EXECUTED;
|
||||||
|
constexpr bool HANDLE_HELPESS = EXECUTED;
|
||||||
enum class SystemState
|
enum class SystemState
|
||||||
{
|
{
|
||||||
TOP_STATE = 0,
|
TOP_STATE = 0,
|
||||||
|
|
|
@ -30,6 +30,8 @@ SdCardHandleState::SdCardHandleState() : State("SdCardHandleState"), mSdCardStat
|
||||||
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&SdCardHandleState::MediaReportHandle, this, _1);
|
mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&SdCardHandleState::MediaReportHandle, this, _1);
|
||||||
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] =
|
||||||
std::bind(&SdCardHandleState::SdCardEventHandle, this, _1);
|
std::bind(&SdCardHandleState::SdCardEventHandle, this, _1);
|
||||||
|
mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] =
|
||||||
|
std::bind(&SdCardHandleState::ResetKeyMediaTaskHandle, this, _1);
|
||||||
}
|
}
|
||||||
void SdCardHandleState::GoInState()
|
void SdCardHandleState::GoInState()
|
||||||
{
|
{
|
||||||
|
@ -86,9 +88,18 @@ bool SdCardHandleState::SdCardEventHandle(VStateMachineData *msg)
|
||||||
}
|
}
|
||||||
mSdCardStatus = data->mData;
|
mSdCardStatus = data->mData;
|
||||||
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) {
|
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) {
|
||||||
|
IFilesManager::GetInstance()->Init();
|
||||||
std::shared_ptr<VMissionData> message =
|
std::shared_ptr<VMissionData> message =
|
||||||
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::CHECK_UPGRADE_FILE));
|
std::make_shared<VMissionData>(static_cast<MissionEvent>(InternalStateEvent::CHECK_UPGRADE_FILE));
|
||||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||||
}
|
}
|
||||||
return EXECUTED;
|
return EXECUTED;
|
||||||
|
}
|
||||||
|
bool SdCardHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg)
|
||||||
|
{
|
||||||
|
if (StorageEvent::SD_CARD_INSERT == mSdCardStatus) {
|
||||||
|
return FATHER_HANDLE_MESSAGE;
|
||||||
|
}
|
||||||
|
LogWarning("Sd card is not inserted, ignore reset key media task.\n");
|
||||||
|
return HANDLE_HELPESS;
|
||||||
}
|
}
|
|
@ -31,6 +31,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
bool MediaReportHandle(VStateMachineData *msg);
|
bool MediaReportHandle(VStateMachineData *msg);
|
||||||
bool SdCardEventHandle(VStateMachineData *msg);
|
bool SdCardEventHandle(VStateMachineData *msg);
|
||||||
|
bool ResetKeyMediaTaskHandle(VStateMachineData *msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StorageEvent mSdCardStatus;
|
StorageEvent mSdCardStatus;
|
||||||
|
|
|
@ -10,8 +10,27 @@
|
||||||
|
|
||||||
### 1.2.1. 数据库表
|
### 1.2.1. 数据库表
|
||||||
|
|
||||||
|
**文件保存表**
|
||||||
|
|
||||||
|
| key | 路径 | 时间 | 类型 | 大小 | 状态 |
|
||||||
|
| ---- | ---- | ---- | ---- | ---- | ---- |
|
||||||
|
| 数据库键值 | 文件保存的相对路径 | 录制的时间<br>可能不准确 | 录制的类型:<br>PIR<br>手动<br>手机app<br>定时 | 文件大小 | 枚举:<br>正在拍摄<br>已完成拍摄<br>待上传<br>正在上传<br>上传完成 |
|
||||||
|
|
||||||
|
**如何应对未知的数据表临加**
|
||||||
|
|
||||||
|
解决基于一个已存在的数据库文件,临加数据元素。
|
||||||
|
|
||||||
|
拍摄流程:
|
||||||
|
|
||||||
|
1. 拍摄前先创建数据,获取唯一自增键值;
|
||||||
|
2. 拍摄结束后,更新数据状态为已完成;
|
||||||
|
|
||||||
|
**状态使用TEXT数据类型,如果使用枚举,可能会存在枚举值变化导致的bug。**
|
||||||
|
|
||||||
## 1.3. 文件夹管理
|
## 1.3. 文件夹管理
|
||||||
|
|
||||||
|
**目录树**
|
||||||
|
|
||||||
```
|
```
|
||||||
DCIM/ // 根目录
|
DCIM/ // 根目录
|
||||||
├── picture // 图片目录
|
├── picture // 图片目录
|
||||||
|
@ -25,10 +44,18 @@ DCIM/ // 根目录
|
||||||
└── xxx.MP4
|
└── xxx.MP4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**野数据**
|
||||||
|
|
||||||
|
  插入一些非软件保存文件的sd卡时,忽略这些数据(不做任何处理)。
|
||||||
|
|
||||||
## 1.4. 文件命名规则
|
## 1.4. 文件命名规则
|
||||||
|
|
||||||
**文件类型**
|
**文件类型**
|
||||||
|
|
||||||
1. PIR抓拍;
|
1. PIR抓拍;
|
||||||
2. 定时抓拍;
|
2. 定时抓拍;
|
||||||
3. 手动抓拍;
|
3. 手动抓拍;
|
||||||
|
|
||||||
|
**文件名命名规则**
|
||||||
|
|
||||||
|
基于文件保存表的数据元素:类型+时间+key
|
||||||
|
|
|
@ -21,6 +21,12 @@ typedef struct save_file_info
|
||||||
save_file_info(const std::string &fileName);
|
save_file_info(const std::string &fileName);
|
||||||
const std::string mFileName;
|
const std::string mFileName;
|
||||||
} SaveFileInfo;
|
} SaveFileInfo;
|
||||||
|
typedef struct info_to_be_saved
|
||||||
|
{
|
||||||
|
info_to_be_saved(const unsigned long &serialNumber, const std::string mSavingPath);
|
||||||
|
const unsigned long mSerialNumber;
|
||||||
|
const std::string mSavingPath;
|
||||||
|
} InfoToBeSaved;
|
||||||
bool CreateFilesManagerModule(void);
|
bool CreateFilesManagerModule(void);
|
||||||
bool DestroyFilesManagerModule(void);
|
bool DestroyFilesManagerModule(void);
|
||||||
class IFilesManager
|
class IFilesManager
|
||||||
|
@ -32,5 +38,6 @@ public:
|
||||||
virtual StatusCode Init(void);
|
virtual StatusCode Init(void);
|
||||||
virtual StatusCode UnInit(void);
|
virtual StatusCode UnInit(void);
|
||||||
virtual StatusCode SaveFile(const SaveFileInfo &fileInfo);
|
virtual StatusCode SaveFile(const SaveFileInfo &fileInfo);
|
||||||
|
virtual InfoToBeSaved GetInfoForSavingFiles(const unsigned int &count);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -25,5 +25,6 @@ public:
|
||||||
void Init(void);
|
void Init(void);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
StatusCode DatabaseSaveFile(const SaveFileInfo &fileInfo);
|
StatusCode DatabaseSaveFile(const SaveFileInfo &fileInfo);
|
||||||
|
InfoToBeSaved CreateInfoForSavingFiles(const unsigned int &count);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -29,4 +29,8 @@ StatusCode FilesManagerImpl::UnInit(void)
|
||||||
StatusCode FilesManagerImpl::SaveFile(const SaveFileInfo &fileInfo)
|
StatusCode FilesManagerImpl::SaveFile(const SaveFileInfo &fileInfo)
|
||||||
{
|
{
|
||||||
return FilesDatabase::DatabaseSaveFile(fileInfo);
|
return FilesDatabase::DatabaseSaveFile(fileInfo);
|
||||||
|
}
|
||||||
|
InfoToBeSaved FilesManagerImpl::GetInfoForSavingFiles(const unsigned int &count)
|
||||||
|
{
|
||||||
|
return FilesDatabase::CreateInfoForSavingFiles(count);
|
||||||
}
|
}
|
|
@ -27,5 +27,6 @@ protected:
|
||||||
StatusCode Init(void) override;
|
StatusCode Init(void) override;
|
||||||
StatusCode UnInit(void) override;
|
StatusCode UnInit(void) override;
|
||||||
StatusCode SaveFile(const SaveFileInfo &fileInfo) override;
|
StatusCode SaveFile(const SaveFileInfo &fileInfo) override;
|
||||||
|
InfoToBeSaved GetInfoForSavingFiles(const unsigned int &count) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -20,6 +20,10 @@
|
||||||
save_file_info::save_file_info(const std::string &fileName) : mFileName(fileName)
|
save_file_info::save_file_info(const std::string &fileName) : mFileName(fileName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
info_to_be_saved::info_to_be_saved(const unsigned long &serialNumber, const std::string mSavingPath)
|
||||||
|
: mSerialNumber(serialNumber), mSavingPath(mSavingPath)
|
||||||
|
{
|
||||||
|
}
|
||||||
std::shared_ptr<IFilesManager> &IFilesManager::GetInstance(std::shared_ptr<IFilesManager> *impl)
|
std::shared_ptr<IFilesManager> &IFilesManager::GetInstance(std::shared_ptr<IFilesManager> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<IFilesManager>();
|
static auto instance = std::make_shared<IFilesManager>();
|
||||||
|
@ -36,13 +40,22 @@ std::shared_ptr<IFilesManager> &IFilesManager::GetInstance(std::shared_ptr<IFile
|
||||||
}
|
}
|
||||||
StatusCode IFilesManager::Init(void)
|
StatusCode IFilesManager::Init(void)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
StatusCode IFilesManager::UnInit(void)
|
StatusCode IFilesManager::UnInit(void)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
StatusCode IFilesManager::SaveFile(const SaveFileInfo &fileInfo)
|
StatusCode IFilesManager::SaveFile(const SaveFileInfo &fileInfo)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
InfoToBeSaved IFilesManager::GetInfoForSavingFiles(const unsigned int &count)
|
||||||
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
|
InfoToBeSaved info(0, ".");
|
||||||
|
return info;
|
||||||
}
|
}
|
|
@ -20,9 +20,12 @@
|
||||||
#include "SqliteHandle.h"
|
#include "SqliteHandle.h"
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#define DATABASE_FILE_NAME "/files.db"
|
||||||
void FilesDatabase::Init(void)
|
void FilesDatabase::Init(void)
|
||||||
{
|
{
|
||||||
SqliteHandle::GetInstance()->Init();
|
std::string dbPath = IStorageManager::GetInstance()->GetFilesDatabasePath();
|
||||||
|
LogInfo("Database path:%s\n", (dbPath + DATABASE_FILE_NAME).c_str());
|
||||||
|
SqliteHandle::GetInstance()->Init(dbPath + DATABASE_FILE_NAME);
|
||||||
}
|
}
|
||||||
void FilesDatabase::UnInit(void)
|
void FilesDatabase::UnInit(void)
|
||||||
{
|
{
|
||||||
|
@ -42,4 +45,10 @@ StatusCode FilesDatabase::DatabaseSaveFile(const SaveFileInfo &fileInfo)
|
||||||
return CreateStatusCode(STATUS_CODE_OK);
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
return CreateStatusCode(STATUS_CODE_NOT_OK);
|
||||||
|
}
|
||||||
|
InfoToBeSaved FilesDatabase::CreateInfoForSavingFiles(const unsigned int &count)
|
||||||
|
{
|
||||||
|
const unsigned long key = SqliteHandle::GetInstance()->CreateFiles(count);
|
||||||
|
InfoToBeSaved info(key, ".");
|
||||||
|
return info;
|
||||||
}
|
}
|
|
@ -15,8 +15,24 @@
|
||||||
#include "SqliteHandle.h"
|
#include "SqliteHandle.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdio.h>
|
#include <string>
|
||||||
|
#define FILES_TABLE "files"
|
||||||
|
#define TABLE_KEY "key"
|
||||||
|
#define FILE_PATH "path"
|
||||||
|
#define CREATE_TIME "time"
|
||||||
|
#define FILE_TYPE "type"
|
||||||
|
#define FILE_SIZE "size"
|
||||||
|
#define FILE_STATUS "status"
|
||||||
|
#define FILE_TYPE_BE_RECORDING "recording"
|
||||||
|
#define FILE_TYPE_COMPLETE_RECORD "complete_record"
|
||||||
|
#define FILE_TYPE_SHOULD_BE_UPLOADED "should_be_uploaded"
|
||||||
|
#define FILE_TYPE_UPLOADING "uploading"
|
||||||
|
#define FILE_TYPE_UPLOADED "uploaded"
|
||||||
|
SqliteHandle::SqliteHandle() : mDb(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
std::shared_ptr<SqliteHandle> &SqliteHandle::GetInstance(std::shared_ptr<SqliteHandle> *impl)
|
std::shared_ptr<SqliteHandle> &SqliteHandle::GetInstance(std::shared_ptr<SqliteHandle> *impl)
|
||||||
{
|
{
|
||||||
static auto instance = std::make_shared<SqliteHandle>();
|
static auto instance = std::make_shared<SqliteHandle>();
|
||||||
|
@ -31,17 +47,76 @@ std::shared_ptr<SqliteHandle> &SqliteHandle::GetInstance(std::shared_ptr<SqliteH
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
void SqliteHandle::Init(void)
|
void SqliteHandle::Init(const std::string &dbFileName)
|
||||||
{
|
{
|
||||||
sqlite3 *db;
|
if (nullptr != mDb) {
|
||||||
int rc;
|
LogWarning("SqliteHandle has been init.\n");
|
||||||
rc = sqlite3_open("test.db", &db);
|
|
||||||
if (rc) {
|
|
||||||
fprintf(stderr, "无法打开数据库: %s\n", sqlite3_errmsg(db));
|
|
||||||
sqlite3_close(db);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int rc = SQLITE_UNDEFINE;
|
||||||
|
rc = sqlite3_open(dbFileName.c_str(), &mDb);
|
||||||
|
if (SQLITE_OK != rc) {
|
||||||
|
LogError("open sqlite3 failed: %s\n", sqlite3_errmsg(mDb));
|
||||||
|
sqlite3_close(mDb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DbInit(mDb);
|
||||||
}
|
}
|
||||||
void SqliteHandle::UnInit(void)
|
void SqliteHandle::UnInit(void)
|
||||||
{
|
{
|
||||||
|
if (mDb) {
|
||||||
|
sqlite3_close(mDb);
|
||||||
|
mDb = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void SqliteHandle::DbInit(sqlite3 *db)
|
||||||
|
{
|
||||||
|
if (nullptr == db) {
|
||||||
|
LogError("db is null.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char *errMsg = nullptr;
|
||||||
|
int rc = SQLITE_UNDEFINE;
|
||||||
|
const char *sql =
|
||||||
|
"CREATE TABLE IF NOT EXISTS " FILES_TABLE " (" TABLE_KEY " INTEGER PRIMARY KEY AUTOINCREMENT, " FILE_PATH
|
||||||
|
" TEXT, " CREATE_TIME " INTEGER," FILE_TYPE " TEXT, " FILE_SIZE " INTEGER);";
|
||||||
|
rc = sqlite3_exec(db, sql, nullptr, nullptr, &errMsg);
|
||||||
|
if (SQLITE_OK != rc) {
|
||||||
|
LogError("Sql: %s, errMsg: %s\n", sql, errMsg);
|
||||||
|
sqlite3_free(errMsg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogInfo("Sqlite init success. table = %s\n", FILES_TABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsigned long int SqliteHandle::CreateFiles(const unsigned int &count)
|
||||||
|
{
|
||||||
|
char *err_msg = nullptr;
|
||||||
|
int rc = SQLITE_UNDEFINE;
|
||||||
|
const char *sql = "INSERT INTO " FILES_TABLE " (" FILE_PATH ", " CREATE_TIME ", " FILE_TYPE ", " FILE_SIZE
|
||||||
|
") VALUES (\"\", 0, \"" FILE_TYPE_BE_RECORDING "\", 0);";
|
||||||
|
for (unsigned int i = 0; i < count; ++i) {
|
||||||
|
rc = sqlite3_exec(mDb, sql, nullptr, nullptr, &err_msg);
|
||||||
|
if (SQLITE_OK != rc) {
|
||||||
|
LogError("SQL error: %s\n", err_msg);
|
||||||
|
sqlite3_free(err_msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto last_rowid_lambda = [](void *last_rowid, int argc, char **argv, char **azColName) -> int {
|
||||||
|
if (argc > 0) {
|
||||||
|
LogInfo("last_rowid = %s\n", argv[0]);
|
||||||
|
*(unsigned long int *)last_rowid = strtoul(argv[0], nullptr, 10);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
unsigned long int last_rowid = 0;
|
||||||
|
const char *sql2 = "SELECT last_insert_rowid();";
|
||||||
|
rc = sqlite3_exec(mDb, sql2, last_rowid_lambda, &last_rowid, &err_msg);
|
||||||
|
if (SQLITE_OK != rc) {
|
||||||
|
LogError("SQL error: %s\n", err_msg);
|
||||||
|
sqlite3_free(err_msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return last_rowid - count + 1;
|
||||||
}
|
}
|
|
@ -14,14 +14,25 @@
|
||||||
*/
|
*/
|
||||||
#ifndef SQLITE_HANDLE_H
|
#ifndef SQLITE_HANDLE_H
|
||||||
#define SQLITE_HANDLE_H
|
#define SQLITE_HANDLE_H
|
||||||
|
#include "sqlite3.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
constexpr int SQLITE_UNDEFINE = -1;
|
||||||
class SqliteHandle
|
class SqliteHandle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SqliteHandle() = default;
|
SqliteHandle();
|
||||||
virtual ~SqliteHandle() = default;
|
virtual ~SqliteHandle() = default;
|
||||||
static std::shared_ptr<SqliteHandle> &GetInstance(std::shared_ptr<SqliteHandle> *impl = nullptr);
|
static std::shared_ptr<SqliteHandle> &GetInstance(std::shared_ptr<SqliteHandle> *impl = nullptr);
|
||||||
void Init(void);
|
void Init(const std::string &dbFileName);
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
void DbInit(sqlite3 *db);
|
||||||
|
unsigned long int CreateFiles(const unsigned int &count);
|
||||||
|
bool Add();
|
||||||
|
bool Remove();
|
||||||
|
bool Modified();
|
||||||
|
bool Serach();
|
||||||
|
|
||||||
|
private:
|
||||||
|
sqlite3 *mDb;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -56,6 +56,7 @@ public:
|
||||||
VMediaTask() = default;
|
VMediaTask() = default;
|
||||||
virtual ~VMediaTask() = default;
|
virtual ~VMediaTask() = default;
|
||||||
virtual const MediaTaskType GetTaskType(void);
|
virtual const MediaTaskType GetTaskType(void);
|
||||||
|
virtual const std::string GetTargetNameForSaving(void);
|
||||||
virtual void Response(const std::vector<MediaTaskResponse> &response);
|
virtual void Response(const std::vector<MediaTaskResponse> &response);
|
||||||
virtual bool IsTaskFinished(void);
|
virtual bool IsTaskFinished(void);
|
||||||
virtual const signed int GetIsNight(void);
|
virtual const signed int GetIsNight(void);
|
||||||
|
|
|
@ -29,6 +29,11 @@ const MediaTaskType VMediaTask::GetTaskType(void)
|
||||||
{
|
{
|
||||||
return MediaTaskType::END;
|
return MediaTaskType::END;
|
||||||
}
|
}
|
||||||
|
const std::string VMediaTask::GetTargetNameForSaving(void)
|
||||||
|
{
|
||||||
|
const std::string fileName = "Undefined";
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
void VMediaTask::Response(const std::vector<MediaTaskResponse> &response)
|
void VMediaTask::Response(const std::vector<MediaTaskResponse> &response)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define I_STORAGE_MANAGER_H
|
#define I_STORAGE_MANAGER_H
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
bool CreateStorageManagerModule(void);
|
bool CreateStorageManagerModule(void);
|
||||||
bool DestroyStorageManagerModule(void);
|
bool DestroyStorageManagerModule(void);
|
||||||
enum class StorageEvent
|
enum class StorageEvent
|
||||||
|
@ -53,5 +54,6 @@ public:
|
||||||
virtual StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht);
|
virtual StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht);
|
||||||
virtual const char *PrintStringStorageEvent(const StorageEvent &event);
|
virtual const char *PrintStringStorageEvent(const StorageEvent &event);
|
||||||
virtual StatusCode GetSdCardInfo(SdCardInfo &info);
|
virtual StatusCode GetSdCardInfo(SdCardInfo &info);
|
||||||
|
virtual std::string GetFilesDatabasePath(void);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -43,21 +43,32 @@ StatusCode IStorageManager::Init(void)
|
||||||
}
|
}
|
||||||
StatusCode IStorageManager::UnInit(void)
|
StatusCode IStorageManager::UnInit(void)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
StatusCode IStorageManager::SetMonitor(std::shared_ptr<VStorageMoniter> &monitor)
|
StatusCode IStorageManager::SetMonitor(std::shared_ptr<VStorageMoniter> &monitor)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
StatusCode IStorageManager::SaveFile(const std::string &sourceFile, const std::string &savePaht)
|
StatusCode IStorageManager::SaveFile(const std::string &sourceFile, const std::string &savePaht)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
}
|
}
|
||||||
const char *IStorageManager::PrintStringStorageEvent(const StorageEvent &event)
|
const char *IStorageManager::PrintStringStorageEvent(const StorageEvent &event)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return "STATUS_CODE_VIRTUAL_FUNCTION";
|
return "STATUS_CODE_VIRTUAL_FUNCTION";
|
||||||
}
|
}
|
||||||
StatusCode IStorageManager::GetSdCardInfo(SdCardInfo &info)
|
StatusCode IStorageManager::GetSdCardInfo(SdCardInfo &info)
|
||||||
{
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
std::string IStorageManager::GetFilesDatabasePath(void)
|
||||||
|
{
|
||||||
|
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION\n");
|
||||||
|
std::string path = "undefined";
|
||||||
|
return path;
|
||||||
}
|
}
|
|
@ -41,6 +41,7 @@ bool StorageBase::CheckDirectory(const char *filepath)
|
||||||
}
|
}
|
||||||
if (stat(path, &st) == -1) {
|
if (stat(path, &st) == -1) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
|
LogInfo("mkdir:%s\n", path);
|
||||||
if (mkdir(path, 0755) == -1) {
|
if (mkdir(path, 0755) == -1) {
|
||||||
LogError("mkdir path failed:%s\n", path);
|
LogError("mkdir path failed:%s\n", path);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
|
@ -13,13 +13,14 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "StorageManagerImpl.h"
|
#include "StorageManagerImpl.h"
|
||||||
// #include "ILog.h"
|
#include "ILog.h"
|
||||||
#include "IStorageManager.h"
|
#include "IStorageManager.h"
|
||||||
#include "SdCardHandle.h"
|
#include "SdCardHandle.h"
|
||||||
#include "StatusCode.h"
|
#include "StatusCode.h"
|
||||||
#include "StorageBase.h"
|
#include "StorageBase.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#define SYSTEM_FILE_PATH "/system"
|
||||||
StatusCode StorageManagerImpl::Init(void)
|
StatusCode StorageManagerImpl::Init(void)
|
||||||
{
|
{
|
||||||
SdCardHandle::SdCardInit();
|
SdCardHandle::SdCardInit();
|
||||||
|
@ -43,4 +44,15 @@ StatusCode StorageManagerImpl::SaveFile(const std::string &sourceFile, const std
|
||||||
const char *StorageManagerImpl::PrintStringStorageEvent(const StorageEvent &event)
|
const char *StorageManagerImpl::PrintStringStorageEvent(const StorageEvent &event)
|
||||||
{
|
{
|
||||||
return StorageBase::PrintStringStorageEvent(event);
|
return StorageBase::PrintStringStorageEvent(event);
|
||||||
|
}
|
||||||
|
std::string StorageManagerImpl::GetFilesDatabasePath(void)
|
||||||
|
{
|
||||||
|
std::string path = SD_CARD_MOUNT_PATH SYSTEM_FILE_PATH "/anyfile";
|
||||||
|
bool directoryExist = StorageBase::CheckDirectory(path.c_str());
|
||||||
|
if (false == directoryExist) {
|
||||||
|
LogError("Directory not exist.\n");
|
||||||
|
path = "Unavailable";
|
||||||
|
}
|
||||||
|
path = SD_CARD_MOUNT_PATH SYSTEM_FILE_PATH;
|
||||||
|
return path;
|
||||||
}
|
}
|
|
@ -23,10 +23,13 @@ class StorageManagerImpl : public SdCardHandle, public EmmcHandle
|
||||||
public:
|
public:
|
||||||
StorageManagerImpl() = default;
|
StorageManagerImpl() = default;
|
||||||
virtual ~StorageManagerImpl() = default;
|
virtual ~StorageManagerImpl() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
StatusCode Init(void) override;
|
StatusCode Init(void) override;
|
||||||
StatusCode UnInit(void) override;
|
StatusCode UnInit(void) override;
|
||||||
StatusCode SetMonitor(std::shared_ptr<VStorageMoniter> &monitor) override;
|
StatusCode SetMonitor(std::shared_ptr<VStorageMoniter> &monitor) override;
|
||||||
StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht) override;
|
StatusCode SaveFile(const std::string &sourceFile, const std::string &savePaht) override;
|
||||||
const char *PrintStringStorageEvent(const StorageEvent &event) override;
|
const char *PrintStringStorageEvent(const StorageEvent &event) override;
|
||||||
|
std::string GetFilesDatabasePath(void) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -273,8 +273,8 @@ bool FfmpegMuxStream::add_stream(OutputStream *ost, AVFormatContext *oc, const A
|
||||||
|
|
||||||
c->bit_rate = 400000;
|
c->bit_rate = 400000;
|
||||||
/* Resolution must be a multiple of two. */
|
/* Resolution must be a multiple of two. */
|
||||||
c->width = 352;
|
c->width = 1920;
|
||||||
c->height = 288;
|
c->height = 2160;
|
||||||
/* timebase: This is the fundamental unit of time (in seconds) in terms
|
/* timebase: This is the fundamental unit of time (in seconds) in terms
|
||||||
* of which frame timestamps are represented. For fixed-fps content,
|
* of which frame timestamps are represented. For fixed-fps content,
|
||||||
* timebase should be 1/framerate and timestamp increments should be
|
* timebase should be 1/framerate and timestamp increments should be
|
||||||
|
@ -498,6 +498,7 @@ bool FfmpegMuxStream::InitCodecAudio(enum AVCodecID codecId, AVCodec **codec, AV
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
*codec = (AVCodec *)avcodec_find_decoder(codecId);
|
*codec = (AVCodec *)avcodec_find_decoder(codecId);
|
||||||
|
// *codec = (AVCodec *)avcodec_find_encoder_by_name("libfdk_aac");
|
||||||
if (!(*codec)) {
|
if (!(*codec)) {
|
||||||
LogError("Codec not found\n");
|
LogError("Codec not found\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user