2012-10-23 22:55:44 +02:00
|
|
|
#ifndef remote_hh_INCLUDED
|
|
|
|
#define remote_hh_INCLUDED
|
|
|
|
|
2014-04-07 22:25:44 +02:00
|
|
|
#include "env_vars.hh"
|
2014-11-12 22:27:07 +01:00
|
|
|
#include "exception.hh"
|
|
|
|
#include "utils.hh"
|
2016-12-01 21:11:09 +01:00
|
|
|
#include "vector.hh"
|
2014-11-12 22:27:07 +01:00
|
|
|
|
|
|
|
#include <memory>
|
2012-10-23 22:55:44 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2016-12-20 11:34:48 +01:00
|
|
|
struct disconnected : runtime_error
|
2016-09-04 18:54:07 +02:00
|
|
|
{
|
2016-12-20 11:34:48 +01:00
|
|
|
disconnected(String what, bool graceful = false)
|
|
|
|
: runtime_error{std::move(what)}, m_graceful{graceful} {}
|
|
|
|
|
|
|
|
const bool m_graceful;
|
2016-09-04 18:54:07 +02:00
|
|
|
};
|
2012-10-26 13:45:32 +02:00
|
|
|
|
2014-11-05 14:57:12 +01:00
|
|
|
class FDWatcher;
|
2016-11-29 20:53:11 +01:00
|
|
|
class UserInterface;
|
2016-12-01 21:11:09 +01:00
|
|
|
|
2017-01-21 13:14:44 +01:00
|
|
|
template<typename T> struct Optional;
|
|
|
|
struct BufferCoord;
|
|
|
|
|
2016-12-01 21:11:09 +01:00
|
|
|
using RemoteBuffer = Vector<char, MemoryDomain::Remote>;
|
2014-11-05 14:57:12 +01:00
|
|
|
|
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:
|
2014-11-05 14:57:12 +01:00
|
|
|
RemoteClient(StringView session, std::unique_ptr<UserInterface>&& ui,
|
2017-01-21 13:14:44 +01:00
|
|
|
const EnvVarMap& env_vars, StringView init_command,
|
|
|
|
Optional<BufferCoord> init_coord);
|
2012-10-23 22:55:44 +02:00
|
|
|
|
2013-03-13 19:59:39 +01:00
|
|
|
private:
|
2012-10-23 22:55:44 +02:00
|
|
|
std::unique_ptr<UserInterface> m_ui;
|
2014-11-05 14:57:12 +01:00
|
|
|
std::unique_ptr<FDWatcher> m_socket_watcher;
|
2016-12-01 21:11:09 +01:00
|
|
|
RemoteBuffer m_send_buffer;
|
2012-10-23 22:55:44 +02:00
|
|
|
};
|
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
|
|
|
|
2016-07-28 01:16:41 +02:00
|
|
|
bool rename_session(StringView name);
|
2015-10-08 21:05:47 +02:00
|
|
|
void close_session(bool do_unlink = true);
|
2014-01-27 20:53:17 +01:00
|
|
|
|
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;
|
2016-11-28 14:59:55 +01:00
|
|
|
Vector<std::unique_ptr<Accepter>, MemoryDomain::Remote> m_accepters;
|
2013-03-13 19:59:39 +01:00
|
|
|
};
|
2012-10-23 22:55:44 +02:00
|
|
|
|
2016-06-06 20:28:56 +02:00
|
|
|
bool check_session(StringView session);
|
|
|
|
|
2012-10-23 22:55:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // remote_hh_INCLUDED
|