MCPcopy Create free account
hub / github.com/AimRT/AimRT / Start

Method Start

src/examples/cpp/executor/module/timer_module/timer_module.cc:22–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22bool TimerModule::Start() {
23 using namespace std::chrono_literals;
24
25 auto start_time = timer_executor_.Now();
26 auto task = [logger = core_.GetLogger(), start_time](aimrt::executor::TimerBase& timer) {
27 static int count = 0;
28
29 auto now = timer.Executor().Now();
30 auto timepoint = std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time).count();
31 AIMRT_HL_INFO(logger, "Executed {} times, execute timepoint: {} ms", ++count, timepoint);
32
33 if (count >= 10) {
34 timer.Cancel();
35 AIMRT_HL_INFO(logger, "Timer cancelled at timepoint: {} ms", timepoint);
36 }
37 };
38
39 timer_ = aimrt::executor::CreateTimer(timer_executor_, 100ms, std::move(task));
40 AIMRT_INFO("Timer created at timepoint: 0 ms");
41
42 timer_executor_.ExecuteAfter(350ms, [this, logger = core_.GetLogger()]() {
43 timer_->Reset();
44 AIMRT_HL_INFO(logger, "Timer reset at timepoint: 350 ms");
45 });
46
47 timer_executor_.ExecuteAfter(600ms, [this, logger = core_.GetLogger()]() {
48 timer_->Reset();
49 AIMRT_HL_INFO(logger, "Timer reset at timepoint: 600 ms");
50 });
51
52 return true;
53}
54
55void TimerModule::Shutdown() { timer_->Cancel(); }
56

Callers

nothing calls this directly

Calls 7

CreateTimerFunction · 0.85
ExecutorMethod · 0.80
CancelMethod · 0.80
ExecuteAfterMethod · 0.80
NowMethod · 0.45
GetLoggerMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected