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
9 * \author Enrico Forestieri
11 * Full author contact details are available in file CREDITS.
17 #include <boost/signals/trackable.hpp>
32 /** This class managed the pipes used for communicating with clients.
33 Usage: Initialize with pipe-filename-base, client class to receive
34 messages, and callback-function that will be called with the messages.
35 When you want to send, use "send()".
36 This class encapsulates all the dirty communication and thus provides
37 a clean string interface.
40 class LyXComm : public boost::signals::trackable {
42 class LyXComm : public QObject {
46 /** When we receive a message, we send it to a client.
47 This is one of the small things that would have been a lot
48 cleaner with a Signal/Slot thing.
50 typedef void (*ClientCallbackfct)(Server *, std::string const &);
52 /// Construct with pipe-basename and callback to receive messages
53 LyXComm(std::string const & pip, Server * cli, ClientCallbackfct ccb = 0);
56 ~LyXComm() { closeConnection(); }
58 /// clean up in emergency
59 void emergencyCleanup();
62 void send(std::string const &);
64 /// asynch ready-to-be-read notification
68 void read_ready(HANDLE);
75 /// the filename of the in pipe
76 std::string const inPipeName() const;
78 /// the filename of the out pipe
79 std::string const outPipeName() const;
82 void openConnection();
85 void closeConnection();
89 int startPipe(std::string const &, bool);
92 void endPipe(int &, std::string const &, bool);
94 /// This is -1 if not open
97 /// This is -1 if not open
103 /// Are we up and running?
106 /// Base of pipename including path
107 std::string pipename_;
112 /// The client callback function
113 ClientCallbackfct clientcb_;
116 /// Catch pipe ready-to-be-read notification
117 bool event(QEvent *);
119 /// Check whether the pipe server must be stopped
120 BOOL checkStopServerEvent();
122 /// Windows event for stopping the pipe server
132 // Hack! This should be changed in 0.13
134 // The lyx server should not take an argument "LyXFunc" but this is
135 // how it will be done for 0.12. In 0.13 we must write a non-gui
137 // IMO lyxserver is atypical, and for the moment the only one, non-gui
138 // bufferview. We just have to find a way to handle situations like if
139 // lyxserver is using a buffer that is being edited with a bufferview.
140 // With a common buffer list this is not a problem, maybe. (Alejandro)
142 Server(LyXFunc * f, std::string const & pip);
146 void notifyClient(std::string const &);
148 /// whilst crashing etc.
149 void emergencyCleanup() { pipes_.emergencyCleanup(); }
151 void callback(std::string const & msg);
154 /// Names and number of current clients
155 enum { MAX_CLIENTS = 10 };
157 std::string clients_[MAX_CLIENTS];
166 /// Implementation is in LyX.cpp
167 extern Server & theServer();