2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01: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
|
|
|
|
|
|
|
|
///\file
|
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/td_api.hpp"
|
2020-11-15 15:38:10 +01:00
|
|
|
#include "td/telegram/TdCallback.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-07-30 21:59:23 +02:00
|
|
|
#include "td/actor/actor.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
|
2020-08-01 20:57:03 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
namespace td {
|
|
|
|
|
2020-07-30 16:28:56 +02:00
|
|
|
class NetQueryStats;
|
2020-07-30 21:59:23 +02:00
|
|
|
class Td;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a low-level Actor interface for interaction with TDLib. The interface is a lot more flexible than
|
2021-09-26 21:17:02 +02:00
|
|
|
* the ClientManager interface, however, for most usages the ClientManager interface should be sufficient.
|
2018-12-31 20:04:05 +01:00
|
|
|
*/
|
2021-07-04 04:58:54 +02:00
|
|
|
class ClientActor final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2020-11-15 15:38:10 +01:00
|
|
|
/// Options for ClientActor creation.
|
2020-07-30 16:28:56 +02:00
|
|
|
struct Options {
|
2020-11-15 15:38:10 +01:00
|
|
|
/// NetQueryStats object for this client.
|
2020-07-30 16:28:56 +02:00
|
|
|
std::shared_ptr<NetQueryStats> net_query_stats;
|
2020-07-30 21:59:23 +02:00
|
|
|
|
2020-11-15 15:38:10 +01:00
|
|
|
/// Default constructor.
|
2020-07-30 21:59:23 +02:00
|
|
|
Options() {
|
|
|
|
}
|
2020-07-30 16:28:56 +02:00
|
|
|
};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
/**
|
|
|
|
* Creates a ClientActor using the specified callback.
|
|
|
|
* \param[in] callback Callback for outgoing notifications from TDLib.
|
2020-11-15 15:38:10 +01:00
|
|
|
* \param[in] options Options to create the TDLib.
|
2018-12-31 20:04:05 +01:00
|
|
|
*/
|
2020-07-30 16:28:56 +02:00
|
|
|
explicit ClientActor(unique_ptr<TdCallback> callback, Options options = {});
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends one request to TDLib. The answer will be received via callback.
|
|
|
|
* \param[in] id Request identifier, must be positive.
|
|
|
|
* \param[in] request The request.
|
|
|
|
*/
|
|
|
|
void request(uint64 id, td_api::object_ptr<td_api::Function> request);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronously executes a TDLib request. Only a few requests can be executed synchronously.
|
|
|
|
* May be called from any thread.
|
2020-11-15 15:38:10 +01:00
|
|
|
* \param[in] request Request to the TDLib instance.
|
2018-12-31 20:04:05 +01:00
|
|
|
* \return The request response.
|
|
|
|
*/
|
|
|
|
static td_api::object_ptr<td_api::Object> execute(td_api::object_ptr<td_api::Function> request);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the ClientActor and the TDLib instance.
|
|
|
|
*/
|
2021-10-19 17:11:16 +02:00
|
|
|
~ClientActor() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
2021-10-18 13:36:15 +02:00
|
|
|
ClientActor(ClientActor &&other) noexcept;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
2021-10-18 13:36:15 +02:00
|
|
|
ClientActor &operator=(ClientActor &&other) noexcept;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
ClientActor(const ClientActor &other) = delete;
|
2021-10-18 13:36:15 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
ClientActor &operator=(const ClientActor &other) = delete;
|
|
|
|
|
|
|
|
private:
|
2022-10-04 18:02:31 +02:00
|
|
|
void start_up() final;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorOwn<Td> td_;
|
2022-10-04 18:02:31 +02:00
|
|
|
unique_ptr<TdCallback> callback_;
|
|
|
|
Options options_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2020-11-15 15:38:10 +01:00
|
|
|
/**
|
|
|
|
* Creates NetQueryStats object, which can be shared between different clients.
|
|
|
|
*/
|
2020-07-30 16:28:56 +02:00
|
|
|
std::shared_ptr<NetQueryStats> create_net_query_stats();
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
/**
|
|
|
|
* Dumps information about all pending network queries to the internal TDLib log.
|
|
|
|
* This is useful for library debugging.
|
|
|
|
*/
|
2020-07-30 16:28:56 +02:00
|
|
|
void dump_pending_network_queries(NetQueryStats &stats);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current number of pending network queries. Useful for library debugging.
|
|
|
|
* \return Number of currently pending network queries.
|
|
|
|
*/
|
2020-07-30 16:28:56 +02:00
|
|
|
uint64 get_pending_network_query_count(NetQueryStats &stats);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
} // namespace td
|