Consider the case where there is not any layout name.
[lyx.git] / src / lyxserver.h
blob838c4b693b7ec18a2404b6d9871e57db73d141f0
1 // -*- C++ -*-
2 /**
3 * \file lyxserver.h
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.
13 #ifndef LYXSERVER_H
14 #define LYXSERVER_H
16 #include <boost/signals/trackable.hpp>
18 class LyXFunc;
19 class LyXServer;
21 /* --- i/o pipes --------------------------------------------------------- */
23 /** This class managed the pipes used for communicating with clients.
24 Usage: Initialize with pipe-filename-base, client class to receive
25 messages, and callback-function that will be called with the messages.
26 When you want to send, use "send()".
27 This class encapsulates all the dirty communication and thus provides
28 a clean string interface.
30 class LyXComm : public boost::signals::trackable {
31 public:
32 /** When we receive a message, we send it to a client.
33 This is one of the small things that would have been a lot
34 cleaner with a Signal/Slot thing.
36 typedef void (*ClientCallbackfct)(LyXServer *, std::string const &);
38 /// Construct with pipe-basename and callback to receive messages
39 LyXComm(std::string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
40 : pipename(pip), client(cli), clientcb(ccb) {
41 ready = false;
42 openConnection();
45 ///
46 ~LyXComm() {
47 closeConnection();
50 /// clean up in emergency
51 void emergencyCleanup();
53 /// Send message
54 void send(std::string const &);
56 /// asynch ready-to-be-read notification
57 void read_ready();
59 private:
60 /// the filename of the in pipe
61 std::string const inPipeName() const;
63 /// the filename of the out pipe
64 std::string const outPipeName() const;
66 /// Open pipes
67 void openConnection();
69 /// Close pipes
70 void closeConnection();
72 /// start a pipe
73 int startPipe(std::string const &, bool);
75 /// finish a pipe
76 void endPipe(int &, std::string const &, bool);
78 /// This is -1 if not open
79 int infd;
81 /// This is -1 if not open
82 int outfd;
84 /// Are we up and running?
85 bool ready;
87 /// Base of pipename including path
88 std::string pipename;
90 /// The client
91 LyXServer * client;
93 /// The client callback function
94 ClientCallbackfct clientcb;
98 /* --- prototypes -------------------------------------------------------- */
99 ///
100 class LyXServer {
101 public:
102 // FIXME IN 0.13
103 // Hack! This should be changed in 0.13
105 // The lyx server should not take an argument "LyXFunc" but this is
106 // how it will be done for 0.12. In 0.13 we must write a non-gui
107 // bufferview.
108 // IMO lyxserver is atypical, and for the moment the only one, non-gui
109 // bufferview. We just have to find a way to handle situations like if
110 // lyxserver is using a buffer that is being edited with a bufferview.
111 // With a common buffer list this is not a problem, maybe. (Alejandro)
113 LyXServer(LyXFunc * f, std::string const & pip)
114 : numclients(0), func(f), pipes(pip, (this), callback) {}
116 ~LyXServer();
118 void notifyClient(std::string const &);
120 /// whilst crashing etc.
121 void emergencyCleanup() {
122 pipes.emergencyCleanup();
125 private:
127 static void callback(LyXServer *, std::string const & msg);
128 /// Names and number of current clients
129 enum {
131 MAX_CLIENTS = 10
134 std::string clients[MAX_CLIENTS];
136 int numclients;
138 LyXFunc * func;
140 LyXComm pipes;
143 #endif /* _LYXSERVER_H_ */
145 /* === End of File: lyxserver.h ========================================== */