From 16e98073d859df0c2b4267ffa41a703d7fd41aa9 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Fri, 31 May 2024 17:08:29 +0800 Subject: [PATCH] Add:MediaManager/MediaHandlState code. --- CMakeLists.txt | 21 ++++++++ application/MissionManager/README.md | 2 + .../MissionManager/src/DataProcessing.h | 2 + application/MissionManager/src/IdleState.cpp | 37 +++++++++++++ application/MissionManager/src/IdleState.h | 30 +++++++++++ .../MissionManager/src/MediaHandleState.cpp | 47 ++++++++++++++++ .../MissionManager/src/MediaHandleState.h | 37 +++++++++++++ application/MissionManager/src/MediaTask.cpp | 25 +++++++++ application/MissionManager/src/MediaTask.h | 42 +++++++++++++++ .../MissionManager/src/MediaTaskHandle.cpp | 51 ++++++++++++++++++ .../MissionManager/src/MediaTaskHandle.h | 35 ++++++++++++ .../src/MissionManagerMakePtr.cpp | 12 +++++ .../src/MissionManagerMakePtr.h | 2 + .../src/MissionStateMachine.cpp | 12 +++++ .../MissionManager/src/MissionStateMachine.h | 3 ++ .../MissionManager/src/TestMissionState.cpp | 15 ++++++ .../MissionManager/src/TestMissionState.h | 1 + .../MissionManager/src/UpgradeState.cpp | 2 + doc/develop_standard.md | 35 +++++++++++- hal/abstract/IHalCpp.cpp | 8 +++ hal/include/IHalCpp.h | 32 +++++++++++ middleware/AppManager/README.md | 2 +- middleware/MediaManager/README.md | 14 ++++- .../MediaManager/include/IMediaManager.h | 20 ++++--- middleware/MediaManager/src/IMediaManager.cpp | 54 ++++++++++++++++++- middleware/MediaManager/src/MediaHandle.cpp | 54 +++++++++++++++++++ middleware/MediaManager/src/MediaHandle.h | 38 +++++++++++++ .../MediaManager/src/MediaManagerImpl.cpp | 39 ++++++++++++-- .../MediaManager/src/MediaManagerImpl.h | 5 +- .../src_mock/DeviceManager_Mock_Test.cpp | 2 + test/hal/tool/src/CameraHalMock.cpp | 14 +++++ test/hal/tool/src/CameraHalMock.h | 3 ++ test/hal/tool/src/HalTestTool.cpp | 4 ++ .../MediaManager/tool/src/MediaHandleMock.cpp | 15 ++++++ .../MediaManager/tool/src/MediaHandleMock.h | 18 +++++++ 35 files changed, 719 insertions(+), 14 deletions(-) create mode 100644 application/MissionManager/src/IdleState.cpp create mode 100644 application/MissionManager/src/IdleState.h create mode 100644 application/MissionManager/src/MediaHandleState.cpp create mode 100644 application/MissionManager/src/MediaHandleState.h create mode 100644 application/MissionManager/src/MediaTask.cpp create mode 100644 application/MissionManager/src/MediaTask.h create mode 100644 application/MissionManager/src/MediaTaskHandle.cpp create mode 100644 application/MissionManager/src/MediaTaskHandle.h create mode 100644 middleware/MediaManager/src/MediaHandle.cpp create mode 100644 middleware/MediaManager/src/MediaHandle.h create mode 100644 test/middleware/MediaManager/tool/src/MediaHandleMock.cpp create mode 100644 test/middleware/MediaManager/tool/src/MediaHandleMock.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 078ab46b..e0914214 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ execute_process( COMMAND git diff --name-only --diff-filter=ACMRT OUTPUT_VARIABLE MODIFIED_FILES OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} ) set(ALL_MODEFIED_FILES "") string(LENGTH "${MODIFIED_FILES}" GIT_RESULT_STRING_LENGTH) @@ -43,6 +44,26 @@ foreach(FILE ${MODIFIED_FILES_LIST}) set(ALL_MODEFIED_FILES "${ALL_MODEFIED_FILES};${FILE}") endif() endforeach() +# 获取未跟踪的文件 +execute_process( + COMMAND git ls-files --others --exclude-standard + OUTPUT_VARIABLE UNTRACKED_FILES + OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} +) +string(LENGTH "${UNTRACKED_FILES}" GIT_RESULT_STRING_LENGTH) +if(GIT_RESULT_STRING_LENGTH EQUAL 0) +else() + string(REPLACE "\n" ";" UNTRACKED_FILES_LIST ${UNTRACKED_FILES}) +endif() +# 遍历每个文件 +foreach(FILE ${UNTRACKED_FILES_LIST}) + # 检查文件扩展名,只格式化.cpp和.h文件 + get_filename_component(FILE_EXT ${FILE} EXT) + if(FILE_EXT MATCHES "\\.(c|cpp|h)$") + set(ALL_MODEFIED_FILES "${ALL_MODEFIED_FILES};${FILE}") + endif() +endforeach() string(LENGTH "${ALL_MODEFIED_FILES}" MODIFIED_STRING_LENGTH) # find the clang-tidy tools unset(CLANG_TIDY_EXE CACHE) diff --git a/application/MissionManager/README.md b/application/MissionManager/README.md index 965c6f5d..a68c1a95 100644 --- a/application/MissionManager/README.md +++ b/application/MissionManager/README.md @@ -23,9 +23,11 @@ TopState --> PowerOff TopState --> MSDCState TopState --> DeviceAbnormal TopState --> MissionState +MissionState --> 空闲 MissionState --> 存储管理 存储管理 --> EMMC 存储管理 --> SD卡 +MissionState --> 媒体管理 SD卡 --> 插卡 SD卡 --> 拔卡 SD卡 --> 卡异常 diff --git a/application/MissionManager/src/DataProcessing.h b/application/MissionManager/src/DataProcessing.h index 1a6b33be..29c08048 100644 --- a/application/MissionManager/src/DataProcessing.h +++ b/application/MissionManager/src/DataProcessing.h @@ -29,6 +29,8 @@ enum class InternalStateEvent CHECK_UPGRADE_FILE, MEDIA_REPORT_EVENT, KEY_EVENT_HANDLE, + RESET_KEY_MEDIA_TASK, + MEDIA_HANDLE_STATE_TASK_TIME_OUT, END }; typedef struct key_event_data diff --git a/application/MissionManager/src/IdleState.cpp b/application/MissionManager/src/IdleState.cpp new file mode 100644 index 00000000..f0a2d6ee --- /dev/null +++ b/application/MissionManager/src/IdleState.cpp @@ -0,0 +1,37 @@ +/* + * 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 "IdleState.h" +#include "IFilesManager.h" +#include "ILog.h" +#include "IMediaManager.h" +#include "MissionStateMachine.h" +IdleState::IdleState() : State("IdleState") +{ + // mEventHandle[InternalStateEvent::MEDIA_REPORT_EVENT] = std::bind(&IdleState::MediaReportHandle, this, _1); + // mEventHandle[InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED] = + // std::bind(&IdleState::SdCardEventHandle, this, _1); +} +void IdleState::GoInState() +{ + LogInfo(" ========== IdleState::GoInState.\n"); +} +void IdleState::GoOutState() +{ + LogInfo(" ========== IdleState::GoOutState.\n"); +} +bool IdleState::ExecuteStateMsg(VStateMachineData *msg) +{ + return DataProcessing::EventHandle(msg); +} \ No newline at end of file diff --git a/application/MissionManager/src/IdleState.h b/application/MissionManager/src/IdleState.h new file mode 100644 index 00000000..f680ba03 --- /dev/null +++ b/application/MissionManager/src/IdleState.h @@ -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. + */ +#ifndef IDLE_STATE_H +#define IDLE_STATE_H +#include "DataProcessing.h" +#include "IStateMachine.h" +class IdleState : public State, public DataProcessing, public std::enable_shared_from_this +{ +public: + IdleState(); + virtual ~IdleState() = default; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(VStateMachineData *msg) override; + +private: +}; +#endif \ No newline at end of file diff --git a/application/MissionManager/src/MediaHandleState.cpp b/application/MissionManager/src/MediaHandleState.cpp new file mode 100644 index 00000000..f6b29f66 --- /dev/null +++ b/application/MissionManager/src/MediaHandleState.cpp @@ -0,0 +1,47 @@ +/* + * 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 "MediaHandleState.h" +#include "IFilesManager.h" +#include "ILog.h" +#include "IMediaManager.h" +#include "MissionStateMachine.h" +MediaHandleState::MediaHandleState() : State("MediaHandleState") +{ + mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] = + std::bind(&MediaHandleState::ResetKeyMediaTaskHandle, this, _1); +} +void MediaHandleState::GoInState() +{ + LogInfo(" ========== MediaHandleState::GoInState.\n"); + if (!mMediaHandle) { + MediaTaskHandle::Init(); + } +} +void MediaHandleState::GoOutState() +{ + LogInfo(" ========== MediaHandleState::GoOutState.\n"); +} +bool MediaHandleState::ExecuteStateMsg(VStateMachineData *msg) +{ + return DataProcessing::EventHandle(msg); +} +void MediaHandleState::TaskResponse(const std::vector &response) +{ +} +bool MediaHandleState::ResetKeyMediaTaskHandle(VStateMachineData *msg) +{ + MakeSingleTask(InternalStateEvent::RESET_KEY_MEDIA_TASK, shared_from_this()); + return EXECUTED; +} \ No newline at end of file diff --git a/application/MissionManager/src/MediaHandleState.h b/application/MissionManager/src/MediaHandleState.h new file mode 100644 index 00000000..4a1e594c --- /dev/null +++ b/application/MissionManager/src/MediaHandleState.h @@ -0,0 +1,37 @@ +/* + * 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 MEDIA_HANDLE_STATE_H +#define MEDIA_HANDLE_STATE_H +#include "DataProcessing.h" +#include "IStateMachine.h" +#include "MediaTaskHandle.h" +class MediaHandleState : public State, + public DataProcessing, + public MediaTaskHandle, + public VMediaTaskIniator, + public std::enable_shared_from_this +{ +public: + MediaHandleState(); + virtual ~MediaHandleState() = default; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(VStateMachineData *msg) override; + +private: + void TaskResponse(const std::vector &response) override; + bool ResetKeyMediaTaskHandle(VStateMachineData *msg); +}; +#endif \ No newline at end of file diff --git a/application/MissionManager/src/MediaTask.cpp b/application/MissionManager/src/MediaTask.cpp new file mode 100644 index 00000000..20d0c6c2 --- /dev/null +++ b/application/MissionManager/src/MediaTask.cpp @@ -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. + */ +#include "MediaTask.h" +MediaTask::MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent, + const std::weak_ptr &iniator) + : mType(type), mBindEvent(bindEvent), mIniator(iniator) +{ + mResponseData.reset(); +} +unsigned int MediaTask::GetTaskTimeOutMs(void) +{ + return MEDIA_TASK_TIMEOUT_MS; +} \ No newline at end of file diff --git a/application/MissionManager/src/MediaTask.h b/application/MissionManager/src/MediaTask.h new file mode 100644 index 00000000..5eb77ae7 --- /dev/null +++ b/application/MissionManager/src/MediaTask.h @@ -0,0 +1,42 @@ +/* + * 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 MEDIA_TASK_H +#define MEDIA_TASK_H +#include "DataProcessing.h" +#include "IMediaManager.h" +constexpr unsigned int MEDIA_TASK_TIMEOUT_MS = 1000 * 60; +class VMediaTaskIniator +{ +public: + VMediaTaskIniator() = default; + virtual ~VMediaTaskIniator() = default; + virtual void TaskResponse(const std::vector &response) = 0; +}; +class MediaTask : public VMediaTask +{ +public: + MediaTask(const MediaTaskType &type, const InternalStateEvent &bindEvent, + const std::weak_ptr &iniator); + virtual ~MediaTask() = default; + virtual unsigned int GetTaskTimeOutMs(void); + +private: + const MediaTaskType mType; + const InternalStateEvent mBindEvent; + const std::weak_ptr mIniator; + bool mFinished = false; + std::shared_ptr mResponseData; +}; +#endif \ No newline at end of file diff --git a/application/MissionManager/src/MediaTaskHandle.cpp b/application/MissionManager/src/MediaTaskHandle.cpp new file mode 100644 index 00000000..37661004 --- /dev/null +++ b/application/MissionManager/src/MediaTaskHandle.cpp @@ -0,0 +1,51 @@ +/* + * 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 "MediaTaskHandle.h" +#include "ILog.h" +#include "MissionStateMachine.h" +MediaTaskHandle::MediaTaskHandle() +{ + mMediaHandle.reset(); + // mMediaHandle = std::make_shared(); +} +void MediaTaskHandle::Init(void) +{ + IMediaManager::GetInstance()->GetMediaChannel(MediaChannel::MEDIA_1, mMediaHandle); +} +void MediaTaskHandle::UnInit(void) +{ + mMediaHandle->ClearTask(); + mMediaHandle.reset(); +} +void MediaTaskHandle::MakeSingleTask(const InternalStateEvent &bindEvent, + const std::shared_ptr &iniator) +{ + std::shared_ptr task = std::make_shared(MediaTaskType::END, bindEvent, iniator); + if (!mMediaHandle) { + LogError("MediaHandle is null"); + return; + } + auto code = mMediaHandle->ExecuteTask(task); + if (IsCodeOK(code)) { + mRuningTask = task; + long long timeOut = std::dynamic_pointer_cast(task)->GetTaskTimeOutMs(); + std::shared_ptr message = std::make_shared( + static_cast(InternalStateEvent::MEDIA_HANDLE_STATE_TASK_TIME_OUT)); + MissionStateMachine::GetInstance()->MessageExecutedLater(message, timeOut); + } + // else if () { + // mMediaHandle->StopTask(); + // } +} \ No newline at end of file diff --git a/application/MissionManager/src/MediaTaskHandle.h b/application/MissionManager/src/MediaTaskHandle.h new file mode 100644 index 00000000..40170499 --- /dev/null +++ b/application/MissionManager/src/MediaTaskHandle.h @@ -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. + */ +#ifndef MEDIA_TASK_HANDLE_H +#define MEDIA_TASK_HANDLE_H +#include "DataProcessing.h" +#include "IMediaManager.h" +#include "MediaTask.h" +class MediaTaskHandle +{ +public: + MediaTaskHandle(); + virtual ~MediaTaskHandle() = default; + void Init(void); + void UnInit(void); + void MakeSingleTask(const InternalStateEvent &bindEvent, const std::shared_ptr &iniator); + +protected: + std::shared_ptr mMediaHandle; + +private: + std::shared_ptr mRuningTask; +}; +#endif \ No newline at end of file diff --git a/application/MissionManager/src/MissionManagerMakePtr.cpp b/application/MissionManager/src/MissionManagerMakePtr.cpp index 19273364..f478ecd5 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.cpp +++ b/application/MissionManager/src/MissionManagerMakePtr.cpp @@ -14,6 +14,8 @@ */ #include "MissionManagerMakePtr.h" #include "ILog.h" +#include "IdleState.h" +#include "MediaHandleState.h" #include "MissionManager.h" #include "OnMissionState.h" #include "PirTriggeredMissionState.h" @@ -103,4 +105,14 @@ std::shared_ptr MissionManagerMakePtr::CreateUpgradeState(void) { std::shared_ptr state = std::make_shared(); return state; +} +std::shared_ptr MissionManagerMakePtr::CreateMediaHandleState(void) +{ + std::shared_ptr state = std::make_shared(); + return state; +} +std::shared_ptr MissionManagerMakePtr::CreateIdleState(void) +{ + std::shared_ptr state = std::make_shared(); + return state; } \ No newline at end of file diff --git a/application/MissionManager/src/MissionManagerMakePtr.h b/application/MissionManager/src/MissionManagerMakePtr.h index cb6b6460..6bc2ded6 100644 --- a/application/MissionManager/src/MissionManagerMakePtr.h +++ b/application/MissionManager/src/MissionManagerMakePtr.h @@ -31,5 +31,7 @@ public: virtual std::shared_ptr CreateStorageHandleState(void); virtual std::shared_ptr CreateSdCardHandleState(void); virtual std::shared_ptr CreateUpgradeState(void); + virtual std::shared_ptr CreateMediaHandleState(void); + virtual std::shared_ptr CreateIdleState(void); }; #endif \ No newline at end of file diff --git a/application/MissionManager/src/MissionStateMachine.cpp b/application/MissionManager/src/MissionStateMachine.cpp index 670d504c..d62fc283 100644 --- a/application/MissionManager/src/MissionStateMachine.cpp +++ b/application/MissionManager/src/MissionStateMachine.cpp @@ -60,6 +60,13 @@ StatusCode MissionStateMachine::SendStateMessage(const std::shared_ptrSendMessage(static_cast(message->mEvent), msg); return CreateStatusCode(STATUS_CODE_OK); } +StatusCode MissionStateMachine::MessageExecutedLater(const std::shared_ptr &message, + long long &delayTimeMs) +{ + std::shared_ptr msg = std::make_shared(message); + mStateMachine->MessageExecutedLater(static_cast(message->mEvent), msg, delayTimeMs); + return CreateStatusCode(STATUS_CODE_OK); +} void MissionStateMachine::DelayMessage(VStateMachineData *msg) { mStateMachine->DelayMessage(msg); @@ -92,6 +99,8 @@ void MissionStateMachine::RunStateMachine(const IpcMission &mission) mStateTree[SystemState::STORAGE_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateStorageHandleState(); mStateTree[SystemState::SD_CARD_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateSdCardHandleState(); mStateTree[SystemState::UPGRADE_STATE] = MissionManagerMakePtr::GetInstance()->CreateUpgradeState(); + mStateTree[SystemState::MEDIA_HANDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateMediaHandleState(); + mStateTree[SystemState::IDLE_STATE] = MissionManagerMakePtr::GetInstance()->CreateIdleState(); mStateMachine->StatePlus(mStateTree[SystemState::TOP_STATE].get(), nullptr); mStateMachine->StatePlus(mStateTree[SystemState::MISSION_STATE].get(), mStateTree[SystemState::TOP_STATE].get()); mStateMachine->StatePlus(mStateTree[SystemState::STORAGE_HANDLE_STATE].get(), @@ -100,6 +109,9 @@ void MissionStateMachine::RunStateMachine(const IpcMission &mission) mStateTree[SystemState::STORAGE_HANDLE_STATE].get()); mStateMachine->StatePlus(mStateTree[SystemState::UPGRADE_STATE].get(), mStateTree[SystemState::MISSION_STATE].get()); + mStateMachine->StatePlus(mStateTree[SystemState::MEDIA_HANDLE_STATE].get(), + mStateTree[SystemState::MISSION_STATE].get()); + mStateMachine->StatePlus(mStateTree[SystemState::IDLE_STATE].get(), mStateTree[SystemState::MISSION_STATE].get()); mStateMachine->SetCurrentState(mStateTree[SystemState::TOP_STATE].get()); mStateMachine->StartStateMachine(); /** diff --git a/application/MissionManager/src/MissionStateMachine.h b/application/MissionManager/src/MissionStateMachine.h index ea2c79ea..dc039bd1 100644 --- a/application/MissionManager/src/MissionStateMachine.h +++ b/application/MissionManager/src/MissionStateMachine.h @@ -29,6 +29,8 @@ enum class SystemState STORAGE_HANDLE_STATE, SD_CARD_HANDLE_STATE, UPGRADE_STATE, + MEDIA_HANDLE_STATE, + IDLE_STATE, END }; class MissionStateMachine @@ -40,6 +42,7 @@ public: void Init(void); void UnInit(void); StatusCode SendStateMessage(const std::shared_ptr &message); + StatusCode MessageExecutedLater(const std::shared_ptr &message, long long &delayTimeMs); void DelayMessage(VStateMachineData *msg); void SwitchState(const SystemState &state); diff --git a/application/MissionManager/src/TestMissionState.cpp b/application/MissionManager/src/TestMissionState.cpp index 0de49f3a..2dd95a99 100644 --- a/application/MissionManager/src/TestMissionState.cpp +++ b/application/MissionManager/src/TestMissionState.cpp @@ -21,6 +21,8 @@ TestMissionState::TestMissionState() : MissionState("TestMissionState") { mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] = std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1); + mEventHandle[InternalStateEvent::RESET_KEY_MEDIA_TASK] = + std::bind(&TestMissionState::ResetKeyMediaTaskHandle, this, _1); mKeyClickHandle["reset"] = std::bind(&TestMissionState::ClickResetKey, this, _1); } void TestMissionState::GoInState() @@ -48,8 +50,21 @@ bool TestMissionState::SdCardEventReportSendToApp(VStateMachineData *msg) IAppManager::GetInstance()->SetSdCardStatus(status); return EXECUTED; } +bool TestMissionState::ResetKeyMediaTaskHandle(VStateMachineData *msg) +{ + MissionStateMachine::GetInstance()->DelayMessage(msg); + MissionStateMachine::GetInstance()->SwitchState(SystemState::MEDIA_HANDLE_STATE); + return EXECUTED; +} bool TestMissionState::ClickResetKey(const KeyEventData &data) { + LogInfo("reset key click:make a media task.\n"); + // std::shared_ptr message = std::make_shared>( + // static_cast(InternalStateEvent::MEDIA_REPORT_EVENT), event); + // MissionStateMachine::GetInstance()->SendStateMessage(message); + std::shared_ptr message = + std::make_shared(static_cast(InternalStateEvent::RESET_KEY_MEDIA_TASK)); + MissionStateMachine::GetInstance()->SendStateMessage(message); return EXECUTED; } SdCardStatus TestMissionState::SdCardStatusConvert(const StorageEvent &event) diff --git a/application/MissionManager/src/TestMissionState.h b/application/MissionManager/src/TestMissionState.h index 1b472ffb..52aa089e 100644 --- a/application/MissionManager/src/TestMissionState.h +++ b/application/MissionManager/src/TestMissionState.h @@ -28,6 +28,7 @@ public: private: bool SdCardEventReportSendToApp(VStateMachineData *msg); + bool ResetKeyMediaTaskHandle(VStateMachineData *msg); bool ClickResetKey(const KeyEventData &data); private: diff --git a/application/MissionManager/src/UpgradeState.cpp b/application/MissionManager/src/UpgradeState.cpp index c3659dc8..e9c70044 100644 --- a/application/MissionManager/src/UpgradeState.cpp +++ b/application/MissionManager/src/UpgradeState.cpp @@ -35,6 +35,8 @@ bool UpgradeState::ExecuteStateMsg(VStateMachineData *msg) } bool UpgradeState::CheckUpgradeFileHandle(VStateMachineData *msg) { + // TODO: need to improve:It cannot be blocked. IHuntingUpgrade::GetInstance()->CheckUpgradeFile(); + MissionStateMachine::GetInstance()->SwitchState(SystemState::IDLE_STATE); return EXECUTED; } \ No newline at end of file diff --git a/doc/develop_standard.md b/doc/develop_standard.md index e820b200..c218327d 100644 --- a/doc/develop_standard.md +++ b/doc/develop_standard.md @@ -50,7 +50,8 @@ void McuManagerImpl::OtherSideSendIpcMission(const unsigned int &serialNumber, c * 注释必须使用英文,且使用翻译器翻译;   避免编码问题导致的乱码,且需要保证阅读困难时可使用翻译器翻译成可读的中文; -**注:** 注释翻译工具使用[百度翻译](https://fanyi.baidu.com/); + +**注:** 注释翻译工具使用[百度翻译](https://fanyi.baidu.com/);翻译的注释在使用doxygen工具生成接口文档时,在网页上方便翻译成中文。 ### 1.1.3. C++继承 @@ -76,3 +77,35 @@ typedef struct app_get_product_info ### 1.1.5. 文件命名 * 文件名必须使用驼峰命名法,且首字母大写; + +### 1.1.6. 代码排版 + +* 使用统一标准的代码排版风格,保持多人开发时代码的整洁,避免因为排版(特别是编辑工具的自动排版功能)导致每次提交时都产生大量的排版修改,影响后续代码异常排查; + +  请使用仓库跟目录下.clang-format配置文件进行排版,如果使用vscode编辑器开发代码,可直接使用快捷键ctrl+alt+f进行排版;也可以使用构建脚本对代码进行排版。 + +**对发生修改的代码进行格式化:** + +```code +$ make cmake // 在仓库根目录执行,对发生修改的文件创建格式化命令 +$ cd cmake-shell/ +$ make improve_modified_code // 文件格式化命令,统一排版,此命名只对发生修改的文件进行格式化 +``` + +**对全部文件进行格式化:** + +```code +详见配置文件://build/global_config.cmake +把 COMPILE_IMPROVE_SUPPORT 设置为 true 时,将会在每次编译代码时进行格式化。 +if(${LINUX_TEST} MATCHES "true") + set(CLANG_TIDY_SUPPORT "true") + set(CLANG_FORMAT_SUPPORT "true") + set(COMPILE_IMPROVE_SUPPORT "false") # 开启后每次编译可能会很慢 + set(LLVM_PATH "$ENV{HOME}/llvm-project") +endif() +``` + +### 1.1.7. 函数 + +* 单个函数代码行控制在50行内,阅读时无需上下滚动去理解代码逻辑;极少数初始化数据的无逻辑推理的代码除外; +* 函数参数不能超过10个; diff --git a/hal/abstract/IHalCpp.cpp b/hal/abstract/IHalCpp.cpp index 057dc649..134200d5 100644 --- a/hal/abstract/IHalCpp.cpp +++ b/hal/abstract/IHalCpp.cpp @@ -54,10 +54,18 @@ void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event) { LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n"); } +camera_task_param::camera_task_param(const CameraTaskType &cameraTask) : mCameraTask(cameraTask) +{ +} void VCameraHal::SetCameraMonitor(std::shared_ptr &monitor) { LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n"); } +StatusCode VCameraHal::StartSingleTask(const CameraTaskParam ¶m) +{ + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} void VSdCardHalMonitor::ReportEvent(const SdCardHalStatus &status) { LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n"); diff --git a/hal/include/IHalCpp.h b/hal/include/IHalCpp.h index ffd3ad4e..79349dd2 100644 --- a/hal/include/IHalCpp.h +++ b/hal/include/IHalCpp.h @@ -40,6 +40,13 @@ enum class SdCardHalStatus ERROR, END }; +enum class CameraTaskType +{ + PICTURE = 0, + VIDEO, + PICTURE_AND_VIDEO, + END +}; typedef struct camera_report_event { camera_report_event(const std::string &fileName, const CameraType &cameraType); @@ -86,12 +93,37 @@ public: virtual ~VCameraHalMonitor() = default; virtual void ReportEvent(const CameraReportEvent &event); }; +class VCameraTaskContext +{ +public: + VCameraTaskContext() = default; + virtual ~VCameraTaskContext() = default; +}; +template +class CameraTaskContext : public VCameraTaskContext +{ +public: + CameraTaskContext(T &value) : mData(value) + { + } + virtual ~CameraTaskContext() = default; + +public: + T mData; +}; +typedef struct camera_task_param +{ + camera_task_param(const CameraTaskType &cameraTask); + const CameraTaskType mCameraTask; + std::shared_ptr mCtx; +} CameraTaskParam; class VCameraHal { public: VCameraHal() = default; virtual ~VCameraHal() = default; virtual void SetCameraMonitor(std::shared_ptr &monitor); + virtual StatusCode StartSingleTask(const CameraTaskParam ¶m); }; class VSdCardHalMonitor { diff --git a/middleware/AppManager/README.md b/middleware/AppManager/README.md index ffcc05c2..e67f2449 100644 --- a/middleware/AppManager/README.md +++ b/middleware/AppManager/README.md @@ -191,7 +191,7 @@ ```code { - "result": 0, + "result": 0, // 0代表成功,-1代表失败 "info": [ { diff --git a/middleware/MediaManager/README.md b/middleware/MediaManager/README.md index 8bc1da5d..879c61bc 100644 --- a/middleware/MediaManager/README.md +++ b/middleware/MediaManager/README.md @@ -8,4 +8,16 @@ ## 1.2. 文件管理 -   对抓拍的图片/视频文件的管理。 \ No newline at end of file +   对抓拍的图片/ + +```mermaid +classDiagram +TopState "SetMediaMonitor" ..> "ReportEvent" IMediaManager:依赖 +IMediaManager <|.. MediaManager:实例 +IMediaManager o-- VMediaHandle:集合 +IMediaManager o-- VMediaTask:集合 +VMediaHandle <|.. MediaHandle:实例 +MediaHandle *-- VCameraHal:组成 +MediaManager ..> IHal:依赖 +IHal o-- VCameraHal:集合 +``` diff --git a/middleware/MediaManager/include/IMediaManager.h b/middleware/MediaManager/include/IMediaManager.h index cc7e9b9d..8f189f49 100644 --- a/middleware/MediaManager/include/IMediaManager.h +++ b/middleware/MediaManager/include/IMediaManager.h @@ -21,7 +21,7 @@ bool CreateMediaManagerModule(void); bool DestroyMediaManagerModule(void); enum class MediaChannel { - MEDIA_1 = 1, + MEDIA_1 = 0, MEDIA_2, END }; @@ -39,12 +39,11 @@ typedef struct media_report_event const std::string mFileName; const MediaChannel mMediaChannedl; } MediaReportEvent; -class MediaTaskResponse +typedef struct media_task_response { -public: - MediaTaskResponse() = default; - ~MediaTaskResponse() = default; -}; + media_task_response(const std::string &fileName); + const std::string mFileName; +} MediaTaskResponse; class VMediaTask { public: @@ -68,6 +67,14 @@ class VMediaHandle public: VMediaHandle() = default; virtual ~VMediaHandle() = default; + virtual StatusCode ExecuteTask(std::shared_ptr &task); + virtual StatusCode StopTask(void); + virtual StatusCode ClearTask(void); + virtual StatusCode SetSpontaneousTaskMonitor(std::shared_ptr &task); + // virtual StatusCode BeReadyForLive(void); + // virtual StatusCode SetMediaMonitor(std::shared_ptr &monitor); + // virtual StatusCode StartMedia(void); + // virtual StatusCode StopMedia(void); }; class IMediaManager { @@ -78,5 +85,6 @@ public: virtual StatusCode Init(void); virtual StatusCode UnInit(void); virtual StatusCode SetMediaMonitor(std::shared_ptr &monitor); + virtual StatusCode GetMediaChannel(const MediaChannel &channel, std::shared_ptr &handle); }; #endif \ No newline at end of file diff --git a/middleware/MediaManager/src/IMediaManager.cpp b/middleware/MediaManager/src/IMediaManager.cpp index 564fbccd..9ee046e7 100644 --- a/middleware/MediaManager/src/IMediaManager.cpp +++ b/middleware/MediaManager/src/IMediaManager.cpp @@ -18,6 +18,9 @@ media_report_event::media_report_event(const std::string &fileName, const MediaC : mFileName(fileName), mMediaChannedl(mediaChannedl) { } +media_task_response::media_task_response(const std::string &fileName) : mFileName(fileName) +{ +} const MediaTaskType VMediaTask::GetTaskType(void) { return MediaTaskType::END; @@ -39,14 +42,55 @@ const unsigned int VMediaTask::GetIsMultShot(void) } StatusCode VMediaMonitor::ReportEvent(const MediaReportEvent &event) { + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } +StatusCode VMediaHandle::ExecuteTask(std::shared_ptr &task) +{ + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode VMediaHandle::StopTask(void) +{ + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode VMediaHandle::ClearTask(void) +{ + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode VMediaHandle::SetSpontaneousTaskMonitor(std::shared_ptr &task) +{ + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +// StatusCode VMediaHandle::BeReadyForLive(void) +// { +// LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode VMediaHandle::SetMediaMonitor(std::shared_ptr &monitor) +// { +// LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode VMediaHandle::StartMedia(void) +// { +// LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } +// StatusCode VMediaHandle::StopMedia(void) +// { +// LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); +// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +// } std::shared_ptr &IMediaManager::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); if (impl) { if (instance.use_count() == 1) { - LogInfo("Instance changed succeed.\n"); + LogWarning("Instance changed succeed.\n"); instance = *impl; } else { @@ -57,13 +101,21 @@ std::shared_ptr &IMediaManager::GetInstance(std::shared_ptr &monitor) { + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} +StatusCode IMediaManager::GetMediaChannel(const MediaChannel &channel, std::shared_ptr &handle) +{ + LogWarning("STATUS_CODE_VIRTUAL_FUNCTION"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaHandle.cpp b/middleware/MediaManager/src/MediaHandle.cpp new file mode 100644 index 00000000..ca1f5fcc --- /dev/null +++ b/middleware/MediaManager/src/MediaHandle.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 "MediaHandle.h" +#include "ILog.h" +MediaHandle::MediaHandle(const MediaChannel &mediaChannel, const std::shared_ptr &cameraHal) + : mMediaChannel(mediaChannel), mCameraHal(cameraHal) +{ +} +StatusCode MediaHandle::ExecuteTask(std::shared_ptr &task) +{ + std::lock_guard locker(mMutex); + LogInfo("CameraHandle::ExecuteTask.\n"); + auto runingTask = mCurrentTask.lock(); + if (!mCurrentTask.expired()) { + if (!runingTask->IsTaskFinished()) { + LogError("Camera is runing task, can't execute more task.\n"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + } + CameraTaskType taskType = TaskTypeConvert(task->GetTaskType()); + CameraTaskParam data(taskType); + auto code = mCameraHal->StartSingleTask(data); + if (IsCodeOK(code)) { + mCurrentTask = task; + } + else { + LogError("Execute task failed.\n"); + } + return code; +} +StatusCode MediaHandle::StopTask(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +StatusCode MediaHandle::ClearTask(void) +{ + return CreateStatusCode(STATUS_CODE_OK); +} +CameraTaskType MediaHandle::TaskTypeConvert(const MediaTaskType &type) +{ + return CameraTaskType::END; +} \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaHandle.h b/middleware/MediaManager/src/MediaHandle.h new file mode 100644 index 00000000..809785b8 --- /dev/null +++ b/middleware/MediaManager/src/MediaHandle.h @@ -0,0 +1,38 @@ +/* + * 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 MEDI_AHANDLE_H +#define MEDI_AHANDLE_H +#include "IHalCpp.h" +#include "IMediaManager.h" +#include +class MediaHandle : public VMediaHandle, public std::enable_shared_from_this +{ +public: + MediaHandle(const MediaChannel &mediaChannel, const std::shared_ptr &cameraHal); + virtual ~MediaHandle() = default; + StatusCode ExecuteTask(std::shared_ptr &task) override; + StatusCode StopTask(void) override; + StatusCode ClearTask(void) override; + +private: + CameraTaskType TaskTypeConvert(const MediaTaskType &type); + +private: + std::mutex mMutex; + const MediaChannel &mMediaChannel; + std::shared_ptr mCameraHal; + std::weak_ptr mCurrentTask; +}; +#endif \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaManagerImpl.cpp b/middleware/MediaManager/src/MediaManagerImpl.cpp index ed7f4dc3..a3356e8d 100644 --- a/middleware/MediaManager/src/MediaManagerImpl.cpp +++ b/middleware/MediaManager/src/MediaManagerImpl.cpp @@ -14,19 +14,31 @@ */ #include "MediaManagerImpl.h" #include "ILog.h" +#include "MediaHandle.h" StatusCode MediaManagerImpl::Init(void) { IHalCpp::GetInstance()->GetCameraHal(mAllCameras); + InitMediaHandles(mAllCameras); return CreateStatusCode(STATUS_CODE_OK); } StatusCode MediaManagerImpl::UnInit(void) { return CreateStatusCode(STATUS_CODE_OK); } +StatusCode MediaManagerImpl::GetMediaChannel(const MediaChannel &channel, std::shared_ptr &handle) +{ + auto it = mAllMediaChannels.find(channel); + if (it == mAllMediaChannels.end()) { + LogError("GetMediaChannel failed.\n"); + return CreateStatusCode(STATUS_CODE_NOT_OK); + } + handle = it->second; + return CreateStatusCode(STATUS_CODE_OK); +} StatusCode MediaManagerImpl::SetMediaMonitor(std::shared_ptr &monitor) { mMediaMonitor = monitor; - SetCamerasMonitor(); + SetCamerasMonitor(mAllCameras); return CreateStatusCode(STATUS_CODE_OK); } void MediaManagerImpl::ReportEvent(const CameraReportEvent &event) @@ -40,11 +52,32 @@ void MediaManagerImpl::ReportEvent(const CameraReportEvent &event) } monitor->ReportEvent(reprot); } -void MediaManagerImpl::SetCamerasMonitor(void) +void MediaManagerImpl::SetCamerasMonitor(std::map> &allCameras) { + if (allCameras.empty()) { + LogWarning("No camera found.\n"); + return; + } std::shared_ptr moniter = shared_from_this(); - for (const auto &camera : mAllCameras) { + for (const auto &camera : allCameras) { LogInfo("SetCameraMonitor.\n"); camera.second->SetCameraMonitor(moniter); } +} +void MediaManagerImpl::InitMediaHandles(std::map> &allCameras) +{ + if (allCameras.empty()) { + LogWarning("No camera found.\n"); + return; + } + for (int i = 0; i < static_cast(CameraType::END); i++) { + auto camera = allCameras.find(static_cast(i)); + if (camera == allCameras.end()) { + continue; + } + MediaChannel channel = static_cast(i); + std::shared_ptr media = std::make_shared(channel, camera->second); + mAllMediaChannels[channel] = media; + LogInfo("InitMediaHandles. channel = %d \n", static_cast(i)); + } } \ No newline at end of file diff --git a/middleware/MediaManager/src/MediaManagerImpl.h b/middleware/MediaManager/src/MediaManagerImpl.h index a349d355..20fe1b75 100644 --- a/middleware/MediaManager/src/MediaManagerImpl.h +++ b/middleware/MediaManager/src/MediaManagerImpl.h @@ -26,14 +26,17 @@ public: virtual ~MediaManagerImpl() = default; StatusCode Init(void) override; StatusCode UnInit(void) override; + StatusCode GetMediaChannel(const MediaChannel &channel, std::shared_ptr &handle) override; StatusCode SetMediaMonitor(std::shared_ptr &monitor) override; void ReportEvent(const CameraReportEvent &event) override; private: - void SetCamerasMonitor(void); + void SetCamerasMonitor(std::map> &allCameras); + void InitMediaHandles(std::map> &allCameras); private: std::map> mAllCameras; + std::map> mAllMediaChannels; std::weak_ptr mMediaMonitor; }; #endif \ No newline at end of file diff --git a/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp b/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp index b7efebc4..e38c8437 100644 --- a/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp +++ b/test/application/HuntingCamera/src_mock/DeviceManager_Mock_Test.cpp @@ -57,6 +57,8 @@ TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_KeyControl2) */ TEST_F(HuntingCameraTest, HS_INTEGRATION_HunttingCamera_EXAMPLE_KeyControlClick) { + SetAllCamerasResult(mAllCamerasMock); + MockOtherSideIpcMissionReply(IpcMission::TEST); MainThread::GetInstance()->Init(); TestManager::ResetTimeOut(1000 * 3); HalTestTool::MockKeyClick("reset", 200); // Simulate pressing a button. diff --git a/test/hal/tool/src/CameraHalMock.cpp b/test/hal/tool/src/CameraHalMock.cpp index 7cdf2b20..2531b059 100644 --- a/test/hal/tool/src/CameraHalMock.cpp +++ b/test/hal/tool/src/CameraHalMock.cpp @@ -31,6 +31,20 @@ void CameraHalTest::SetCameraMonitorTrace(std::shared_ptr &mo { LogWarning("SetCameraMonitorTrace.\n"); } +StatusCode CameraHalTest::StartSingleTask(const CameraTaskParam ¶m) +{ + LogInfo("CameraHalTest::StartSingleTask\n"); + StatusCode code = StartSingleTaskTrace(param); + // if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) { + // return HalCpp::GetAllKeys(allKeys); + // } + return code; +} +StatusCode CameraHalTest::StartSingleTaskTrace(const CameraTaskParam ¶m) +{ + LogInfo("CameraHalTest::StartSingleTaskTrace\n"); + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} CameraHalMock::CameraHalMock(const CameraType &cameraType) : CameraHalTest(cameraType) { } diff --git a/test/hal/tool/src/CameraHalMock.h b/test/hal/tool/src/CameraHalMock.h index 10b0de63..c8144ba2 100644 --- a/test/hal/tool/src/CameraHalMock.h +++ b/test/hal/tool/src/CameraHalMock.h @@ -22,9 +22,11 @@ public: CameraHalTest(const CameraType &cameraType); virtual ~CameraHalTest() = default; void SetCameraMonitor(std::shared_ptr &monitor) override; + StatusCode StartSingleTask(const CameraTaskParam ¶m) override; private: virtual void SetCameraMonitorTrace(std::shared_ptr &monitor); + virtual StatusCode StartSingleTaskTrace(const CameraTaskParam ¶m); protected: const CameraType mCameraType; @@ -38,5 +40,6 @@ public: virtual ~CameraHalMock() = default; void MockReportCameraEvent(const CameraReportEvent &event); MOCK_METHOD1(SetCameraMonitorTrace, void(std::shared_ptr &)); + MOCK_METHOD1(StartSingleTaskTrace, StatusCode(const CameraTaskParam &)); }; #endif \ No newline at end of file diff --git a/test/hal/tool/src/HalTestTool.cpp b/test/hal/tool/src/HalTestTool.cpp index dd6b3203..c1d9b6d9 100644 --- a/test/hal/tool/src/HalTestTool.cpp +++ b/test/hal/tool/src/HalTestTool.cpp @@ -327,7 +327,11 @@ void HalTestTool::InitCamerasMock(std::shared_ptr &vMock) return; } constexpr int USER_SHOULD_SET_CAMERA_MONITER = 1; + // constexpr int SINGLE_TASK_DEFAULT_TIMES = 0; EXPECT_CALL(*mock.get(), SetCameraMonitorTrace(_)).Times(USER_SHOULD_SET_CAMERA_MONITER); + EXPECT_CALL(*mock.get(), StartSingleTaskTrace(_)) + .Times(AnyNumber()) + .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_OK)))); } void HalTestTool::MockSdCardRemove(std::shared_ptr &mock) { diff --git a/test/middleware/MediaManager/tool/src/MediaHandleMock.cpp b/test/middleware/MediaManager/tool/src/MediaHandleMock.cpp new file mode 100644 index 00000000..fb9cbc08 --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaHandleMock.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 "MediaHandleMock.h" \ No newline at end of file diff --git a/test/middleware/MediaManager/tool/src/MediaHandleMock.h b/test/middleware/MediaManager/tool/src/MediaHandleMock.h new file mode 100644 index 00000000..b8c565d5 --- /dev/null +++ b/test/middleware/MediaManager/tool/src/MediaHandleMock.h @@ -0,0 +1,18 @@ +/* + * 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 MEDIA_HANDLE_MOCK_H +#define MEDIA_HANDLE_MOCK_H +#include "MediaHandle.h" +#endif \ No newline at end of file