2026-05-31 18:14:46 +02:00
|
|
|
// Driver for the GENERATED native C++ bindings (my_timer_native.hpp).
|
|
|
|
|
#include "my_timer_native.hpp"
|
|
|
|
|
#include <iostream>
|
|
|
|
|
int main() {
|
|
|
|
|
try {
|
|
|
|
|
my_timer::My_timerNode node(my_timer::TimerConfig{"cpp-native-gen"});
|
|
|
|
|
std::cout << "version: " << node.Version() << "\n";
|
|
|
|
|
|
2026-05-31 18:23:02 +02:00
|
|
|
my_timer::EchoEvent gotEvt;
|
|
|
|
|
bool got = false;
|
|
|
|
|
node.OnEchoFired([&](const my_timer::EchoEvent& e){ gotEvt = e; got = true; });
|
|
|
|
|
|
2026-05-31 18:14:46 +02:00
|
|
|
auto r = node.Echo(my_timer::EchoRequest{"hello from generated C++", 5});
|
2026-05-31 18:20:38 +02:00
|
|
|
std::cout << "echo: echoed=" << r.echoed << " timerName=" << r.timerName << "\n";
|
2026-05-31 18:23:02 +02:00
|
|
|
if (got) std::cout << "event OnEchoFired: message=\"" << gotEvt.message << "\" echoCount=" << gotEvt.echoCount << "\n";
|
2026-05-31 18:20:38 +02:00
|
|
|
|
|
|
|
|
// seq + Option params (ComplexRequest), typed ComplexResponse return.
|
|
|
|
|
my_timer::ComplexRequest creq;
|
|
|
|
|
creq.messages = {{"one", 0}, {"two", 0}};
|
|
|
|
|
creq.tags = {"a", "b"};
|
|
|
|
|
creq.note = "a note";
|
|
|
|
|
creq.retries = 3;
|
|
|
|
|
auto c = node.Complex(creq);
|
|
|
|
|
std::cout << "complex: itemCount=" << c.itemCount << " hasNote=" << c.hasNote
|
|
|
|
|
<< " summary=\"" << c.summary << "\"\n";
|
|
|
|
|
|
|
|
|
|
// Multiple struct params (JobSpec, RetryPolicy, ScheduleConfig).
|
|
|
|
|
my_timer::JobSpec job; job.name = "nightly"; job.payload = {"x"}; job.priority = 5;
|
|
|
|
|
my_timer::RetryPolicy retry; retry.maxAttempts = 3; retry.backoffMs = 100; retry.retryOn = {"timeout"};
|
|
|
|
|
my_timer::ScheduleConfig sched; sched.startAtMs = 1000; sched.intervalMs = 5000; sched.jitter = 50;
|
|
|
|
|
auto s = node.Schedule(job, retry, sched);
|
|
|
|
|
std::cout << "schedule: jobId=\"" << s.jobId << "\" willRunCount=" << s.willRunCount << "\n";
|
2026-05-31 18:14:46 +02:00
|
|
|
|
|
|
|
|
std::cout << "done.\n";
|
|
|
|
|
return 0;
|
|
|
|
|
} catch (const std::exception &e) {
|
2026-05-31 18:20:38 +02:00
|
|
|
std::cerr << "error: " << e.what() << "\n"; return 1;
|
2026-05-31 18:14:46 +02:00
|
|
|
}
|
|
|
|
|
}
|