Rename create_client to create_client_id.
This commit is contained in:
parent
21f6ddc6fb
commit
5eea5b7501
@ -161,7 +161,7 @@ int main(int argc, char **argv) {
|
||||
SET_VERBOSITY_LEVEL(new_verbosity_level);
|
||||
|
||||
td::ClientManager client_manager;
|
||||
auto client_id = client_manager.create_client();
|
||||
auto client_id = client_manager.create_client_id();
|
||||
for (size_t i = 0; i < requests.size(); i++) {
|
||||
auto &request = requests[i].second;
|
||||
request->dc_id_ = dc_id;
|
||||
|
@ -55,7 +55,7 @@ class TdExample {
|
||||
TdExample() {
|
||||
td::ClientManager::execute(td_api::make_object<td_api::setLogVerbosityLevel>(1));
|
||||
client_manager_ = std::make_unique<td::ClientManager>();
|
||||
client_id_ = client_manager_->create_client();
|
||||
client_id_ = client_manager_->create_client_id();
|
||||
send_query(td_api::make_object<td_api::getOption>("version"), {});
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ int main() {
|
||||
// disable TDLib logging
|
||||
td_execute("{\"@type\":\"setLogVerbosityLevel\", \"new_verbosity_level\":0}");
|
||||
|
||||
int client_id = td_create_client();
|
||||
int client_id = td_create_client_id();
|
||||
// somehow share the client_id with other threads, which will be able to send requests via td_send
|
||||
|
||||
// start the client by sending request to it
|
||||
|
@ -31,7 +31,7 @@ static td::ClientManager *get_manager() {
|
||||
}
|
||||
|
||||
static jint Client_createNativeClient(JNIEnv *env, jclass clazz) {
|
||||
return static_cast<jint>(get_manager()->create_client());
|
||||
return static_cast<jint>(get_manager()->create_client_id());
|
||||
}
|
||||
|
||||
static void Client_nativeClientSend(JNIEnv *env, jclass clazz, jint client_id, jlong id, jobject function) {
|
||||
|
@ -18,9 +18,9 @@ if tdjson_path is None:
|
||||
tdjson = CDLL(tdjson_path)
|
||||
|
||||
# load TDLib functions from shared library
|
||||
_td_create_client = tdjson.td_create_client
|
||||
_td_create_client.restype = c_int
|
||||
_td_create_client.argtypes = []
|
||||
_td_create_client_id = tdjson.td_create_client_id
|
||||
_td_create_client_id.restype = c_int
|
||||
_td_create_client_id.argtypes = []
|
||||
|
||||
_td_receive = tdjson.td_receive
|
||||
_td_receive.restype = c_char_p
|
||||
@ -60,7 +60,7 @@ print(str(td_execute({'@type': 'setLogVerbosityLevel', 'new_verbosity_level': 1,
|
||||
|
||||
|
||||
# create client
|
||||
client_id = _td_create_client()
|
||||
client_id = _td_create_client_id()
|
||||
|
||||
# simple wrappers for client usage
|
||||
def td_send(query):
|
||||
|
@ -9,7 +9,7 @@ import Foundation
|
||||
|
||||
// TDLib Client Swift binding
|
||||
class TdClient {
|
||||
var client_id = td_create_client()!
|
||||
var client_id = td_create_client_id()!
|
||||
let tdlibMainLoop = DispatchQueue(label: "TDLib")
|
||||
let tdlibQueryQueue = DispatchQueue(label: "TDLibQuery")
|
||||
var queryF = Dictionary<Int64, (Dictionary<String,Any>)->()>()
|
||||
|
@ -614,7 +614,7 @@ class TdClient {
|
||||
this.TdModule = await loadTdlib(mode, this.onFS, options.wasmUrl);
|
||||
log.info('got TdModule');
|
||||
this.td_functions = {
|
||||
td_create: this.TdModule.cwrap('td_emscripten_create', 'number', []),
|
||||
td_create: this.TdModule.cwrap('td_emscripten_create_client_id', 'number', []),
|
||||
td_send: this.TdModule.cwrap('td_emscripten_send', null, [
|
||||
'number',
|
||||
'string'
|
||||
@ -679,7 +679,7 @@ class TdClient {
|
||||
options.logVerbosityLevel = 2;
|
||||
}
|
||||
this.td_functions.td_set_verbosity(options.logVerbosityLevel);
|
||||
this.client = this.td_functions.td_create();
|
||||
this.client_id = this.td_functions.td_create();
|
||||
|
||||
this.savingFiles = new Map();
|
||||
this.send({
|
||||
@ -842,7 +842,7 @@ class TdClient {
|
||||
return;
|
||||
}
|
||||
query = this.prepareQuery(query);
|
||||
this.td_functions.td_send(this.client, JSON.stringify(query));
|
||||
this.td_functions.td_send(this.client_id, JSON.stringify(query));
|
||||
this.scheduleReceiveSoon();
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ class TdReceiver {
|
||||
|
||||
class ClientManager::Impl final {
|
||||
public:
|
||||
ClientId create_client() {
|
||||
ClientId create_client_id() {
|
||||
CHECK(client_id_ != std::numeric_limits<ClientId>::max());
|
||||
auto client_id = ++client_id_;
|
||||
pending_clients_.insert(client_id);
|
||||
@ -205,7 +205,7 @@ class ClientManager::Impl final {
|
||||
|
||||
class Client::Impl final {
|
||||
public:
|
||||
Impl() : client_id_(impl_.create_client()) {
|
||||
Impl() : client_id_(impl_.create_client_id()) {
|
||||
}
|
||||
|
||||
void send(Request request) {
|
||||
@ -455,7 +455,7 @@ class MultiImplPool {
|
||||
|
||||
class ClientManager::Impl final {
|
||||
public:
|
||||
ClientId create_client() {
|
||||
ClientId create_client_id() {
|
||||
auto client_id = MultiImpl::create_id();
|
||||
{
|
||||
auto lock = impls_mutex_.lock_write().move_as_ok();
|
||||
@ -639,8 +639,8 @@ Client &Client::operator=(Client &&other) = default;
|
||||
ClientManager::ClientManager() : impl_(std::make_unique<Impl>()) {
|
||||
}
|
||||
|
||||
ClientManager::ClientId ClientManager::create_client() {
|
||||
return impl_->create_client();
|
||||
ClientManager::ClientId ClientManager::create_client_id() {
|
||||
return impl_->create_client_id();
|
||||
}
|
||||
|
||||
void ClientManager::send(ClientId client_id, RequestId request_id, td_api::object_ptr<td_api::Function> &&request) {
|
||||
|
@ -134,20 +134,24 @@ class Client final {
|
||||
/**
|
||||
* The future native C++ interface for interaction with TDLib.
|
||||
*
|
||||
* The TDLib client instance is created using the ClientManager::create_client method, returning a client identifier.
|
||||
* Requests to TDLib can be sent using the ClientManager::send method from any thread.
|
||||
* New updates and responses to requests can be received using the ClientManager::receive method from any thread,
|
||||
* this function must not 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.
|
||||
* The TDLib client instance is created using the ClientManager::create_client_id method, returning a client identifier.
|
||||
* Requests to a TDLib client instance can be sent using the ClientManager::send method from any thread.
|
||||
* New updates and responses to requests can be received using the ClientManager::receive method from any thread
|
||||
* after a first request is sent to the client instance. ClientManager::receive must not 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.
|
||||
* Some TDLib requests can be executed synchronously from any thread by using the ClientManager::execute method.
|
||||
*
|
||||
* General pattern of usage:
|
||||
* \code
|
||||
* td::ClientManager manager;
|
||||
* auto client_id = manager.create_client();
|
||||
* auto client_id = manager.create_client_id();
|
||||
* // somehow share the manager and the client_id with other threads,
|
||||
* // which will be able to send requests via manager.send(client_id, ...)
|
||||
*
|
||||
* // send some dummy requests to the new instance to activate it
|
||||
* manager.send(client_id, ...);
|
||||
*
|
||||
* const double WAIT_TIMEOUT = 10.0; // seconds
|
||||
* while (true) {
|
||||
* auto response = manager.receive(WAIT_TIMEOUT);
|
||||
@ -183,10 +187,11 @@ class ClientManager final {
|
||||
using RequestId = std::uint64_t;
|
||||
|
||||
/**
|
||||
* Creates a new TDLib client and returns its opaque identifier.
|
||||
* The client will not send updates until the first request is sent to it.
|
||||
* Returns an opaque identifier of a new TDLib instance.
|
||||
* The TDLib instance will not send updates until the first request is sent to it.
|
||||
* \return Opaque indentifier of a new TDLib instance.
|
||||
*/
|
||||
ClientId create_client();
|
||||
ClientId create_client_id();
|
||||
|
||||
/**
|
||||
* Sends request to TDLib. May be called from any thread.
|
||||
|
@ -125,8 +125,8 @@ static std::mutex extra_mutex;
|
||||
static std::unordered_map<int64, string> extra;
|
||||
static std::atomic<uint64> extra_id{1};
|
||||
|
||||
int json_create_client() {
|
||||
return static_cast<int>(get_manager()->create_client());
|
||||
int json_create_client_id() {
|
||||
return static_cast<int>(get_manager()->create_client_id());
|
||||
}
|
||||
|
||||
void json_send(int client_id, Slice request) {
|
||||
|
@ -33,7 +33,7 @@ class ClientJson final {
|
||||
std::atomic<std::uint64_t> extra_id_{1};
|
||||
};
|
||||
|
||||
int json_create_client();
|
||||
int json_create_client_id();
|
||||
|
||||
void json_send(int client_id, Slice request);
|
||||
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double td_emscripten_create() {
|
||||
return td_create_client();
|
||||
EMSCRIPTEN_KEEPALIVE double td_emscripten_create_client_id() {
|
||||
return td_create_client_id();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void td_emscripten_send(double client_id, const char *query) {
|
||||
|
@ -30,8 +30,8 @@ const char *td_json_client_execute(void *client, const char *request) {
|
||||
return td::ClientJson::execute(td::Slice(request == nullptr ? "" : request));
|
||||
}
|
||||
|
||||
int td_create_client() {
|
||||
return td::json_create_client();
|
||||
int td_create_client_id() {
|
||||
return td::json_create_client_id();
|
||||
}
|
||||
|
||||
void td_send(int client_id, const char *request) {
|
||||
|
@ -102,7 +102,7 @@ TDJSON_EXPORT void td_json_client_destroy(void *client);
|
||||
* Each returned object will have an "@client_id" field, containing and identifier of the client for which
|
||||
* a response or an update is received.
|
||||
*
|
||||
* A TDLib client instance can be created through td_create_client.
|
||||
* A TDLib client instance can be created through td_create_client_id.
|
||||
* Requests then can be sent using td_send from any thread and the received client identifier.
|
||||
* New updates and request responses can be received through td_receive from any thread. This function
|
||||
* must not be called simultaneously from two different threads. Also note that all updates and request responses
|
||||
@ -112,7 +112,7 @@ TDJSON_EXPORT void td_json_client_destroy(void *client);
|
||||
*
|
||||
* General pattern of usage:
|
||||
* \code
|
||||
* int client_id = td_create_client();
|
||||
* int client_id = td_create_client_id();
|
||||
* // share the client_id with other threads, which will be able to send requests via td_send
|
||||
*
|
||||
* const double WAIT_TIMEOUT = 10.0; // seconds
|
||||
@ -126,10 +126,11 @@ TDJSON_EXPORT void td_json_client_destroy(void *client);
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new instance of TDLib. The TDLib instance will not send updates until the first request is sent to it.
|
||||
* \return Opaque indentifier of the created TDLib instance.
|
||||
* Returns an opaque identifier of a new TDLib instance.
|
||||
* The TDLib instance will not send updates until the first request is sent to it.
|
||||
* \return Opaque indentifier of a new TDLib instance.
|
||||
*/
|
||||
TDJSON_EXPORT int td_create_client();
|
||||
TDJSON_EXPORT int td_create_client_id();
|
||||
|
||||
/**
|
||||
* Sends request to the TDLib client. May be called from any thread.
|
||||
|
@ -7,7 +7,7 @@ _td_set_log_file_path
|
||||
_td_set_log_max_file_size
|
||||
_td_set_log_verbosity_level
|
||||
_td_set_log_fatal_error_callback
|
||||
_td_create_client
|
||||
_td_create_client_id
|
||||
_td_send
|
||||
_td_receive
|
||||
_td_execute
|
||||
|
@ -942,7 +942,7 @@ TEST(Client, Manager) {
|
||||
for (int i = 0; i < threads_n; i++) {
|
||||
threads.emplace_back([&] {
|
||||
for (int i = 0; i <= clients_n; i++) {
|
||||
auto id = client.create_client();
|
||||
auto id = client.create_client_id();
|
||||
if (i != 0) {
|
||||
client.send(id, 3, td::make_tl_object<td::td_api::testSquareInt>(3));
|
||||
}
|
||||
@ -1036,7 +1036,7 @@ TEST(Client, ManagerClose) {
|
||||
std::atomic<td::int64> send_count{1};
|
||||
std::atomic<td::int64> receive_count{0};
|
||||
td::ClientManager client_manager;
|
||||
auto client_id = client_manager.create_client();
|
||||
auto client_id = client_manager.create_client_id();
|
||||
|
||||
std::mutex request_ids_mutex;
|
||||
std::set<td::uint64> request_ids;
|
||||
@ -1141,7 +1141,7 @@ TEST(Client, ManagerCloseOneThread) {
|
||||
|
||||
receive();
|
||||
|
||||
auto client_id = client_manager.create_client();
|
||||
auto client_id = client_manager.create_client_id();
|
||||
|
||||
for (td::int32 i = -5; i < 5; i++) {
|
||||
send_request(i, i == client_id ? 0 : (i > 0 && i < client_id ? 500 : 400));
|
||||
|
Loading…
Reference in New Issue
Block a user