1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-16 14:06:57 +00:00
|
|
|
#ifndef LYXSERVER_H
|
|
|
|
#define LYXSERVER_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
|
|
|
class LyXFunc;
|
|
|
|
class LyXServer;
|
|
|
|
|
|
|
|
/* --- i/o pipes --------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** This class managed the pipes used for communicating with clients.
|
|
|
|
Usage: Initialize with pipe-filename-base, client class to receive
|
|
|
|
messages, and callback-function that will be called with the messages.
|
|
|
|
When you want to send, use "send()".
|
|
|
|
This class encapsulates all the dirty communication and thus provides
|
1999-10-02 16:21:10 +00:00
|
|
|
a clean string interface.
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
2000-08-07 20:58:24 +00:00
|
|
|
class LyXComm {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
/** When we receive a message, we send it to a client.
|
|
|
|
This is one of the small things that would have been a lot
|
|
|
|
cleaner with a Signal/Slot thing.
|
|
|
|
*/
|
1999-10-02 16:21:10 +00:00
|
|
|
typedef void (*ClientCallbackfct)(LyXServer *, string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Construct with pipe-basename and callback to receive messages
|
2000-04-08 17:02:02 +00:00
|
|
|
LyXComm(string const & pip, LyXServer * cli, ClientCallbackfct ccb = 0)
|
2000-08-07 20:58:24 +00:00
|
|
|
: pipename(pip), client(cli), clientcb(ccb) {
|
1999-09-27 18:44:28 +00:00
|
|
|
ready = false;
|
|
|
|
openConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
~LyXComm() {
|
|
|
|
closeConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Send message
|
1999-10-02 16:21:10 +00:00
|
|
|
void send(string const &);
|
1999-10-25 14:18:30 +00:00
|
|
|
|
|
|
|
/// We receive messages via XForms through this callback
|
|
|
|
static void callback(int fd, void *v);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
|
|
|
/// Open pipes
|
|
|
|
void openConnection();
|
|
|
|
|
|
|
|
/// Close pipes
|
|
|
|
void closeConnection();
|
|
|
|
|
|
|
|
/// This is -1 if not open
|
|
|
|
int infd;
|
|
|
|
|
|
|
|
/// This is -1 if not open
|
|
|
|
int outfd;
|
|
|
|
|
|
|
|
/// Are we up and running?
|
|
|
|
bool ready;
|
|
|
|
|
|
|
|
/// Base of pipename including path
|
1999-10-02 16:21:10 +00:00
|
|
|
string pipename;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// The client
|
|
|
|
LyXServer * client;
|
|
|
|
|
|
|
|
/// The client callback function
|
|
|
|
ClientCallbackfct clientcb;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* --- prototypes -------------------------------------------------------- */
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
|
|
|
class LyXServer {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
// FIXME IN 0.13
|
|
|
|
// Hack! This should be changed in 0.13
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
// The lyx server should not take an argument "LyXFunc" but this is
|
1999-09-27 18:44:28 +00:00
|
|
|
// how it will be done for 0.12. In 0.13 we must write a non-gui
|
|
|
|
// bufferview.
|
|
|
|
// IMO lyxserver is atypical, and for the moment the only one, non-gui
|
|
|
|
// bufferview. We just have to find a way to handle situations like if
|
|
|
|
// lyxserver is using a buffer that is being edited with a bufferview.
|
|
|
|
// With a common buffer list this is not a problem, maybe. (Alejandro)
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
LyXServer(LyXFunc * f, string const & pip)
|
2000-08-07 20:58:24 +00:00
|
|
|
: numclients(0), func(f), pipes(pip, (this), callback) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~LyXServer();
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
void notifyClient(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
static void callback(LyXServer *, string const & msg);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Names and number of current clients
|
2000-08-07 20:58:24 +00:00
|
|
|
enum {
|
|
|
|
///
|
|
|
|
MAX_CLIENTS = 10
|
|
|
|
};
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
string clients[MAX_CLIENTS];
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
int numclients;
|
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
LyXFunc * func;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
LyXComm pipes;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _LYXSERVER_H_ */
|
|
|
|
|
|
|
|
/* === End of File: lyxserver.h ========================================== */
|