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