summaryrefslogtreecommitdiff
path: root/src/remote.hh
blob: 0d85cf81d0e21bd6ec30d226403a3d03da643e38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef remote_hh_INCLUDED
#define remote_hh_INCLUDED

#include "coord.hh"
#include "env_vars.hh"
#include "exception.hh"
#include "user_interface.hh"
#include "utils.hh"

#include <memory>

namespace Kakoune
{

struct peer_disconnected {};

struct connection_failed : runtime_error
{
    connection_failed(StringView filename)
        : runtime_error{"connect to " + filename + " failed"}
    {}
};

class FDWatcher;

// A remote client handle communication between a client running on the server
// and a user interface running on the local process.
class RemoteClient
{
public:
    RemoteClient(StringView session, std::unique_ptr<UserInterface>&& ui,
                 const EnvVarMap& env_vars, StringView init_command);

private:
    void process_available_messages();
    void process_next_message();
    void write_next_key();

    std::unique_ptr<UserInterface> m_ui;
    CharCoord                      m_dimensions;
    std::unique_ptr<FDWatcher>     m_socket_watcher;
};

void send_command(StringView session, StringView command);

struct Server : public Singleton<Server>
{
    Server(String session_name);
    ~Server();
    const String& session() const { return m_session; }

    void close_session();

private:
    class Accepter;
    void remove_accepter(Accepter* accepter);

    String m_session;
    std::unique_ptr<FDWatcher> m_listener;
    std::vector<std::unique_ptr<Accepter>> m_accepters;
};

}

#endif // remote_hh_INCLUDED