#pragma once #include #include #include #include #include "release_info.h" namespace roro { // What the device knows of the project's releases on Gitea (docs/milestones/R1.md, #6): the latest, // and a list of the last ten. The fetching runs on the Update Service's task; the screens read what // came out, from the main loop. class GiteaReleases { public: enum class Status : uint8_t { Never, Busy, Done, Failed }; static constexpr size_t kListSize = 10; GiteaReleases() : lock_(xSemaphoreCreateMutex()) {} // On the Update Service's task. True when the answer was read; otherwise error() says why. bool fetchLatest(); bool fetchList(); void fail(const std::string& error) { finish(false, error); } // something stopped it before it began Status status() const; std::string error() const; uint32_t seq() const; // grows with every answer that changed something bool latest(release::Release& out) const; // false: not fetched yet std::vector list() const; bool find(const std::string& tag, release::Release& out) const; // in the list, or the latest private: bool fetch(const std::string& path, size_t max, std::vector& out); void finish(bool ok, const std::string& error); mutable SemaphoreHandle_t lock_; Status status_ = Status::Never; std::string error_; uint32_t seq_ = 0; bool haveLatest_ = false; release::Release latest_; std::vector list_; }; } // namespace roro