2012-10-23 22:55:44 +02:00
|
|
|
#ifndef remote_hh_INCLUDED
|
|
|
|
#define remote_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "display_buffer.hh"
|
2013-01-10 18:54:40 +01:00
|
|
|
#include "event_manager.hh"
|
2013-04-09 20:05:40 +02:00
|
|
|
#include "user_interface.hh"
|
2014-04-07 22:25:44 +02:00
|
|
|
#include "env_vars.hh"
|
2012-10-23 22:55:44 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-10-30 14:00:44 +01:00
|
|
|
struct peer_disconnected {};
|
2012-10-26 13:45:32 +02:00
|
|
|
|
2014-03-21 14:42:37 +01:00
|
|
|
struct connection_failed : runtime_error
|
|
|
|
{
|
2014-10-20 20:18:38 +02:00
|
|
|
connection_failed(StringView filename)
|
2014-03-21 14:42:37 +01:00
|
|
|
: runtime_error{"connect to " + filename + " failed"}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2013-03-12 18:53:18 +01:00
|
|
|
// A remote client handle communication between a client running on the server
|
|
|
|
// and a user interface running on the local process.
|
2012-10-23 22:55:44 +02:00
|
|
|
class RemoteClient
|
|
|
|
{
|
|
|
|
public:
|
2013-03-13 19:59:39 +01:00
|
|
|
RemoteClient(int socket, std::unique_ptr<UserInterface>&& ui,
|
2014-10-20 20:18:38 +02:00
|
|
|
const EnvVarMap& env_vars, StringView init_command);
|
2012-10-23 22:55:44 +02:00
|
|
|
|
2013-03-13 19:59:39 +01:00
|
|
|
private:
|
2014-04-15 20:08:47 +02:00
|
|
|
void process_available_messages();
|
2012-10-23 22:55:44 +02:00
|
|
|
void process_next_message();
|
|
|
|
void write_next_key();
|
|
|
|
|
|
|
|
std::unique_ptr<UserInterface> m_ui;
|
2014-05-07 20:51:01 +02:00
|
|
|
CharCoord m_dimensions;
|
2013-01-11 18:44:02 +01:00
|
|
|
FDWatcher m_socket_watcher;
|
2012-10-23 22:55:44 +02:00
|
|
|
};
|
2014-10-20 20:18:38 +02:00
|
|
|
std::unique_ptr<RemoteClient> connect_to(StringView session,
|
2013-03-13 19:59:39 +01:00
|
|
|
std::unique_ptr<UserInterface>&& ui,
|
2014-04-07 22:25:44 +02:00
|
|
|
const EnvVarMap& env_vars,
|
2014-10-20 20:18:38 +02:00
|
|
|
StringView init_command);
|
2013-03-13 19:59:39 +01:00
|
|
|
|
2014-10-20 20:18:38 +02:00
|
|
|
void send_command(StringView session, StringView command);
|
2014-03-02 03:01:09 +01:00
|
|
|
|
2013-03-13 19:59:39 +01:00
|
|
|
struct Server : public Singleton<Server>
|
|
|
|
{
|
2013-09-25 20:04:52 +02:00
|
|
|
Server(String session_name);
|
2013-03-13 19:59:39 +01:00
|
|
|
~Server();
|
2013-09-25 20:04:52 +02:00
|
|
|
const String& session() const { return m_session; }
|
2013-03-13 19:59:39 +01:00
|
|
|
|
2014-01-27 20:53:17 +01:00
|
|
|
void close_session();
|
|
|
|
|
2013-03-13 19:59:39 +01:00
|
|
|
private:
|
2014-03-25 10:21:20 +01:00
|
|
|
class Accepter;
|
|
|
|
void remove_accepter(Accepter* accepter);
|
|
|
|
|
2013-09-25 20:04:52 +02:00
|
|
|
String m_session;
|
2013-03-13 19:59:39 +01:00
|
|
|
std::unique_ptr<FDWatcher> m_listener;
|
2014-03-25 10:21:20 +01:00
|
|
|
std::vector<std::unique_ptr<Accepter>> m_accepters;
|
2013-03-13 19:59:39 +01:00
|
|
|
};
|
2012-10-23 22:55:44 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // remote_hh_INCLUDED
|
|
|
|
|