// Copyright (c) 2026 Juhapekka Piiroinen // All Rights Reserved. // AmoosedWeb project: https://amoosed.com #pragma once #include "AmoosedWeb/PreviewC.h" #include #include // Source-only C++17 conveniences for the experimental C ABI. No C++ type // crosses the shared-library boundary. The caller must finish an in-flight // call before either owning object is destroyed. namespace amoosed::preview { class Operation final { public: Operation() = default; ~Operation() { amw_preview_operation_release(handle_); } Operation(const Operation&) = delete; Operation& operator=(const Operation&) = delete; Operation(Operation&&) = delete; Operation& operator=(Operation&&) = delete; [[nodiscard]] std::int32_t prepare() noexcept { if (handle_) return AMW_PREVIEW_INVALID_STATE; return amw_preview_operation_prepare(&handle_); } void cancel() noexcept { amw_preview_operation_cancel(handle_); } [[nodiscard]] amw_preview_operation* get() const noexcept { return handle_; } private: amw_preview_operation* handle_ = nullptr; }; class Site final { public: Site() = default; ~Site() { amw_preview_site_release(handle_); } Site(const Site&) = delete; Site& operator=(const Site&) = delete; Site(Site&&) = delete; Site& operator=(Site&&) = delete; [[nodiscard]] std::int32_t prepare(std::string_view origin, char* error = nullptr, std::uint64_t error_capacity = 0) noexcept { if (handle_) return AMW_PREVIEW_INVALID_STATE; return amw_preview_site_prepare(origin.data(), origin.size(), &handle_, error, error_capacity); } [[nodiscard]] std::int32_t load_hosted(Operation& operation, char* error = nullptr, std::uint64_t error_capacity = 0) noexcept { return amw_preview_site_load_hosted_operation(handle_, operation.get(), error, error_capacity); } [[nodiscard]] std::int32_t load_external(Operation& operation, const std::uint8_t* credential, std::uint64_t credential_length, char* error = nullptr, std::uint64_t error_capacity = 0) noexcept { return amw_preview_site_load_external_operation(handle_, operation.get(), credential, credential_length, error, error_capacity); } [[nodiscard]] amw_preview_site* get() const noexcept { return handle_; } private: amw_preview_site* handle_ = nullptr; }; } // namespace amoosed::preview