#pragma once
#include "sd-event.h"
#include "sd-resolve.h"
#include "sd-network.h"
#include "list.h"
#include "socket-util.h"
#include "ratelimit.h"
typedef struct Manager Manager;
#include "timesyncd-server.h"
struct Manager {
sd_event *event;
sd_resolve *resolve;
LIST_HEAD(ServerName, system_servers);
LIST_HEAD(ServerName, link_servers);
LIST_HEAD(ServerName, fallback_servers);
RateLimit ratelimit;
bool exhausted_servers;
sd_event_source *network_event_source;
sd_network_monitor *network_monitor;
sd_resolve_query *resolve_query;
sd_event_source *event_receive;
ServerName *current_server_name;
ServerAddress *current_server_address;
int server_socket;
int missed_replies;
uint64_t packet_count;
sd_event_source *event_timeout;
struct timespec trans_time_mon;
struct timespec trans_time;
usec_t retry_interval;
bool pending;
sd_event_source *event_timer;
usec_t poll_interval_usec;
bool poll_resync;
struct {
double offset;
double delay;
} samples[8];
unsigned int samples_idx;
double samples_jitter;
bool jumped;
bool sync;
int drift_ppm;
sd_event_source *event_clock_watch;
int clock_watch_fd;
sd_event_source *event_retry;
bool rtc_local_time;
};
int manager_new(Manager **ret);
void manager_free(Manager *m);
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
void manager_set_server_name(Manager *m, ServerName *n);
void manager_set_server_address(Manager *m, ServerAddress *a);
void manager_flush_server_names(Manager *m, ServerType t);
int manager_connect(Manager *m);
void manager_disconnect(Manager *m);