]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/timesync/timesyncd-manager.h
Merge pull request #1957 from zonque/qemu-test
[thirdparty/systemd.git] / src / timesync / timesyncd-manager.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2014 Kay Sievers, Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "sd-event.h"
25 #include "sd-network.h"
26 #include "sd-resolve.h"
27
28 #include "list.h"
29 #include "ratelimit.h"
30
31 typedef struct Manager Manager;
32
33 #include "timesyncd-server.h"
34
35 struct Manager {
36 sd_event *event;
37 sd_resolve *resolve;
38
39 LIST_HEAD(ServerName, system_servers);
40 LIST_HEAD(ServerName, link_servers);
41 LIST_HEAD(ServerName, fallback_servers);
42
43 RateLimit ratelimit;
44 bool exhausted_servers;
45
46 /* network */
47 sd_event_source *network_event_source;
48 sd_network_monitor *network_monitor;
49
50 /* peer */
51 sd_resolve_query *resolve_query;
52 sd_event_source *event_receive;
53 ServerName *current_server_name;
54 ServerAddress *current_server_address;
55 int server_socket;
56 int missed_replies;
57 uint64_t packet_count;
58 sd_event_source *event_timeout;
59 bool good;
60
61 /* last sent packet */
62 struct timespec trans_time_mon;
63 struct timespec trans_time;
64 usec_t retry_interval;
65 bool pending;
66
67 /* poll timer */
68 sd_event_source *event_timer;
69 usec_t poll_interval_usec;
70 bool poll_resync;
71
72 /* history data */
73 struct {
74 double offset;
75 double delay;
76 } samples[8];
77 unsigned int samples_idx;
78 double samples_jitter;
79
80 /* last change */
81 bool jumped;
82 bool sync;
83 int drift_ppm;
84
85 /* watch for time changes */
86 sd_event_source *event_clock_watch;
87 int clock_watch_fd;
88
89 /* Retry connections */
90 sd_event_source *event_retry;
91
92 /* RTC runs in local time, leave it alone */
93 bool rtc_local_time;
94 };
95
96 int manager_new(Manager **ret);
97 void manager_free(Manager *m);
98
99 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
100
101 void manager_set_server_name(Manager *m, ServerName *n);
102 void manager_set_server_address(Manager *m, ServerAddress *a);
103 void manager_flush_server_names(Manager *m, ServerType t);
104
105 int manager_connect(Manager *m);
106 void manager_disconnect(Manager *m);