/* * Copyright (C) 2026 oxmc / PawletOS * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include #include #include #include #include #include #include "handlers.h" #include "state.h" namespace pawlet::hwupdate { // Thread-safe snapshots exposed to the AIDL layer. struct ComponentStatus { std::string componentId; std::string productId; std::string componentClass; std::string role; std::string transport; bool present = false; std::string installedVersion; std::string hardwareRevision; std::string support; }; struct PendingUpdate { std::string componentId; bool available = false; std::string version; int64_t sizeBytes = 0; std::string changelogUrl; }; struct EngineConfig { std::string manifestPath; std::string serverBaseUrl; // ".../ota.php?mode=hardware" std::string stateDir; // e.g. /data/pawlet/hw int maxRetries = 3; bool autoApply = true; }; class Engine { public: explicit Engine(EngineConfig cfg); ~Engine(); void Start(); // spawns worker, runs an initial cycle void Stop(); // Request an asynchronous detect+check(+apply) cycle. void CheckNow(); // Snapshots (safe to call from binder threads). std::vector Components() const; std::vector Pending() const; bool IsBusy() const { return busy_.load(); } int LastResult() const { return lastResult_.load(); } private: void WorkerLoop(); int RunCycle(); // returns 0 on success EngineConfig cfg_; HandlerRegistry handlers_; State state_; mutable std::mutex snapMu_; std::vector components_; std::vector pending_; std::thread worker_; std::mutex reqMu_; std::condition_variable reqCv_; bool requested_ = false; bool stop_ = false; std::atomic busy_{false}; std::atomic lastResult_{0}; }; } // namespace pawlet::hwupdate