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
10 * Full author contact details are available in file CREDITS.
16 #include <boost/signals/trackable.hpp>
21 /* --- i/o pipes --------------------------------------------------------- */
23 /** This class managed the pipes used for communicating with clients.
24 Usage: Initialize with pipe-filename-base, client class to receive
25 messages, and callback-function that will be called with the messages.
26 When you want to send, use "send()".
27 This class encapsulates all the dirty communication and thus provides
28 a clean string interface.
30 class LyXComm : public boost::signals::trackable {
32 /** When we receive a message, we send it to a client.
33 This is one of the small things that would have been a lot
34 cleaner with a Signal/Slot thing.
36 typedef void (*ClientCallbackfct)(LyXServer *, std::string const &);
38 /// Construct with pipe-basename and callback to receive messages
39 LyXComm(std::string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
40 : pipename(pip), client(cli), clientcb(ccb) {
50 /// clean up in emergency
51 void emergencyCleanup();
54 void send(std::string const &);
56 /// asynch ready-to-be-read notification
60 /// the filename of the in pipe
61 std::string const inPipeName() const;
63 /// the filename of the out pipe
64 std::string const outPipeName() const;
67 void openConnection();
70 void closeConnection();
73 int startPipe(std::string const &, bool);
76 void endPipe(int &, std::string const &, bool);
78 /// This is -1 if not open
81 /// This is -1 if not open
84 /// Are we up and running?
87 /// Base of pipename including path
93 /// The client callback function
94 ClientCallbackfct clientcb;
98 /* --- prototypes -------------------------------------------------------- */
103 // Hack! This should be changed in 0.13
105 // The lyx server should not take an argument "LyXFunc" but this is
106 // how it will be done for 0.12. In 0.13 we must write a non-gui
108 // IMO lyxserver is atypical, and for the moment the only one, non-gui
109 // bufferview. We just have to find a way to handle situations like if
110 // lyxserver is using a buffer that is being edited with a bufferview.
111 // With a common buffer list this is not a problem, maybe. (Alejandro)
113 LyXServer(LyXFunc * f, std::string const & pip)
114 : numclients(0), func(f), pipes(pip, (this), callback) {}
118 void notifyClient(std::string const &);
120 /// whilst crashing etc.
121 void emergencyCleanup() {
122 pipes.emergencyCleanup();
127 static void callback(LyXServer *, std::string const & msg);
128 /// Names and number of current clients
134 std::string clients[MAX_CLIENTS];
143 #endif /* _LYXSERVER_H_ */
145 /* === End of File: lyxserver.h ========================================== */