hunting/middleware/DeviceManager/src/DeviceManager.cpp

65 lines
2.3 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 "DeviceManager.h"
#include "LedTimer.h"
#include <vector>
const StatusCode DeviceManager::Init(void)
{
std::vector<std::shared_ptr<VLedHal>> ledHals;
IHalCpp::GetInstance()->GetLedHals(ledHals);
for (auto it = ledHals.begin(); it != ledHals.end(); ++it) {
std::shared_ptr<VLedHal> ledHal = *it;
std::shared_ptr<LedManager> ledOut =
std::make_shared<LedManager>(ledHal, NEW_LED_STATE, DEFAULT_KEEP_ALIVE_TIME, LED_NOT_BLINK);
mLedManagers.push_back(ledOut);
LedTimer::GetInstance()->AddTimerLedManager(ledOut);
}
LedTimer::GetInstance()->Init();
return CreateStatusCode(STATUS_CODE_OK);
}
const StatusCode DeviceManager::UnInit(void)
{
if (!mLedManagers.empty()) {
mLedManagers.clear();
}
LedTimer::GetInstance()->UnInit();
return CreateStatusCode(STATUS_CODE_OK);
}
const IpcMission DeviceManager::GetIpcMission(void) { return IpcMission::TEST; }
const StatusCode DeviceManager::ISetLedState(std::string ledName, LedState &CurrentState,
const unsigned int &KeepAliveTime, const unsigned int &BlinkPeriod)
{
if (!ledName.empty() || *ledName.c_str() == '\0') {
LogDebug("\n\n\n\n %s %d\n\n\n", __func__, __LINE__);
}
for (auto it = mLedManagers.begin(); it != mLedManagers.end(); ++it) {
std::shared_ptr<LedManager> ledOut = *it;
if (ledOut->GetLedHal()->GetLedName() == ledName) {
ledOut->SetLedState(CurrentState, KeepAliveTime, BlinkPeriod);
return CreateStatusCode(STATUS_CODE_OK);
}
}
LogWarning("ledName(%s) not found", ledName.c_str());
return CreateStatusCode(STATUS_CODE_NOT_OK);
}