// Generated by nim-ffi native C++ codegen. Do not edit by hand. // // Native (zero-serialization) wrapper over the C ABI in "my_timer.h". Struct params/returns cross as flat C-POD structs — no CBOR. For the // inter-process path use the CBOR header (my_timer_cbor.hpp). #ifndef NIM_FFI_GEN_MY_TIMER_NATIVE_HPP #define NIM_FFI_GEN_MY_TIMER_NATIVE_HPP #include "my_timer.h" #include #include #include #include namespace my_timer { struct TimerConfig { std::string name{}; }; inline ::TimerConfig toC(const TimerConfig& v) { ::TimerConfig c{}; c.name = v.name.c_str(); return c; } inline TimerConfig fromC(const ::TimerConfig& c) { TimerConfig v{}; v.name = c.name ? std::string(c.name) : std::string(); return v; } struct EchoRequest { std::string message{}; int64_t delayMs{}; }; inline ::EchoRequest toC(const EchoRequest& v) { ::EchoRequest c{}; c.message = v.message.c_str(); c.delayMs = v.delayMs; return c; } inline EchoRequest fromC(const ::EchoRequest& c) { EchoRequest v{}; v.message = c.message ? std::string(c.message) : std::string(); v.delayMs = c.delayMs; return v; } struct EchoResponse { std::string echoed{}; std::string timerName{}; }; inline ::EchoResponse toC(const EchoResponse& v) { ::EchoResponse c{}; c.echoed = v.echoed.c_str(); c.timerName = v.timerName.c_str(); return c; } inline EchoResponse fromC(const ::EchoResponse& c) { EchoResponse v{}; v.echoed = c.echoed ? std::string(c.echoed) : std::string(); v.timerName = c.timerName ? std::string(c.timerName) : std::string(); return v; } struct ComplexResponse { std::string summary{}; int64_t itemCount{}; bool hasNote{}; }; inline ::ComplexResponse toC(const ComplexResponse& v) { ::ComplexResponse c{}; c.summary = v.summary.c_str(); c.itemCount = v.itemCount; c.hasNote = (v.hasNote ? 1 : 0); return c; } inline ComplexResponse fromC(const ::ComplexResponse& c) { ComplexResponse v{}; v.summary = c.summary ? std::string(c.summary) : std::string(); v.itemCount = c.itemCount; v.hasNote = c.hasNote != 0; return v; } struct EchoEvent { std::string message{}; int64_t echoCount{}; }; inline ::EchoEvent toC(const EchoEvent& v) { ::EchoEvent c{}; c.message = v.message.c_str(); c.echoCount = v.echoCount; return c; } inline EchoEvent fromC(const ::EchoEvent& c) { EchoEvent v{}; v.message = c.message ? std::string(c.message) : std::string(); v.echoCount = c.echoCount; return v; } struct ScheduleResult { std::string jobId{}; int64_t willRunCount{}; int64_t firstRunAtMs{}; int64_t effectiveBackoffMs{}; }; inline ::ScheduleResult toC(const ScheduleResult& v) { ::ScheduleResult c{}; c.jobId = v.jobId.c_str(); c.willRunCount = v.willRunCount; c.firstRunAtMs = v.firstRunAtMs; c.effectiveBackoffMs = v.effectiveBackoffMs; return c; } inline ScheduleResult fromC(const ::ScheduleResult& c) { ScheduleResult v{}; v.jobId = c.jobId ? std::string(c.jobId) : std::string(); v.willRunCount = c.willRunCount; v.firstRunAtMs = c.firstRunAtMs; v.effectiveBackoffMs = c.effectiveBackoffMs; return v; } namespace detail { template struct Capture { int ret = RET_ERR; T value{}; std::string err; std::promise done; }; struct AckCapture { int ret = RET_ERR; std::string err; std::promise done; }; inline std::string rawText(const char* msg, std::size_t len) { return (msg && len) ? std::string(msg, len) : std::string(); } } // namespace detail extern "C" { inline void my_timer_native_ack(int ret, const char* msg, std::size_t len, void* ud) { auto* c = static_cast(ud); c->ret = ret; if (ret == RET_ERR) c->err = detail::rawText(msg, len); c->done.set_value(); } inline void my_timer_native_str(int ret, const char* msg, std::size_t len, void* ud) { auto* c = static_cast*>(ud); c->ret = ret; if (ret == RET_OK) c->value = detail::rawText(msg, len); else c->err = detail::rawText(msg, len); c->done.set_value(); } inline void my_timer_native_my_timer_echo(int ret, const char* msg, std::size_t len, void* ud) { auto* c = static_cast*>(ud); c->ret = ret; if (ret == RET_OK) c->value = fromC(*reinterpret_cast(msg)); else c->err = detail::rawText(msg, len); c->done.set_value(); } } // extern "C" class My_timerNode { public: explicit My_timerNode(const TimerConfig& config) { detail::AckCapture cap; auto fut = cap.done.get_future(); auto c_config = toC(config); ctx_ = my_timer_create(c_config, my_timer_native_ack, &cap); if (!ctx_) throw std::runtime_error("my_timer_create returned null"); fut.wait(); if (cap.ret != RET_OK) throw std::runtime_error(cap.err); } EchoResponse Echo(const EchoRequest& req) { detail::Capture cap; auto fut = cap.done.get_future(); auto c_req = toC(req); if (my_timer_echo(ctx_, my_timer_native_my_timer_echo, &cap, c_req) != RET_OK) throw std::runtime_error("my_timer_echo dispatch failed"); fut.wait(); if (cap.ret != RET_OK) throw std::runtime_error(cap.err); return cap.value; } std::string Version() { detail::Capture cap; auto fut = cap.done.get_future(); if (my_timer_version(ctx_, my_timer_native_str, &cap) != RET_OK) throw std::runtime_error("my_timer_version dispatch failed"); fut.wait(); if (cap.ret != RET_OK) throw std::runtime_error(cap.err); return cap.value; } // SKIPPED my_timer_complex: seq/Option/multi-struct params not yet supported by native C++ codegen // SKIPPED my_timer_schedule: seq/Option/multi-struct params not yet supported by native C++ codegen ~My_timerNode() { if (ctx_) my_timer_destroy(ctx_); } My_timerNode(const My_timerNode&) = delete; My_timerNode& operator=(const My_timerNode&) = delete; private: void* ctx_ = nullptr; }; } // namespace my_timer #endif // NIM_FFI_GEN_MY_TIMER_NATIVE_HPP