kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

remote.hh (2048B)


      1 #ifndef remote_hh_INCLUDED
      2 #define remote_hh_INCLUDED
      3 
      4 #include "env_vars.hh"
      5 #include "exception.hh"
      6 #include "utils.hh"
      7 #include "vector.hh"
      8 #include "optional.hh"
      9 #include "unique_ptr.hh"
     10 
     11 namespace Kakoune
     12 {
     13 
     14 struct disconnected : runtime_error
     15 {
     16     using runtime_error::runtime_error;
     17 };
     18 
     19 class FDWatcher;
     20 class UserInterface;
     21 
     22 template<typename T> struct Optional;
     23 struct BufferCoord;
     24 
     25 using RemoteBuffer = Vector<char, MemoryDomain::Remote>;
     26 
     27 // A remote client handle communication between a client running on the server
     28 // and a user interface running on the local process.
     29 class RemoteClient
     30 {
     31 public:
     32     RemoteClient(StringView session, StringView name, UniquePtr<UserInterface>&& ui,
     33                  int pid, const EnvVarMap& env_vars, StringView init_command,
     34                  Optional<BufferCoord> init_coord, Optional<int> stdin_fd);
     35 
     36     bool is_ui_ok() const;
     37     const Optional<int>& exit_status() const { return m_exit_status; }
     38 private:
     39     UniquePtr<UserInterface> m_ui;
     40     UniquePtr<FDWatcher>     m_socket_watcher;
     41     RemoteBuffer                   m_send_buffer;
     42     Optional<int>                  m_exit_status;
     43 };
     44 
     45 void send_command(StringView session, StringView command);
     46 String get_user_name();
     47 const String& session_directory();
     48 String session_path(StringView session, bool assume_valid = false);
     49 
     50 struct Server : public Singleton<Server>
     51 {
     52     Server(String session_name, bool daemon);
     53     ~Server();
     54     const String& session() const { return m_session; }
     55 
     56     bool rename_session(StringView name);
     57     void close_session(bool do_unlink = true);
     58 
     59     bool negotiating() const { return not m_accepters.empty(); }
     60 
     61     void daemonize() { m_is_daemon = true; }
     62     bool is_daemon() const { return m_is_daemon; }
     63 
     64 private:
     65     class Accepter;
     66     void remove_accepter(Accepter* accepter);
     67 
     68     String m_session;
     69     bool m_is_daemon;
     70     UniquePtr<FDWatcher> m_listener;
     71     Vector<UniquePtr<Accepter>, MemoryDomain::Remote> m_accepters;
     72 };
     73 
     74 bool check_session(StringView session);
     75 
     76 }
     77 
     78 #endif // remote_hh_INCLUDED