2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
21 #include <boost/signals/trackable.hpp>
26 /* --- i/o pipes --------------------------------------------------------- */
28 /** This class managed the pipes used for communicating with clients.
29 Usage: Initialize with pipe-filename-base, client class to receive
30 messages, and callback-function that will be called with the messages.
31 When you want to send, use "send()".
32 This class encapsulates all the dirty communication and thus provides
33 a clean string interface.
35 class LyXComm : public boost::signals::trackable {
37 /** When we receive a message, we send it to a client.
38 This is one of the small things that would have been a lot
39 cleaner with a Signal/Slot thing.
41 typedef void (*ClientCallbackfct)(LyXServer *, string const &);
43 /// Construct with pipe-basename and callback to receive messages
44 LyXComm(string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
45 : pipename(pip), client(cli), clientcb(ccb) {
55 /// clean up in emergency
56 void emergencyCleanup();
59 void send(string const &);
61 /// asynch ready-to-be-read notification
65 /// the filename of the in pipe
66 string const inPipeName() {
67 return pipename + ".in";
70 /// the filename of the out pipe
71 string const outPipeName() {
72 return pipename + ".out";
76 void openConnection();
79 void closeConnection();
82 int startPipe(string const &, bool);
85 void endPipe(int &, string const &);
87 /// This is -1 if not open
90 /// This is -1 if not open
93 /// Are we up and running?
96 /// Base of pipename including path
102 /// The client callback function
103 ClientCallbackfct clientcb;
107 /* --- prototypes -------------------------------------------------------- */
112 // Hack! This should be changed in 0.13
114 // The lyx server should not take an argument "LyXFunc" but this is
115 // how it will be done for 0.12. In 0.13 we must write a non-gui
117 // IMO lyxserver is atypical, and for the moment the only one, non-gui
118 // bufferview. We just have to find a way to handle situations like if
119 // lyxserver is using a buffer that is being edited with a bufferview.
120 // With a common buffer list this is not a problem, maybe. (Alejandro)
122 LyXServer(LyXFunc * f, string const & pip)
123 : numclients(0), func(f), pipes(pip, (this), callback) {}
127 void notifyClient(string const &);
129 /// whilst crashing etc.
130 void emergencyCleanup() {
131 pipes.emergencyCleanup();
136 static void callback(LyXServer *, string const & msg);
137 /// Names and number of current clients
143 string clients[MAX_CLIENTS];
152 #endif /* _LYXSERVER_H_ */
154 /* === End of File: lyxserver.h ========================================== */