tdlight/td/telegram/td_c_client.cpp

75 lines
2.2 KiB
C++
Raw Normal View History

//
2021-01-01 13:57:46 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// 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)
//
#include "td/telegram/td_c_client.h"
#include "td/telegram/Client.h"
#include "td/telegram/Log.h"
#include "td/telegram/td_tdc_api_inner.h"
#include <cstring>
2021-09-26 21:17:02 +02:00
static td::ClientManager *GetClientManager() {
return td::ClientManager::get_manager_singleton();
}
2021-09-26 21:17:02 +02:00
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);
}
2021-09-26 21:17:02 +02:00
TdResponse TdCClientReceive(double timeout) {
auto response = GetClientManager()->receive(timeout);
TdResponse c_response;
2021-09-26 21:17:02 +02:00
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;
}
2021-09-26 21:17:02 +02:00
TdObject *TdCClientExecute(TdFunction *function) {
auto result = td::ClientManager::execute(TdConvertToInternal(function));
TdDestroyObjectFunction(function);
return TdConvertFromInternal(*result);
}
TdVectorInt *TdCreateObjectVectorInt(int size, int *data) {
auto res = new TdVectorInt();
res->len = size;
res->data = new int[size];
std::memcpy(res->data, data, sizeof(int) * size);
return res;
}
TdVectorLong *TdCreateObjectVectorLong(int size, long long *data) {
auto res = new TdVectorLong();
res->len = size;
res->data = new long long[size];
std::memcpy(res->data, data, sizeof(long long) * size);
return res;
}
TdVectorObject *TdCreateObjectVectorObject(int size, TdObject **data) {
auto res = new TdVectorObject();
res->len = size;
res->data = new TdObject *[size];
std::memcpy(res->data, data, sizeof(TdObject *) * size);
return res;
}
TdBytes TdCreateObjectBytes(unsigned char *data, int len) {
TdBytes res;
res.len = len;
res.data = new unsigned char[len];
std::memcpy(res.data, data, len);
return res;
}