home/src/remote.hh
Maxime Coste 4fc20b8d7d Rework client quitting and handling of remote errors
Client quitting no longer immediately unwinds, client is just pushed
for deletion until we get back to the main loop, similarly to what
happens for buffer and window deletion.
2016-09-04 17:56:07 +01:00

71 lines
1.5 KiB
C++

#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 remote_error : runtime_error
{
remote_error(String error)
: runtime_error{std::move(error)}
{}
};
struct connection_failed : runtime_error
{
connection_failed(StringView filename)
: runtime_error{format("connect to {} failed", filename)}
{}
};
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 write_next_key();
std::unique_ptr<UserInterface> m_ui;
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; }
bool rename_session(StringView name);
void close_session(bool do_unlink = true);
private:
class Accepter;
void remove_accepter(Accepter* accepter);
String m_session;
std::unique_ptr<FDWatcher> m_listener;
Vector<std::unique_ptr<Accepter>> m_accepters;
};
bool check_session(StringView session);
}
#endif // remote_hh_INCLUDED