/* * 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(); 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(); 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::GetInstance(&instance); } std::shared_ptr &HalMakePtr::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); 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 &impl) { LogWarning("IHalCpp is default.\n"); impl = std::make_shared(); return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalMakePtr::CreateWifiHal(std::shared_ptr &impl) { LogWarning("CreateWifiHal.\n"); impl = std::make_shared(); return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalMakePtr::CreateCameraHal(std::shared_ptr &impl) { LogWarning("CreateCameraHal.\n"); return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); } StatusCode HalMakePtr::CreateSdCardHal(std::shared_ptr &impl) { LogWarning("CreateSdCardHal.\n"); impl = std::make_shared(); return CreateStatusCode(STATUS_CODE_OK); }