Use ClientManager in td_c_client.
This commit is contained in:
parent
493a9e5457
commit
a04423ad66
@ -25,7 +25,7 @@ class Td;
|
||||
|
||||
/**
|
||||
* This is a low-level Actor interface for interaction with TDLib. The interface is a lot more flexible than
|
||||
* the Client interface, however, for most usages the Client interface should be sufficient.
|
||||
* the ClientManager interface, however, for most usages the ClientManager interface should be sufficient.
|
||||
*/
|
||||
class ClientActor final : public Actor {
|
||||
public:
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
// TODO can be made private in TDLib 2.0
|
||||
// TODO can be removed in TDLib 2.0
|
||||
class ClientJson final {
|
||||
public:
|
||||
void send(Slice request);
|
||||
|
@ -13,35 +13,32 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
void *TdCClientCreate() {
|
||||
return new td::Client();
|
||||
static td::ClientManager *GetClientManager() {
|
||||
return td::ClientManager::get_manager_singleton();
|
||||
}
|
||||
|
||||
void TdCClientSend(void *instance, struct TdRequest request) {
|
||||
auto client = static_cast<td::Client *>(instance);
|
||||
td::Client::Request client_request;
|
||||
client_request.id = request.id;
|
||||
client_request.function = TdConvertToInternal(request.function);
|
||||
int TdCClientCreateId() {
|
||||
return GetClientManager()->create_client_id();
|
||||
}
|
||||
|
||||
void TdCClientSend(int client_id, struct TdRequest request) {
|
||||
GetClientManager()->send(client_id, request.request_id, TdConvertToInternal(request.function));
|
||||
TdDestroyObjectFunction(request.function);
|
||||
client->send(std::move(client_request));
|
||||
}
|
||||
|
||||
TdResponse TdCClientReceive(void *instance, double timeout) {
|
||||
auto client = static_cast<td::Client *>(instance);
|
||||
auto response = client->receive(timeout);
|
||||
TdResponse TdCClientReceive(double timeout) {
|
||||
auto response = GetClientManager()->receive(timeout);
|
||||
TdResponse c_response;
|
||||
c_response.id = response.id;
|
||||
c_response.client_id = response.client_id;
|
||||
c_response.request_id = response.request_id;
|
||||
c_response.object = response.object == nullptr ? nullptr : TdConvertFromInternal(*response.object);
|
||||
return c_response;
|
||||
}
|
||||
|
||||
void TdCClientDestroy(void *instance) {
|
||||
auto client = static_cast<td::Client *>(instance);
|
||||
delete client;
|
||||
}
|
||||
|
||||
void TdCClientSetVerbosity(int new_verbosity_level) {
|
||||
td::Log::set_verbosity_level(new_verbosity_level);
|
||||
TdObject *TdCClientExecute(TdFunction *function) {
|
||||
auto result = td::ClientManager::execute(TdConvertToInternal(function));
|
||||
TdDestroyObjectFunction(function);
|
||||
return TdConvertFromInternal(*result);
|
||||
}
|
||||
|
||||
TdVectorInt *TdCreateObjectVectorInt(int size, int *data) {
|
||||
|
@ -18,21 +18,23 @@ struct TdVectorObject *TdCreateObjectVectorObject(int size, struct TdObject **da
|
||||
struct TdBytes TdCreateObjectBytes(unsigned char *data, int len);
|
||||
|
||||
struct TdRequest {
|
||||
long long id;
|
||||
long long request_id;
|
||||
TdFunction *function;
|
||||
};
|
||||
|
||||
struct TdResponse {
|
||||
long long id;
|
||||
long long request_id;
|
||||
int client_id;
|
||||
TdObject *object;
|
||||
};
|
||||
|
||||
void *TdCClientCreate();
|
||||
void TdCClientSend(void *instance, struct TdRequest cmd);
|
||||
struct TdResponse TdCClientSendCommandSync(void *instance, double timeout);
|
||||
void TdCClientDestroy(void *instance);
|
||||
int TdCClientCreateId();
|
||||
|
||||
void TdCClientSetVerbosity(int new_verbosity_level);
|
||||
void TdCClientSend(int client_id, struct TdRequest request);
|
||||
|
||||
TdResponse TdCClientReceive(double timeout);
|
||||
|
||||
TdObject *TdCClientExecute(TdFunction *function);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user