hunting/hal/src/HalMakePtr.cpp
2024-06-06 22:57:48 +08:00

105 lines
3.4 KiB
C++

/*
* 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 "HalMakePtr.h"
#include "Hal.h"
#include "HalCpp.h"
#include "ILog.h"
#include "SdCardHal.h"
#include "WifiHal.h"
StatusCode CreateHalModule(void)
{
IHal *hal = NULL;
StatusCode code = HalMakePtr::GetInstance()->CreateHalPtr(&hal);
if (IsCodeOK(code) && NULL != hal) {
LogInfo("Create Hal instance ok.\n");
ResetHalImpl((IHal *)hal);
}
else {
LogError("Create Hal failed.\n");
return CreateStatusCode(STATUS_CODE_NOT_OK);
}
auto instance = std::make_shared<IHalCpp>();
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
if (IsCodeOK(code2)) {
LogInfo("Hal instance is ok.\n");
IHalCpp::GetInstance(&instance);
}
return code2;
}
StatusCode DestroyHalModule(void)
{
ResetHalImpl(nullptr);
return CreateStatusCode(STATUS_CODE_OK);
}
void CreateHalCppModule(void)
{
auto instance = std::make_shared<IHalCpp>();
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
if (IsCodeOK(code2)) {
LogInfo("Hal instance is ok.\n");
IHalCpp::GetInstance(&instance);
}
}
void DestroyHalCppModule(void)
{
auto instance = std::make_shared<IHalCpp>();
IHalCpp::GetInstance(&instance);
}
std::shared_ptr<HalMakePtr> &HalMakePtr::GetInstance(std::shared_ptr<HalMakePtr> *impl)
{
static auto instance = std::make_shared<HalMakePtr>();
if (impl) {
instance = *impl;
}
return instance;
}
StatusCode HalMakePtr::CreateHalPtr(IHal **hal)
{
LogWarning("Hal is default hal.\n");
return NewHal((Hal **)hal);
}
StatusCode HalMakePtr::CreateHalSharePtr(std::shared_ptr<IHalCpp> &impl)
{
LogWarning("IHalCpp is default.\n");
impl = std::make_shared<HalCpp>();
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode HalMakePtr::CreateWifiHal(std::shared_ptr<VWifiHal> &impl)
{
LogInfo("CreateWifiHal.\n");
impl = std::make_shared<WifiHal>();
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode HalMakePtr::CreateCameraHal(std::shared_ptr<VCameraHal> &impl)
{
LogWarning("CreateCameraHal.\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode HalMakePtr::CreateSdCardHal(std::shared_ptr<VSdCardHal> &impl)
{
LogInfo("CreateSdCardHal.\n");
impl = std::make_shared<SdCardHal>();
return CreateStatusCode(STATUS_CODE_OK);
}
StatusCode HalMakePtr::CreateAllKeysHal(std::vector<std::shared_ptr<VKeyControl>> &keys)
{
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION.\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}
StatusCode HalMakePtr::CreateAllLedsHal(std::vector<std::shared_ptr<VLedControl>> &leds)
{
LogInfo("STATUS_CODE_VIRTUAL_FUNCTION.\n");
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
}