/* * * Copyright (c) 2022 Project CHIP Authors * * 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 "OTAInitializer.h" #include "app/clusters/ota-requestor/DefaultOTARequestorStorage.h" #include #include #include #include using namespace chip; using namespace chip::DeviceLayer; namespace { DefaultOTARequestor gRequestorCore; DefaultOTARequestorStorage gRequestorStorage; DefaultOTARequestorDriver gRequestorUser; BDXDownloader gDownloader; AmebaOTAImageProcessor gImageProcessor; } // namespace extern "C" void amebaQueryImageCmdHandler() { ChipLogProgress(DeviceLayer, "Calling amebaQueryImageCmdHandler"); if (OTAInitializer::Instance().CheckInit()) PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); }); } extern "C" void amebaApplyUpdateCmdHandler() { ChipLogProgress(DeviceLayer, "Calling amebaApplyUpdateCmdHandler"); if (OTAInitializer::Instance().CheckInit()) PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); }); } void OTAInitializer::InitOTARequestor() { SetRequestorInstance(&gRequestorCore); gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage()); // Set server instance used for session establishment gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); gImageProcessor.SetOTADownloader(&gDownloader); // Connect the Downloader and Image Processor objects gDownloader.SetImageProcessorDelegate(&gImageProcessor); gRequestorUser.Init(&gRequestorCore, &gImageProcessor); initialized = true; } bool OTAInitializer::CheckInit() { return initialized; }