Client.h
Go to the documentation of this file.
1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
10 
11 #include "td/telegram/td_api.h"
12 #include "td/telegram/td_api.hpp"
13 
14 #include <cstdint>
15 #include <memory>
16 
17 namespace td {
18 
55 class ClientManager final {
56  public:
60  ClientManager();
61 
65  using ClientId = std::int32_t;
66 
72  using RequestId = std::uint64_t;
73 
80 
87  void send(ClientId client_id, RequestId request_id, td_api::object_ptr<td_api::Function> &&request);
88 
92  struct Response {
97 
102 
107  };
108 
116  Response receive(double timeout);
117 
125 
134  using LogMessageCallbackPtr = void (*)(int verbosity_level, const char *message);
135 
145  static void set_log_message_callback(int max_verbosity_level, LogMessageCallbackPtr callback);
146 
150  ~ClientManager();
151 
155  ClientManager(ClientManager &&other) noexcept;
156 
160  ClientManager &operator=(ClientManager &&other) noexcept;
161 
167 
168  private:
169  friend class Client;
170  class Impl;
171  std::unique_ptr<Impl> impl_;
172 };
173 
207 class Client final {
208  public:
212  Client();
213 
217  struct Request {
223  std::uint64_t id;
224 
229  };
230 
235  void send(Request &&request);
236 
240  struct Response {
244  std::uint64_t id;
245 
250  };
251 
259  Response receive(double timeout);
260 
267  static Response execute(Request &&request);
268 
272  ~Client();
273 
277  Client(Client &&other) noexcept;
278 
282  Client &operator=(Client &&other) noexcept;
283 
284  private:
285  class Impl;
286  std::unique_ptr<Impl> impl_;
287 };
288 
289 } // namespace td
static Response execute(Request &&request)
void send(ClientId client_id, RequestId request_id, td_api::object_ptr< td_api::Function > &&request)
static ClientManager * get_manager_singleton()
RequestId request_id
Definition: Client.h:101
Definition: Client.h:240
Response receive(double timeout)
std::int32_t ClientId
Definition: Client.h:65
td_api::object_ptr< td_api::Object > object
Definition: Client.h:249
ClientId client_id
Definition: Client.h:96
::td::tl_object_ptr< Type > object_ptr
Definition: td_api.h:58
void(*)(int verbosity_level, const char *message) LogMessageCallbackPtr
Definition: Client.h:134
Client & operator=(Client &&other) noexcept
td_api::object_ptr< td_api::Object > object
Definition: Client.h:106
Definition: Client.h:92
void send(Request &&request)
ClientManager & operator=(ClientManager &&other) noexcept
static void set_log_message_callback(int max_verbosity_level, LogMessageCallbackPtr callback)
std::uint64_t RequestId
Definition: Client.h:72
ClientId create_client_id()
Definition: Client.h:207
std::uint64_t id
Definition: Client.h:223
Response receive(double timeout)
Definition: Client.h:217
Definition: Client.h:55
std::uint64_t id
Definition: Client.h:244
static td_api::object_ptr< td_api::Object > execute(td_api::object_ptr< td_api::Function > &&request)