/* * 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 "HalCpp.h" #include "HalMakePtr.h" #include "IHalCpp.h" #include "ILog.h" #include "SdCardHal.h" #include "StatusCode.h" #include "WifiHal.h" #include #include #include #include StatusCode HalCpp::Init(void) { LogInfo("HalCpp::Init\n"); HalMakePtr::GetInstance()->CreateWifiHal(mWifiHal); std::shared_ptr wifiImpl = std::dynamic_pointer_cast(mWifiHal); if (nullptr != wifiImpl) { wifiImpl->Init(); } HalMakePtr::GetInstance()->CreateSdCardHal(mSdCardHal); std::shared_ptr sdCardImpl = std::dynamic_pointer_cast(mSdCardHal); if (nullptr != sdCardImpl) { sdCardImpl->Init(); } HalMakePtr::GetInstance()->CreateAllKeysHal(mKeys); HalMakePtr::GetInstance()->CreateAllLedsHal(mLeds); return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalCpp::UnInit(void) { LogInfo("HalCpp::UnInit\n"); std::shared_ptr sdCardImpl = std::dynamic_pointer_cast(mSdCardHal); if (nullptr != sdCardImpl) { sdCardImpl->UnInit(); } mWifiHal.reset(); mSdCardHal.reset(); return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalCpp::GetWifiHal(std::shared_ptr &wifi) { wifi = mWifiHal; return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalCpp::GetSdCardHal(std::shared_ptr &sdCard) { sdCard = mSdCardHal; return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalCpp::GetAllLeds(std::map> &allLeds) { LogInfo("GetAllLeds, size = %d\n", mLeds.size()); for (auto &led : mLeds) { std::shared_ptr ledControl = std::dynamic_pointer_cast(led); if (nullptr == ledControl) { LogError("ledControl is nullptr\n"); continue; } allLeds.insert(std::make_pair(led->GetLedName(), ledControl)); } return CreateStatusCode(STATUS_CODE_OK); } StatusCode HalCpp::GetAllKeys(std::map> &allKeys) { LogInfo("GetAllKeys\n"); for (auto &key : mKeys) { std::shared_ptr keyControl = std::dynamic_pointer_cast(key); if (nullptr == keyControl) { LogError("keyControl is nullptr\n"); continue; } allKeys.insert(std::make_pair(key->GetKeyName(), keyControl)); } return CreateStatusCode(STATUS_CODE_OK); }