blob: 1840f60e8d7d9f2baf7796743c7204a0ca9b65f6 [file] [log] [blame]
William A. Kennington III7e2e60e2018-07-17 14:40:14 -07001#include <chrono>
2#include <cstdio>
3#include <sdeventplus/clock.hpp>
4#include <sdeventplus/event.hpp>
5#include <sdeventplus/source/time.hpp>
6#include <string>
7#include <utility>
8
9using sdeventplus::Clock;
10using sdeventplus::ClockId;
11using sdeventplus::Event;
12using sdeventplus::source::Time;
13
14int main(int argc, char* argv[])
15{
16 if (argc != 2)
17 {
18 fprintf(stderr, "Usage: %s [seconds]\n", argv[0]);
19 return 1;
20 }
21
22 unsigned interval = std::stoul(argv[1]);
23 fprintf(stderr, "Beating every %u seconds\n", interval);
24
25 auto event = Event::get_default();
26 auto hbFunc = [interval](Time<ClockId::RealTime>& source,
27 Time<ClockId::RealTime>::TimePoint time) {
28 printf("Beat\n");
29 source.set_time(time + std::chrono::seconds{interval});
30 };
31 Time<ClockId::RealTime> time(event, Clock<ClockId::RealTime>(event).now(),
32 std::chrono::seconds{1}, std::move(hbFunc));
William A. Kennington III8fd0cd42018-07-23 18:33:04 -070033 time.set_enabled(sdeventplus::source::Enabled::On);
William A. Kennington III7e2e60e2018-07-17 14:40:14 -070034 return event.loop();
35}