2
0
mirror of https://github.com/ars3niy/tdlib-purple synced 2025-08-31 05:55:08 +00:00
Files
tdlib-purple/td-client.h

64 lines
2.2 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>
2020-02-22 14:58:32 +01:00
#include <mutex>
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;
2020-02-22 14:58:32 +01:00
using TdObjectPtr = td::td_api::object_ptr<td::td_api::Object>;
using ResponseCb = void (PurpleTdClient::*)(uint64_t requestId, TdObjectPtr object);
using TdErrorPtr = td::td_api::object_ptr<td::td_api::error>;
using TdAuthCodePtr = td::td_api::object_ptr<td::td_api::authenticationCodeInfo>;
// All non-static member functions below are called from the poll thread
void pollThreadLoop();
void processResponse(td::Client::Response response);
void sendTdlibParameters();
void sendPhoneNumber();
2020-02-22 14:58:32 +01:00
static int requestAuthCode(gpointer user_data);
static void requestCodeEntered(PurpleTdClient *self, const gchar *code);
static void requestCodeCancelled(PurpleTdClient *self);
2020-02-22 11:42:04 +01:00
void sendQuery(td::td_api::object_ptr<td::td_api::Function> f, ResponseCb handler);
void authResponse(uint64_t requestId, td::td_api::object_ptr<td::td_api::Object> object);
2020-02-22 13:23:01 +01:00
static int notifyAuthError(gpointer user_data);
void connectionReady();
static int setPurpleConnectionReady(gpointer user_data);
2020-02-22 13:23:01 +01:00
2020-02-22 11:42:04 +01:00
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;
2020-02-22 14:58:32 +01:00
std::atomic<uint64_t> m_lastQueryId;
2020-02-22 11:42:04 +01:00
std::map<std::uint64_t, ResponseCb> m_responseHandlers;
2020-02-22 14:58:32 +01:00
std::mutex m_dataMutex;
2020-02-22 13:23:01 +01:00
2020-02-22 14:58:32 +01:00
int32_t m_lastAuthState = 0;
TdErrorPtr m_authError;
TdAuthCodePtr m_authCodeInfo;
};
#endif