2018-04-28 22:22:28 +02:00
|
|
|
//
|
2020-01-01 02:23:48 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
2018-04-28 22:22:28 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
2019-02-12 22:26:36 +01:00
|
|
|
#include "td/utils/common.h"
|
2020-09-24 18:15:42 +02:00
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/StorerBase.h"
|
2019-08-14 02:13:34 +02:00
|
|
|
#include "td/utils/Time.h"
|
|
|
|
#include "td/utils/tl_helpers.h"
|
2018-04-28 22:22:28 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2020-09-24 18:15:42 +02:00
|
|
|
struct LogEventIdWithGeneration {
|
2020-09-22 01:15:09 +02:00
|
|
|
uint64 log_event_id = 0;
|
2020-09-21 14:21:41 +02:00
|
|
|
uint64 generation = 0;
|
|
|
|
};
|
2018-04-28 22:22:28 +02:00
|
|
|
|
2020-09-24 18:15:42 +02:00
|
|
|
void add_log_event(LogEventIdWithGeneration &log_event_id, const Storer &storer, uint32 type, Slice name);
|
2018-04-28 22:22:28 +02:00
|
|
|
|
2020-09-24 18:15:42 +02:00
|
|
|
void delete_log_event(LogEventIdWithGeneration &log_event_id, uint64 generation, Slice name);
|
2020-09-21 14:21:41 +02:00
|
|
|
|
2020-09-22 01:15:09 +02:00
|
|
|
Promise<Unit> get_erase_log_event_promise(uint64 log_event_id, Promise<Unit> promise = Promise<Unit>());
|
2018-04-28 22:22:28 +02:00
|
|
|
|
2019-08-10 23:14:35 +02:00
|
|
|
template <class StorerT>
|
|
|
|
void store_time(double time_at, StorerT &storer) {
|
|
|
|
if (time_at == 0) {
|
|
|
|
store(-1.0, storer);
|
|
|
|
} else {
|
|
|
|
double time_left = max(time_at - Time::now(), 0.0);
|
|
|
|
store(time_left, storer);
|
2020-02-01 05:43:54 +01:00
|
|
|
store(get_server_time(), storer);
|
2019-08-10 23:14:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse_time(double &time_at, ParserT &parser) {
|
|
|
|
double time_left;
|
|
|
|
parse(time_left, parser);
|
|
|
|
if (time_left < -0.1) {
|
|
|
|
time_at = 0;
|
|
|
|
} else {
|
|
|
|
double old_server_time;
|
|
|
|
parse(old_server_time, parser);
|
|
|
|
double passed_server_time = max(parser.context()->server_time() - old_server_time, 0.0);
|
|
|
|
time_left = max(time_left - passed_server_time, 0.0);
|
|
|
|
time_at = Time::now_cached() + time_left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 22:22:28 +02:00
|
|
|
} // namespace td
|