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>
25 /** This class managed the pipes used for communicating with clients.
26 Usage: Initialize with pipe-filename-base, client class to receive
27 messages, and callback-function that will be called with the messages.
28 When you want to send, use "send()".
29 This class encapsulates all the dirty communication and thus provides
30 a clean string interface.
32 class LyXComm : public boost::signals::trackable {
34 /** When we receive a message, we send it to a client.
35 This is one of the small things that would have been a lot
36 cleaner with a Signal/Slot thing.
38 typedef void (*ClientCallbackfct)(Server *, std::string const &);
40 /// Construct with pipe-basename and callback to receive messages
41 LyXComm(std::string const & pip, Server * cli, ClientCallbackfct ccb = 0)
42 : pipename(pip), client(cli), clientcb(ccb)
49 ~LyXComm() { closeConnection(); }
51 /// clean up in emergency
52 void emergencyCleanup();
55 void send(std::string const &);
57 /// asynch ready-to-be-read notification
61 /// the filename of the in pipe
62 std::string const inPipeName() const;
64 /// the filename of the out pipe
65 std::string const outPipeName() const;
68 void openConnection();
71 void closeConnection();
74 int startPipe(std::string const &, bool);
77 void endPipe(int &, std::string const &, bool);
79 /// This is -1 if not open
82 /// This is -1 if not open
85 /// Are we up and running?
88 /// Base of pipename including path
94 /// The client callback function
95 ClientCallbackfct clientcb;
104 // Hack! This should be changed in 0.13
106 // The lyx server should not take an argument "LyXFunc" but this is
107 // how it will be done for 0.12. In 0.13 we must write a non-gui
109 // IMO lyxserver is atypical, and for the moment the only one, non-gui
110 // bufferview. We just have to find a way to handle situations like if
111 // lyxserver is using a buffer that is being edited with a bufferview.
112 // With a common buffer list this is not a problem, maybe. (Alejandro)
114 Server(LyXFunc * f, std::string const & pip)
115 : numclients(0), func(f), pipes(pip, (this), callback) {}
119 void notifyClient(std::string const &);
121 /// whilst crashing etc.
122 void emergencyCleanup() { pipes.emergencyCleanup(); }
126 static void callback(Server *, std::string const & msg);
127 /// Names and number of current clients
133 std::string clients[MAX_CLIENTS];
142 /// Implementation is in LyX.cpp
143 extern Server & theServer();