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 * ====================================================== */
17 #include <boost/signals/trackable.hpp>
22 /* --- i/o pipes --------------------------------------------------------- */
24 /** This class managed the pipes used for communicating with clients.
25 Usage: Initialize with pipe-filename-base, client class to receive
26 messages, and callback-function that will be called with the messages.
27 When you want to send, use "send()".
28 This class encapsulates all the dirty communication and thus provides
29 a clean string interface.
31 class LyXComm : public boost::signals::trackable {
33 /** When we receive a message, we send it to a client.
34 This is one of the small things that would have been a lot
35 cleaner with a Signal/Slot thing.
37 typedef void (*ClientCallbackfct)(LyXServer *, string const &);
39 /// Construct with pipe-basename and callback to receive messages
40 LyXComm(string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
41 : pipename(pip), client(cli), clientcb(ccb) {
51 /// clean up in emergency
52 void emergencyCleanup();
55 void send(string const &);
57 /// asynch ready-to-be-read notification
61 /// the filename of the in pipe
62 string const inPipeName() {
63 return pipename + ".in";
66 /// the filename of the out pipe
67 string const outPipeName() {
68 return pipename + ".out";
72 void openConnection();
75 void closeConnection();
78 int startPipe(string const &, bool);
81 void endPipe(int &, string const &, bool);
83 /// This is -1 if not open
86 /// This is -1 if not open
89 /// Are we up and running?
92 /// Base of pipename including path
98 /// The client callback function
99 ClientCallbackfct clientcb;
103 /* --- prototypes -------------------------------------------------------- */
108 // Hack! This should be changed in 0.13
110 // The lyx server should not take an argument "LyXFunc" but this is
111 // how it will be done for 0.12. In 0.13 we must write a non-gui
113 // IMO lyxserver is atypical, and for the moment the only one, non-gui
114 // bufferview. We just have to find a way to handle situations like if
115 // lyxserver is using a buffer that is being edited with a bufferview.
116 // With a common buffer list this is not a problem, maybe. (Alejandro)
118 LyXServer(LyXFunc * f, string const & pip)
119 : numclients(0), func(f), pipes(pip, (this), callback) {}
123 void notifyClient(string const &);
125 /// whilst crashing etc.
126 void emergencyCleanup() {
127 pipes.emergencyCleanup();
132 static void callback(LyXServer *, string const & msg);
133 /// Names and number of current clients
139 string clients[MAX_CLIENTS];
148 #endif /* _LYXSERVER_H_ */
150 /* === End of File: lyxserver.h ========================================== */