Migrate to VoidLibrary (toolchain + API groundwork)
This commit is contained in:
1 parent
5e1e3d66c4
commit
e17cfed56f
38 files changed
+3077
-2505
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// Opaque state blob - contents are internal to Core
|
||||
// Plugin should NEVER inspect or modify the data field
|
||||
struct StateBlob {
|
||||
std::vector<uint8_t>
|
||||
data; // Serialized state data (JSON using glaze)
|
||||
uint32_t version = 0; // Format version (for logging/debugging only)
|
||||
std::string timestamp; // ISO 8601 timestamp when saved
|
||||
|
||||
bool empty() const { return data.empty(); }
|
||||
size_t size() const { return data.size(); }
|
||||
|
||||
// Clear the state
|
||||
void clear()
|
||||
{
|
||||
data.clear();
|
||||
version = 0;
|
||||
timestamp.clear();
|
||||
}
|
||||
};
|
||||
|
||||
// Constants for state management
|
||||
constexpr uint32_t MAX_SUPPORTED_STATE_VERSION_AGE =
|
||||
10; // Support 10 versions back
|
||||
constexpr uint32_t STATE_VERSION_NONE = 0;
|
||||
|
||||
} // namespace Echoion::Api
|
||||
@@ -0,0 +1,140 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <format>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// Version constants
|
||||
inline constexpr uint32_t VERSION_MAJOR = 1;
|
||||
inline constexpr uint32_t VERSION_MINOR = 0;
|
||||
inline constexpr uint32_t VERSION_PATCH = 0;
|
||||
inline constexpr const char* VERSION_STRING = "1.0.0";
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
enum class ErrorCode : uint32_t {
|
||||
Success = 0,
|
||||
InvalidArgument,
|
||||
NotFound,
|
||||
AlreadyExists,
|
||||
NetworkError,
|
||||
ParseError,
|
||||
AudioError,
|
||||
PluginError,
|
||||
InvalidUrl,
|
||||
NotAuthenticated,
|
||||
Unauthorized,
|
||||
PermissionDenied,
|
||||
ServiceUnavailable,
|
||||
DatabaseError,
|
||||
NotSupported,
|
||||
NotInitialized,
|
||||
IncompatibleVersion, // State version incompatible
|
||||
UnknownError
|
||||
};
|
||||
|
||||
struct Error {
|
||||
ErrorCode code = ErrorCode::UnknownError;
|
||||
std::string message;
|
||||
std::string source;
|
||||
std::chrono::system_clock::time_point timestamp;
|
||||
// Optional underlying cause (set via with_context), forming a chain.
|
||||
std::shared_ptr<const Error> cause;
|
||||
|
||||
Error() = default;
|
||||
Error(ErrorCode c, std::string_view msg, std::string_view src = "")
|
||||
: code(c), message(msg), source(src),
|
||||
timestamp(std::chrono::system_clock::now())
|
||||
{
|
||||
}
|
||||
|
||||
// Void::Result context API: wrap this error as the cause of a new
|
||||
// contextual layer, preserving the original ErrorCode and source.
|
||||
[[nodiscard]] Error with_context(std::string ctx) const&
|
||||
{
|
||||
Error e(code, ctx, source);
|
||||
e.cause = std::make_shared<const Error>(*this);
|
||||
return e;
|
||||
}
|
||||
[[nodiscard]] Error with_context(std::string ctx) &&
|
||||
{
|
||||
Error e(code, ctx, source);
|
||||
e.cause = std::make_shared<const Error>(std::move(*this));
|
||||
return e;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string toString() const
|
||||
{
|
||||
std::string out =
|
||||
std::format("[{}] {} (from: {})",
|
||||
static_cast<uint32_t>(code), message, source);
|
||||
for (const Error* c = cause.get(); c; c = c->cause.get()) {
|
||||
out += std::format("\n caused by: {}", c->message);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
// Result<T> aliases Void::Result with Echoion's domain Error (which keeps
|
||||
// the ErrorCode used across RPC and error handling). Void::Result::Result
|
||||
// is itself std::expected<T, E>, so existing call sites are unaffected and
|
||||
// Void::Result::ok/fail/with_context all work with Api::Error.
|
||||
template <typename T>
|
||||
using Result = Void::Result::Result<T, Error>;
|
||||
|
||||
enum class LogLevel : uint8_t { Debug = 0, Info, Warning, Error, Critical };
|
||||
|
||||
inline constexpr std::string LogLevelToString(const LogLevel level) noexcept
|
||||
{
|
||||
switch (level) {
|
||||
|
||||
case LogLevel::Debug:
|
||||
return "Debug";
|
||||
case LogLevel::Info:
|
||||
return "Info";
|
||||
case LogLevel::Warning:
|
||||
return "Warning";
|
||||
case LogLevel::Error:
|
||||
return "Error";
|
||||
case LogLevel::Critical:
|
||||
return "Critical";
|
||||
}
|
||||
}
|
||||
inline constexpr LogLevel StringToLogLevel(const std::string level) noexcept
|
||||
{
|
||||
if (level == "Info") {
|
||||
return LogLevel::Info;
|
||||
} else if (level == "Warning") {
|
||||
return LogLevel::Warning;
|
||||
|
||||
} else if (level == "Error") {
|
||||
return LogLevel::Error;
|
||||
|
||||
} else if (level == "Critical") {
|
||||
return LogLevel::Critical;
|
||||
}
|
||||
return LogLevel::Debug;
|
||||
}
|
||||
|
||||
struct LogEntry {
|
||||
LogLevel level;
|
||||
std::string message;
|
||||
std::string source;
|
||||
std::string sourceFile;
|
||||
uint32_t sourceLine = 0;
|
||||
std::string function;
|
||||
std::thread::id threadId;
|
||||
std::chrono::system_clock::time_point timestamp;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user