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() {
62 return pipename + ".in";
65 /// the filename of the out pipe
66 std::string const outPipeName() {
67 return pipename + ".out";
71 void openConnection();
74 void closeConnection();
77 int startPipe(std::string const &, bool);
80 void endPipe(int &, std::string const &, bool);
82 /// This is -1 if not open
85 /// This is -1 if not open
88 /// Are we up and running?
91 /// Base of pipename including path
97 /// The client callback function
98 ClientCallbackfct clientcb;
102 /* --- prototypes -------------------------------------------------------- */
107 // Hack! This should be changed in 0.13
109 // The lyx server should not take an argument "LyXFunc" but this is
110 // how it will be done for 0.12. In 0.13 we must write a non-gui
112 // IMO lyxserver is atypical, and for the moment the only one, non-gui
113 // bufferview. We just have to find a way to handle situations like if
114 // lyxserver is using a buffer that is being edited with a bufferview.
115 // With a common buffer list this is not a problem, maybe. (Alejandro)
117 LyXServer(LyXFunc * f, std::string const & pip)
118 : numclients(0), func(f), pipes(pip, (this), callback) {}
122 void notifyClient(std::string const &);
124 /// whilst crashing etc.
125 void emergencyCleanup() {
126 pipes.emergencyCleanup();
131 static void callback(LyXServer *, std::string const & msg);
132 /// Names and number of current clients
138 std::string clients[MAX_CLIENTS];
147 #endif /* _LYXSERVER_H_ */
149 /* === End of File: lyxserver.h ========================================== */