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);
44 ~LyXComm() { closeConnection(); }
46 /// clean up in emergency
47 void emergencyCleanup();
50 void send(std::string
const &);
52 /// asynch ready-to-be-read notification
56 /// the filename of the in pipe
57 std::string
const inPipeName() const;
59 /// the filename of the out pipe
60 std::string
const outPipeName() const;
63 void openConnection();
66 void closeConnection();
69 int startPipe(std::string
const &, bool);
72 void endPipe(int &, std::string
const &, bool);
74 /// This is -1 if not open
77 /// This is -1 if not open
80 /// Are we up and running?
83 /// Base of pipename including path
84 std::string pipename_
;
89 /// The client callback function
90 ClientCallbackfct clientcb_
;
98 // Hack! This should be changed in 0.13
100 // The lyx server should not take an argument "LyXFunc" but this is
101 // how it will be done for 0.12. In 0.13 we must write a non-gui
103 // IMO lyxserver is atypical, and for the moment the only one, non-gui
104 // bufferview. We just have to find a way to handle situations like if
105 // lyxserver is using a buffer that is being edited with a bufferview.
106 // With a common buffer list this is not a problem, maybe. (Alejandro)
108 Server(LyXFunc
* f
, std::string
const & pip
);
112 void notifyClient(std::string
const &);
114 /// whilst crashing etc.
115 void emergencyCleanup() { pipes_
.emergencyCleanup(); }
117 void callback(std::string
const & msg
);
120 /// Names and number of current clients
121 enum { MAX_CLIENTS
= 10 };
123 std::string clients_
[MAX_CLIENTS
];
132 /// Implementation is in LyX.cpp
133 extern Server
& theServer();