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