Files

111 lines
3.7 KiB
C++

#pragma once
#include <Types.hpp>
#include <filesystem>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
namespace Echoion::Standalone
{
struct ManagedCoreStartupSelection {
std::filesystem::path corePath;
std::optional<std::filesystem::path> archivedStore;
bool runtimeBaselineChanged = false;
};
// Installed runtime releases own their bundled Core baseline. A runtime
// version change archives the previous managed store; Core-only updates
// remain active across ordinary restarts of the same runtime.
[[nodiscard]] Api::Result<ManagedCoreStartupSelection>
selectManagedCoreForStartup(
const std::filesystem::path& stateDirectory,
const std::filesystem::path& bundledCore,
std::optional<std::string_view> installedRuntimeVersion);
// Roll back any uncommitted managed-plugin activation before Core loads and
// discovers plugin `current` links. This must run before PluginHost
// startup.
[[nodiscard]] Api::Result<void> reconcileManagedPluginUpdates(
const std::filesystem::path& stateDirectory);
// Host-owned update coordinator. Core only forwards authenticated RPC
// requests across the append-only host interface; all trust, download,
// staging and activation decisions remain in the long-lived daemon.
class UpdateService final
{
public:
struct Options {
std::filesystem::path configPath;
std::filesystem::path stateDirectory;
std::filesystem::path installRoot;
std::filesystem::path runningExecutable;
std::filesystem::path currentCore;
std::filesystem::path releaseManifestPath;
std::string officialFeedUrl;
std::string officialPublicKeysJson = "[]";
std::string runtimeVersion;
std::string apiVersion;
std::string toolchainAbi;
// Trusted administrator drop directory for file://
// feeds/artifacts. Empty selects stateDirectory /
// "incoming".
std::filesystem::path incomingDirectory;
};
struct Hooks {
std::function<Api::Result<void>(
const std::filesystem::path&)>
replaceCore;
std::function<Api::Result<std::string>(const std::string&)>
managePlugins;
std::function<Api::Result<std::string>(const std::string&)>
manageRuntime;
std::function<bool()> playbackActive;
std::function<std::string()> coreVersion;
};
UpdateService(Options options, Hooks hooks);
~UpdateService();
UpdateService(const UpdateService&) = delete;
UpdateService& operator=(const UpdateService&) = delete;
UpdateService(UpdateService&&) noexcept;
UpdateService& operator=(UpdateService&&) noexcept;
[[nodiscard]] Api::Result<void> start();
void stop() noexcept;
// Execute host mutations which must not run on the Core RPC stack.
// The daemon calls this from its polling loop after an RPC has
// returned.
void processPendingHostActions();
// Methods are the internal `updates.*` names forwarded by Core.
// Requests and successful responses are JSON documents matching the
// web contract.
[[nodiscard]] Api::Result<std::string>
handle(const std::string& method,
const std::string& requestJson);
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
using UpdateControlHandler = std::function<Api::Result<std::string>(
const std::string&, const std::string&)>;
// Keep the service alive for the complete duration of an in-flight host
// control request. StandaloneClientInterface intentionally invokes a copied
// handler outside its mutex, so clearing the registered handler cannot
// cancel a callback which has already started.
[[nodiscard]] UpdateControlHandler
bindUpdateService(std::shared_ptr<UpdateService> service);
} // namespace Echoion::Standalone