2
0
mirror of https://github.com/ars3niy/tdlib-purple synced 2025-08-22 09:57:52 +00:00
tdlib-purple/td-client.h

47 lines
1.3 KiB
C
Raw Normal View History

#ifndef _TD_CLIENT_H
#define _TD_CLIENT_H
2020-02-22 11:42:04 +01:00
#include <purple.h>
#include <td/telegram/Client.h>
#include <td/telegram/td_api.h>
#include <td/telegram/td_api.hpp>
#include <memory>
#include <thread>
#include <atomic>
2020-02-22 11:42:04 +01:00
#include <map>
class UpdateHandler;
class AuthUpdateHandler;
class PurpleTdClient {
public:
2020-02-22 11:42:04 +01:00
PurpleTdClient(PurpleAccount *acct);
~PurpleTdClient();
static void setLogLevel(int level);
void startLogin();
private:
friend class UpdateHandler;
friend class AuthUpdateHandler;
using TdObjectPtr = td::td_api::object_ptr<td::td_api::Object>;
2020-02-22 11:42:04 +01:00
using ResponseCb = std::function<void(uint64_t requestId, TdObjectPtr object)>;
void pollThreadLoop();
void processResponse(td::Client::Response response);
void sendTdlibParameters();
void sendPhoneNumber();
2020-02-22 11:42:04 +01:00
void sendQuery(td::td_api::object_ptr<td::td_api::Function> f, ResponseCb handler);
PurpleAccount *m_account;
std::unique_ptr<UpdateHandler> m_updateHandler;
std::unique_ptr<AuthUpdateHandler> m_authUpdateHandler;
std::unique_ptr<td::Client> m_client;
std::thread m_pollThread;
std::atomic_bool m_stopThread;
uint64_t m_lastQueryId;
std::map<std::uint64_t, ResponseCb> m_responseHandlers;
};
#endif