remote_client.hpp 2.1 KB
Newer Older
1
2
3
4
5
/** @addtogroup Network
 *  @{
 */

/**
6
7
 * Represents one single remote client connected to the main server (the one
 * doing authentication, history, chat, etc).
8
9
10
 * @class RemoteClient
 */

louiz’'s avatar
louiz’ committed
11
12
#ifndef __REMOTE_CLIENT_HPP__
# define __REMOTE_CLIENT_HPP__
louiz’'s avatar
louiz’ committed
13

14
15
#include <boost/asio.hpp>
#include <functional>
16
#include "batadb.hpp"
17

18
#include <network/remote_client_base.hpp>
19
20
21
22

class MasterServer;
class Message;
class TransferSender;
23

24
class RemoteClient: public RemoteClientBase
louiz’'s avatar
louiz’ committed
25
26
{
public:
27
  RemoteClient();
louiz’'s avatar
louiz’ committed
28
  ~RemoteClient();
29
30
  void on_connection_closed() override final;
  void set_server(MasterServer* server);
31
32
33
34
35
36

  /**
   * Sends a file to the remote client.
   * @param filename The file to send.
   */
  void send_file(const std::string&);
37
38
39
40
41
42
43
  /**
   * Sends a ping request to the remote client.
   */
  void send_ping();
  /**
   * Called when we receive the response to our ping.
   */
44
  void on_pong(Message*);
45
46
47
48
49
  /**
   * To be called whenever a file transfer ends.
   * Removes the TransferSender from the list.
   * @param transfer The TransferSender to remove from the list.
   */
louiz’'s avatar
louiz’ committed
50
  void on_transfer_ended(const TransferSender*);
51
52
53
54
55
  /**
   * Called when the client is successfully authenticated.
   * For example, checks if there are news to send, or offline messages, etc
   */
  void on_auth_success();
56
  const db::User* get_user() const;
57

louiz’'s avatar
louiz’ committed
58
private:
59
60
61
62
63
64
65
  /**
   * Keep track of which user is associated with this client. Used to get
   * various other information from the database (the contact list, account
   * informations, etc).
   * If it's nullptr, the user did not successfully log in (yet)
   */
  std::unique_ptr<db::User> user;
66
  /**
67
68
69
   * Creates the default callbacks associated with a network message.
   * It is executed whenever that message is received.
   * See MessageHandler for details
70
   */
71
  virtual void install_callbacks();
72
73
  void auth_callback(Message*);
  void transfer_callback(Message*);
74
  void on_user_logged_in();
75
  /**
76
   * A pointer to the server owning use
77
   */
78
  MasterServer* server;
79
  /**
80
   * A list of all the current file transfers with the client.
81
82
   */
  std::vector<TransferSender*> senders;
louiz’'s avatar
louiz’ committed
83
84
85
};

#endif
86
/**@}*/