]> git.lyx.org Git - lyx.git/blobdiff - src/lyxsocket.h
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / lyxsocket.h
index cadea4cbe7152e3045809858452f4a16d0cd9d11..84d3e2c1515c841cffd8f5f4c27938f3b360fa1a 100644 (file)
 #include "support/socktools.h"
 #include "lyxfunc.h"
 
+#include <boost/shared_ptr.hpp>
+
 #include <string>
-#include <set>
+#include <map>
+
+
+namespace lyx {
 
 class LyXServerSocket;
 class LyXDataSocket;
 
+
 /** Sockets can be in two states: listening and connected.
  *  Connected sockets are used to transfer data, and will therefore
  *  be called Data Sockets. Listening sockets are used to create
@@ -32,24 +38,22 @@ class LyXDataSocket;
  * This class encapsulates local (unix) server socket operations and
  * manages LyXDataSockets objects that are created when clients connect.
  */
-class LyXServerSocket
-{
+class LyXServerSocket {
 public:
+       ///
        LyXServerSocket(LyXFunc *, std::string const &);
+       ///
        ~LyXServerSocket();
-       /// File descriptor of the socket
-       int fd() const;
        /// Address of the local socket
        std::string const & address() const;
        /// To be called when there is activity in the server socket
        void serverCallback();
        /// To be called when there is activity in the data socket
-       void dataCallback(LyXDataSocket *);
-
+       void dataCallback(int fd);
 private:
-       /// Close the connection to the argument client
-       void close(LyXDataSocket *);
-
+       ///
+       void writeln(std::string const &);
+       ///
        LyXFunc * func;
        /// File descriptor for the server socket
        int fd_;
@@ -57,40 +61,41 @@ private:
        std::string address_;
        /// Maximum number of simultaneous clients
        enum {
-                MAX_CLIENTS = 10
-        };
+               MAX_CLIENTS = 10
+       };
        /// All connections
-       std::set<LyXDataSocket *> clients;
+       std::map<int, boost::shared_ptr<LyXDataSocket> > clients;
 };
 
 
 /** This class encapsulates data socket operations.
  *  It provides read and write IO operations on the socket.
  */
-class LyXDataSocket
-{
+class LyXDataSocket {
 public:
-       LyXDataSocket(LyXServerSocket *);
+       ///
+       LyXDataSocket(int fd);
+       ///
        ~LyXDataSocket();
-       /// The object that allocated us
-       LyXServerSocket * server() const;
-       /// File descriptor of the connection
-       int fd() const;
        /// Connection status
        bool connected() const;
-       /// Line buffered input from the socket 
+       /// Line buffered input from the socket
        bool readln(std::string &);
        /// Write the string + '\n' to the socket
        void writeln(std::string const &);
-
 private:
-       LyXServerSocket * server_;
        /// File descriptor for the data socket
        int fd_;
        /// True if the connection is up
        bool connected_;
        /// buffer for input data
-       std::string buffer;
+       std::string buffer_;
 };
 
+/// Implementation is in lyx_main.C
+extern LyXServerSocket & theLyXServerSocket();
+
+
+} // namespace lyx
+
 #endif // LYXSOCKET_H