Another minor change, but this should almost get us to the point that we
[lyx.git] / src / ServerSocket.h
blob1899e8b9ae82de30d2792252947b34a7b8982b10
1 // -*- C++ -*-
2 /**
3 * \file ServerSocket.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
9 * \author João Luis M. Assirati
11 * Full author contact details are available in file CREDITS.
14 #ifndef LYXSERVERSOCKET_H
15 #define LYXSERVERSOCKET_H
17 #include "support/FileName.h"
18 #include "support/socktools.h"
20 #include <boost/shared_ptr.hpp>
22 #include <string>
23 #include <map>
26 namespace lyx {
28 class LyXDataSocket;
29 class LyXFunc;
32 /** Sockets can be in two states: listening and connected.
33 * Connected sockets are used to transfer data, and will therefore
34 * be called Data Sockets. Listening sockets are used to create
35 * Data Sockets when clients connect, and therefore will be called
36 * Server Sockets.
38 * This class encapsulates local (unix) server socket operations and
39 * manages LyXDataSockets objects that are created when clients connect.
41 class ServerSocket {
42 public:
43 ///
44 ServerSocket(LyXFunc *, support::FileName const &);
45 ///
46 ~ServerSocket();
47 /// Address of the local socket
48 std::string const address() const;
49 /// To be called when there is activity in the server socket
50 void serverCallback();
51 /// To be called when there is activity in the data socket
52 void dataCallback(int fd);
53 private:
54 ///
55 void writeln(std::string const &);
56 ///
57 LyXFunc * func;
58 /// File descriptor for the server socket
59 int fd_;
60 /// Stores the socket filename
61 support::FileName address_;
62 /// Maximum number of simultaneous clients
63 enum {
64 MAX_CLIENTS = 10
66 /// All connections
67 std::map<int, boost::shared_ptr<LyXDataSocket> > clients;
71 /** This class encapsulates data socket operations.
72 * It provides read and write IO operations on the socket.
74 class LyXDataSocket {
75 public:
76 ///
77 LyXDataSocket(int fd);
78 ///
79 ~LyXDataSocket();
80 /// Connection status
81 bool connected() const;
82 /// Line buffered input from the socket
83 bool readln(std::string &);
84 /// Write the string + '\n' to the socket
85 void writeln(std::string const &);
86 private:
87 /// File descriptor for the data socket
88 int fd_;
89 /// True if the connection is up
90 bool connected_;
91 /// buffer for input data
92 std::string buffer_;
95 /// Implementation is in LyX.cpp
96 extern ServerSocket & theServerSocket();
99 } // namespace lyx
101 #endif // LYXSERVERSOCKET_H