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>
24 /* --- i/o pipes --------------------------------------------------------- */
26 /** This class managed the pipes used for communicating with clients.
27 Usage: Initialize with pipe-filename-base, client class to receive
28 messages, and callback-function that will be called with the messages.
29 When you want to send, use "send()".
30 This class encapsulates all the dirty communication and thus provides
31 a clean string interface.
33 class LyXComm : public boost::signals::trackable {
35 /** When we receive a message, we send it to a client.
36 This is one of the small things that would have been a lot
37 cleaner with a Signal/Slot thing.
39 typedef void (*ClientCallbackfct)(LyXServer *, std::string const &);
41 /// Construct with pipe-basename and callback to receive messages
42 LyXComm(std::string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
43 : pipename(pip), client(cli), clientcb(ccb) {
53 /// clean up in emergency
54 void emergencyCleanup();
57 void send(std::string const &);
59 /// asynch ready-to-be-read notification
63 /// the filename of the in pipe
64 std::string const inPipeName() const;
66 /// the filename of the out pipe
67 std::string const outPipeName() const;
70 void openConnection();
73 void closeConnection();
76 int startPipe(std::string const &, bool);
79 void endPipe(int &, std::string const &, bool);
81 /// This is -1 if not open
84 /// This is -1 if not open
87 /// Are we up and running?
90 /// Base of pipename including path
96 /// The client callback function
97 ClientCallbackfct clientcb;
101 /* --- prototypes -------------------------------------------------------- */
106 // Hack! This should be changed in 0.13
108 // The lyx server should not take an argument "LyXFunc" but this is
109 // how it will be done for 0.12. In 0.13 we must write a non-gui
111 // IMO lyxserver is atypical, and for the moment the only one, non-gui
112 // bufferview. We just have to find a way to handle situations like if
113 // lyxserver is using a buffer that is being edited with a bufferview.
114 // With a common buffer list this is not a problem, maybe. (Alejandro)
116 LyXServer(LyXFunc * f, std::string const & pip)
117 : numclients(0), func(f), pipes(pip, (this), callback) {}
121 void notifyClient(std::string const &);
123 /// whilst crashing etc.
124 void emergencyCleanup() {
125 pipes.emergencyCleanup();
130 static void callback(LyXServer *, std::string const & msg);
131 /// Names and number of current clients
137 std::string clients[MAX_CLIENTS];
146 /// Implementation is in lyx_main.C
147 extern LyXServer & theLyXServer();
152 #endif /* _LYXSERVER_H_ */
154 /* === End of File: lyxserver.h ========================================== */