]> git.lyx.org Git - lyx.git/blob - src/lyxserver.h
change LyXScreen names to begin with lower case
[lyx.git] / src / lyxserver.h
1 // -*- C++ -*-
2 /* This file is part of
3 * ====================================================== 
4
5 *           LyX, The Document Processor
6 *        
7 *           Copyright 1995 Matthias Ettrich
8 *           Copyright 1995-2001 The LyX Team.
9 *
10 * ====================================================== */
11
12 #ifndef LYXSERVER_H
13 #define LYXSERVER_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "LString.h"
20 class LyXFunc;
21 class LyXServer;
22
23 /* --- i/o pipes --------------------------------------------------------- */
24
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.
31  */
32 class LyXComm {
33 public:
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.
37          */
38         typedef void (*ClientCallbackfct)(LyXServer *, string const &);
39
40         /// Construct with pipe-basename and callback to receive messages
41         LyXComm(string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
42                 : pipename(pip), client(cli), clientcb(ccb) {
43                 ready = false;
44                 openConnection();
45         }
46
47         ///
48         ~LyXComm() {
49                 closeConnection();
50         }
51
52         /// Send message
53         void send(string const &);
54
55         /// We receive messages via XForms through this callback
56         static void callback(int fd, void *v);
57
58 private:
59         /// Open pipes
60         void openConnection();
61         
62         /// Close pipes
63         void closeConnection();
64
65         /// This is -1 if not open
66         int infd;
67
68         /// This is -1 if not open
69         int outfd;
70
71         /// Are we up and running?
72         bool ready;
73
74         /// Base of pipename including path
75         string pipename;
76
77         /// The client
78         LyXServer * client;
79
80         /// The client callback function
81         ClientCallbackfct clientcb;
82 };
83
84
85 /* --- prototypes -------------------------------------------------------- */
86 ///
87 class LyXServer {
88 public:
89         // FIXME IN 0.13
90         // Hack! This should be changed in 0.13
91
92         // The lyx server should not take an argument "LyXFunc" but this is
93         // how it will be done for 0.12. In 0.13 we must write a non-gui
94         // bufferview.
95         // IMO lyxserver is atypical, and for the moment the only one, non-gui
96         // bufferview. We just have to find a way to handle situations like if
97         // lyxserver is using a buffer that is being edited with a bufferview.
98         // With a common buffer list this is not a problem, maybe. (Alejandro)
99         ///
100         LyXServer(LyXFunc * f, string const & pip)
101                 : numclients(0), func(f), pipes(pip, (this), callback) {}
102         /// 
103         ~LyXServer();
104         ///
105         void notifyClient(string const &);
106 private:
107         ///
108         static void callback(LyXServer *, string const & msg);
109         /// Names and number of current clients
110         enum {
111                 ///
112                 MAX_CLIENTS = 10
113         };
114         ///
115         string clients[MAX_CLIENTS];
116         ///
117         int numclients;
118         ///
119         LyXFunc * func;
120         ///
121         LyXComm pipes;
122 };
123
124 #endif /* _LYXSERVER_H_ */
125
126 /* === End of File: lyxserver.h ========================================== */