]> git.lyx.org Git - lyx.git/blob - src/lyxsocket.h
float2string #4 (Spacing)
[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/socktools.h"
18 #include "lyxfunc.h"
19
20 #include <boost/shared_ptr.hpp>
21
22 #include <string>
23 #include <map>
24
25 class LyXServerSocket;
26 class LyXDataSocket;
27
28
29 /** Sockets can be in two states: listening and connected.
30  *  Connected sockets are used to transfer data, and will therefore
31  *  be called Data Sockets. Listening sockets are used to create
32  *  Data Sockets when clients connect, and therefore will be called
33  * Server Sockets.
34
35  * This class encapsulates local (unix) server socket operations and
36  * manages LyXDataSockets objects that are created when clients connect.
37  */
38 class LyXServerSocket {
39 public:
40         ///
41         LyXServerSocket(LyXFunc *, std::string const &);
42         ///
43         ~LyXServerSocket();
44         /// Address of the local socket
45         std::string const & address() const;
46         /// To be called when there is activity in the server socket
47         void serverCallback();
48         /// To be called when there is activity in the data socket
49         void dataCallback(int fd);
50 private:
51         ///
52         void writeln(std::string const &);
53         ///
54         LyXFunc * func;
55         /// File descriptor for the server socket
56         int fd_;
57         /// Stores the socket filename
58         std::string address_;
59         /// Maximum number of simultaneous clients
60         enum {
61                 MAX_CLIENTS = 10
62         };
63         /// All connections
64         std::map<int, boost::shared_ptr<LyXDataSocket> > clients;
65 };
66
67
68 /** This class encapsulates data socket operations.
69  *  It provides read and write IO operations on the socket.
70  */
71 class LyXDataSocket {
72 public:
73         ///
74         LyXDataSocket(int fd);
75         ///
76         ~LyXDataSocket();
77         /// Connection status
78         bool connected() const;
79         /// Line buffered input from the socket
80         bool readln(std::string &);
81         /// Write the string + '\n' to the socket
82         void writeln(std::string const &);
83 private:
84         /// File descriptor for the data socket
85         int fd_;
86         /// True if the connection is up
87         bool connected_;
88         /// buffer for input data
89         std::string buffer_;
90 };
91
92 #endif // LYXSOCKET_H