blob: e45ae893cd80d8e1903a508e41b23ad65e4884ac [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));
33 time.set_enabled(SD_EVENT_ON);
34 return event.loop();
35}