Improve:AppManager tcp server.
This commit is contained in:
parent
b299854b90
commit
b305614fda
|
@ -24,6 +24,7 @@ enum class InternalStateEvent
|
|||
{
|
||||
STORAGE_HANDLE_STATE_INIT = static_cast<int>(MissionEvent::END),
|
||||
SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED,
|
||||
ANY_STATE_SD_STATUS_PERORIED,
|
||||
CHECK_UPGRADE_FILE,
|
||||
MEDIA_REPORT_EVENT,
|
||||
END
|
||||
|
|
|
@ -25,9 +25,11 @@ public:
|
|||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
protected:
|
||||
bool SdCardEventReportHandle(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
bool MediaReportHandle(VStateMachineData *msg);
|
||||
bool SdCardEventReportHandle(VStateMachineData *msg);
|
||||
bool CheckUpgradeFileHandle(VStateMachineData *msg);
|
||||
};
|
||||
#endif
|
|
@ -48,6 +48,9 @@ void StorageHandleState::ReportEvent(const StorageEvent &event)
|
|||
std::shared_ptr<VMissionData> message = std::make_shared<VMissionDataV2<StorageEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::SD_CARD_HANDLE_STATE_SD_STATUS_REPORTED), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message);
|
||||
std::shared_ptr<VMissionData> message2 = std::make_shared<VMissionDataV2<StorageEvent>>(
|
||||
static_cast<MissionEvent>(InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED), event);
|
||||
MissionStateMachine::GetInstance()->SendStateMessage(message2);
|
||||
}
|
||||
bool StorageHandleState::StorageStartInitHandle(VStateMachineData *msg)
|
||||
{
|
||||
|
|
|
@ -15,8 +15,12 @@
|
|||
#include "TestMissionState.h"
|
||||
#include "IAppManager.h"
|
||||
#include "ILog.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionStateMachine.h"
|
||||
TestMissionState::TestMissionState() : MissionState("TestMissionState")
|
||||
{
|
||||
mEventHandle[InternalStateEvent::ANY_STATE_SD_STATUS_PERORIED] =
|
||||
std::bind(&TestMissionState::SdCardEventReportSendToApp, this, _1);
|
||||
}
|
||||
void TestMissionState::GoInState()
|
||||
{
|
||||
|
@ -33,7 +37,27 @@ void TestMissionState::GoOutState()
|
|||
MissionState::GoOutState();
|
||||
LogInfo(" ========== TestMissionState::GoOutState.\n");
|
||||
}
|
||||
// bool TestMissionState::ExecuteStateMsg(VStateMachineData *msg)
|
||||
// {
|
||||
// return MissionState::EventHandle(msg);
|
||||
// }
|
||||
bool TestMissionState::SdCardEventReportSendToApp(VStateMachineData *msg)
|
||||
{
|
||||
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
||||
std::shared_ptr<VMissionDataV2<StorageEvent>> data =
|
||||
std::dynamic_pointer_cast<VMissionDataV2<StorageEvent>>(message->mMissionData);
|
||||
LogInfo(" SdCardEventHandle event:%s.\n", IStorageManager::GetInstance()->PrintStringStorageEvent(data->mData));
|
||||
SdCardStatus status = SdCardStatusConvert(data->mData);
|
||||
IAppManager::GetInstance()->SetSdCardStatus(status);
|
||||
return EXECUTED;
|
||||
}
|
||||
SdCardStatus TestMissionState::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:
|
||||
LogError("SdCardStatusConvert failed.\n");
|
||||
return SdCardStatus::END;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
#define TEST_MISSION_STATE_H
|
||||
#include "AppMonitor.h"
|
||||
#include "IStateMachine.h"
|
||||
#include "IStorageManager.h"
|
||||
#include "MissionState.h"
|
||||
class TestMissionState : public MissionState, public AppMonitor
|
||||
{
|
||||
|
@ -24,6 +25,11 @@ public:
|
|||
virtual ~TestMissionState() = default;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
// bool ExecuteStateMsg(VStateMachineData *msg) override;
|
||||
|
||||
private:
|
||||
bool SdCardEventReportSendToApp(VStateMachineData *msg);
|
||||
|
||||
private:
|
||||
SdCardStatus SdCardStatusConvert(const StorageEvent &event);
|
||||
};
|
||||
#endif
|
|
@ -337,5 +337,6 @@ public:
|
|||
virtual const StatusCode Init(const AppParam ¶m);
|
||||
virtual const StatusCode UnInit(void);
|
||||
virtual const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor);
|
||||
virtual StatusCode SetSdCardStatus(const SdCardStatus &status);
|
||||
};
|
||||
#endif
|
|
@ -63,6 +63,13 @@ const StatusCode AppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor
|
|||
mAppMonitor = monitor;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode AppManager::SetSdCardStatus(const SdCardStatus &status)
|
||||
{
|
||||
for (const auto &pair : mAppClients) {
|
||||
pair.second->SetSdCardStatus(status);
|
||||
}
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void AppManager::AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle,
|
||||
void *context)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
const StatusCode Init(const AppParam ¶m) override;
|
||||
const StatusCode UnInit(void) override;
|
||||
const StatusCode SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor) override;
|
||||
StatusCode SetSdCardStatus(const SdCardStatus &status) override;
|
||||
void AppRequestHandle(const char *url, const unsigned int urlLength, ResponseHandle responseHandle, void *context);
|
||||
void AppRequestHandleTcp(const char *data, const unsigned int dataLength, ResponseHandle responseHandle,
|
||||
void *context);
|
||||
|
|
|
@ -207,6 +207,10 @@ const StatusCode IAppManager::UnInit(void)
|
|||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
const StatusCode IAppManager::SetAppMonitor(std::shared_ptr<VAppMonitor> &monitor)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IAppManager::SetSdCardStatus(const SdCardStatus &status)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -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 "AppManagerTestTool.h"
|
||||
#include "GtestUsing.h"
|
||||
#include "HalTestTool.h"
|
||||
#include "HuntingCameraTest.h"
|
||||
#include "ILog.h"
|
||||
#include "MainThread.h"
|
||||
#include "McuManagerTestTool.h"
|
||||
#include "MissionManagerTestTool.h"
|
||||
#include "TestManager.h"
|
||||
#include <thread>
|
||||
namespace AppManager_Mock_Test
|
||||
{
|
||||
/**
|
||||
* @brief Construct a new test f object
|
||||
* ../output_files/test/bin/HuntingCameraTest
|
||||
* --gtest_filter=HuntingCameraTest.INTEGRATION_HunttingCamera_EXAMPLE_SetSdCardStatus
|
||||
*/
|
||||
TEST_F(HuntingCameraTest, INTEGRATION_HunttingCamera_EXAMPLE_SetSdCardStatus)
|
||||
{
|
||||
MainThread::GetInstance()->Init();
|
||||
TestManager::ResetTimeOut(1000 * 6);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
AppManagerTestTool::MockAppClientConnect();
|
||||
HalTestTool::MockSdCardRemove(mLinuxTest);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
HalTestTool::MockSdCardInsert(mLinuxTest);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MainThread::GetInstance()->Runing();
|
||||
// printf("helle world\n");
|
||||
// LogInfo("helle world\n");
|
||||
//
|
||||
}
|
||||
} // namespace AppManager_Mock_Test
|
|
@ -164,4 +164,13 @@ StatusCode TestMissionStateTest::UploadFile(AppUploadFile ¶m)
|
|||
return AppMonitor::UploadFile(param);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode TestMissionStateTest::AppClientConnected(std::shared_ptr<VAppClient> &client)
|
||||
{
|
||||
LogInfo("TestMissionStateTest::AppClientConnected\n");
|
||||
StatusCode code = AppClientConnectedTrace(client);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return AppMonitor::AppClientConnected(client);
|
||||
}
|
||||
return code;
|
||||
}
|
|
@ -38,6 +38,7 @@ public:
|
|||
StatusCode EnterRecorder(void) override;
|
||||
StatusCode AppPlayback(const PlayBackEvent &event) override;
|
||||
StatusCode UploadFile(AppUploadFile ¶m) override;
|
||||
StatusCode AppClientConnected(std::shared_ptr<VAppClient> &client) override;
|
||||
|
||||
protected:
|
||||
};
|
||||
|
|
|
@ -68,7 +68,10 @@ private: // About camera hal
|
|||
void InitAllCamerasMock(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
void InitCamerasMock(std::shared_ptr<VCameraHal> &vMock);
|
||||
|
||||
private: // About sd card hal
|
||||
protected: // About sd card hal
|
||||
void MockSdCardRemove(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardInsert(std::shared_ptr<LinuxTest> &mock);
|
||||
|
||||
public:
|
||||
static std::shared_ptr<VKeyHal> MakeKeyHalTest(const std::string &keyName);
|
||||
static std::shared_ptr<VLedHal> MakeLedHalTest(const std::string &ledName);
|
||||
|
|
|
@ -312,6 +312,24 @@ void HalTestTool::InitCamerasMock(std::shared_ptr<VCameraHal> &vMock)
|
|||
constexpr int USER_SHOULD_SET_CAMERA_MONITER = 1;
|
||||
EXPECT_CALL(*mock.get(), SetCameraMonitorTrace(_)).Times(USER_SHOULD_SET_CAMERA_MONITER);
|
||||
}
|
||||
void HalTestTool::MockSdCardRemove(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
std::shared_ptr<SdCardHalMock> sdCardHal = std::dynamic_pointer_cast<SdCardHalMock>(mSdCardHal);
|
||||
if (nullptr == sdCardHal) {
|
||||
LogError("SdCardHalMock is null.\n");
|
||||
return;
|
||||
}
|
||||
sdCardHal->MockSdCardRemove(mock);
|
||||
}
|
||||
void HalTestTool::MockSdCardInsert(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
std::shared_ptr<SdCardHalMock> sdCardHal = std::dynamic_pointer_cast<SdCardHalMock>(mSdCardHal);
|
||||
if (nullptr == sdCardHal) {
|
||||
LogError("SdCardHalMock is null.\n");
|
||||
return;
|
||||
}
|
||||
sdCardHal->MockSdCardInsert(mock);
|
||||
}
|
||||
std::shared_ptr<VKeyHal> HalTestTool::MakeKeyHalTest(const std::string &keyName)
|
||||
{
|
||||
std::shared_ptr<VKeyHal> key = std::make_shared<KeyControlMock>(keyName);
|
||||
|
|
|
@ -15,14 +15,15 @@
|
|||
#include "SdCardHalMock.h"
|
||||
#include "ILog.h"
|
||||
extern const char *SD_CARD_DEVICE;
|
||||
constexpr int FSTAT_SUCCESS = 0;
|
||||
constexpr int FILE_EXIST = 0;
|
||||
constexpr int FILE_NOT_EXIST = -1;
|
||||
SdCardHalMock::SdCardHalMock()
|
||||
{
|
||||
mDevFd = -1;
|
||||
}
|
||||
void SdCardHalMock::SetLinuxTest(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
constexpr int FSTAT_SUCCESS = 0;
|
||||
constexpr int FILE_EXIST = 0;
|
||||
mLinuxTest = mock;
|
||||
mDevFd = mLinuxTest->GetHandleForMock();
|
||||
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST)));
|
||||
|
@ -32,4 +33,12 @@ void SdCardHalMock::SetLinuxTest(std::shared_ptr<LinuxTest> &mock)
|
|||
};
|
||||
EXPECT_CALL(*mock.get(), fx_fstat(mDevFd, _))
|
||||
.WillRepeatedly(DoAll(WithArgs<0, 1>(Invoke(fstatFunc)), Return(FSTAT_SUCCESS)));
|
||||
}
|
||||
void SdCardHalMock::MockSdCardRemove(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_NOT_EXIST)));
|
||||
}
|
||||
void SdCardHalMock::MockSdCardInsert(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
EXPECT_CALL(*mock.get(), fx_access(SD_CARD_DEVICE, F_OK)).WillRepeatedly(DoAll(Return(FILE_EXIST)));
|
||||
}
|
|
@ -23,6 +23,8 @@ public:
|
|||
SdCardHalMock();
|
||||
virtual ~SdCardHalMock() = default;
|
||||
void SetLinuxTest(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardRemove(std::shared_ptr<LinuxTest> &mock);
|
||||
void MockSdCardInsert(std::shared_ptr<LinuxTest> &mock);
|
||||
|
||||
private:
|
||||
std::shared_ptr<LinuxTest> mLinuxTest;
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
void Init(void);
|
||||
void UnInit(void);
|
||||
|
||||
protected:
|
||||
protected: // About http
|
||||
void MockGetProductInfo(void);
|
||||
void MockGetDeviceAttr(void);
|
||||
void MockGetMediaInfo(void);
|
||||
|
@ -44,7 +44,7 @@ protected:
|
|||
void MockAppPlayback(void);
|
||||
void MockMonitorSetFileList(std::vector<AppGetFileList> &files);
|
||||
|
||||
protected:
|
||||
protected: // About TCP
|
||||
void MockAppClientConnect(void);
|
||||
void MockSetRecordingStatus(const RecordingStatus &status);
|
||||
void MockSetMicrophoneStatus(const MicrophoneStatus &status);
|
||||
|
|
|
@ -15,39 +15,9 @@
|
|||
#ifndef DEVICE_MANAGER_TEST_TOOL_H
|
||||
#define DEVICE_MANAGER_TEST_TOOL_H
|
||||
#include "DeviceManager.h"
|
||||
#include "GtestUsing.h"
|
||||
#include "HalTestTool.h"
|
||||
#include "LedControl.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
using ::testing::_;
|
||||
using ::testing::Action;
|
||||
using ::testing::ActionInterface;
|
||||
using ::testing::AnyNumber;
|
||||
using ::testing::Assign;
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::ByMove;
|
||||
using ::testing::ByRef;
|
||||
using ::testing::DefaultValue;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::DoDefault;
|
||||
using ::testing::IgnoreResult;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::InvokeWithoutArgs;
|
||||
using ::testing::MakePolymorphicAction;
|
||||
using ::testing::PolymorphicAction;
|
||||
using ::testing::Return;
|
||||
using ::testing::ReturnNew;
|
||||
using ::testing::ReturnNull;
|
||||
using ::testing::ReturnPointee;
|
||||
using ::testing::ReturnRef;
|
||||
using ::testing::ReturnRefOfCopy;
|
||||
using ::testing::ReturnRoundRobin;
|
||||
using ::testing::SaveArg;
|
||||
using ::testing::SetArgPointee;
|
||||
using ::testing::SetArgumentPointee;
|
||||
using ::testing::Unused;
|
||||
using ::testing::WithArgs;
|
||||
using ::testing::internal::BuiltInDefaultValue;
|
||||
class DeviceManagerTool : public DeviceManager
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue
Block a user