List of all members | Classes | Public Class Methods | Public Instance Methods
Client Class Referencefinal

Description

Native C++ interface for interaction with TDLib.

The TDLib instance is created for the lifetime of the Client object. Requests to TDLib can be sent using the Client::send method from any thread. New updates and responses to requests can be received using the Client::receive method from any thread, this function shouldn't be called simultaneously from two different threads. Also note that all updates and responses to requests should be applied in the same order as they were received, to ensure consistency. Given this information, it's advisable to call this function from a dedicated thread. Some service TDLib requests can be executed synchronously from any thread by using the Client::execute method.

General pattern of usage:

std::shared_ptr<td::Client> client = std::make_shared<td::Client>();
// somehow share the client with other threads, which will be able to send requests via client->send
const double WAIT_TIMEOUT = 10.0; // seconds
bool is_closed = false; // should be set to true, when updateAuthorizationState with
// authorizationStateClosed is received
while (!is_closed) {
auto response = client->receive(WAIT_TIMEOUT);
if (response.object == nullptr) {
continue;
}
if (response.id == 0) {
// process response.object as an incoming update of type td_api::Update
} else {
// process response.object as an answer to a sent request with id response.id
}
}

Classes

struct  Request
 
struct  Response
 

Public Class Methods

static Response execute (Request &&request)
 

Public Instance Methods

 Client ()
 
void send (Request &&request)
 
Response receive (double timeout)
 
 ~Client ()
 
 Client (Client &&other)
 
Clientoperator= (Client &&other)
 

Constructor & Destructor Documentation

◆ Client() [1/2]

Client ( )

Creates a new TDLib client.

◆ ~Client()

~Client ( )

Destroys the client and TDLib instance.

◆ Client() [2/2]

Client ( Client &&  other)

Move constructor.

Method Documentation

◆ send()

void send ( Request &&  request)

Sends request to TDLib. May be called from any thread.

Parameters
[in]requestRequest to TDLib.

◆ receive()

Response receive ( double  timeout)

Receives incoming updates and request responses from TDLib. May be called from any thread, but shouldn't be called simultaneously from two different threads.

Parameters
[in]timeoutMaximum number of seconds allowed for this function to wait for new data.
Returns
An incoming update or request response. The object returned in the response may be a nullptr if the timeout expires.

◆ execute()

static Response execute ( Request &&  request)
static

Synchronously executes TDLib requests. Only a few requests can be executed synchronously. May be called from any thread.

Parameters
[in]requestRequest to the TDLib.
Returns
The request response.

◆ operator=()

Client& operator= ( Client &&  other)

Move assignment operator.


The documentation for this class was generated from the following file: