1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
1999-09-27 18:44:28 +00:00
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
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
|
|
|
|
|
|
|
#include "LString.h"
|
2002-07-14 01:44:15 +00:00
|
|
|
|
|
|
|
#include <boost/signals/trackable.hpp>
|
2002-12-01 22:59:25 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
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
|
|
|
*/
|
2002-07-14 01:44:15 +00:00
|
|
|
class LyXComm : public boost::signals::trackable {
|
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();
|
|
|
|
}
|
|
|
|
|
2001-10-19 15:13:49 +00:00
|
|
|
/// clean up in emergency
|
|
|
|
void emergencyCleanup();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Send message
|
1999-10-02 16:21:10 +00:00
|
|
|
void send(string const &);
|
1999-10-25 14:18:30 +00:00
|
|
|
|
2002-07-14 01:44:15 +00:00
|
|
|
/// asynch ready-to-be-read notification
|
|
|
|
void read_ready();
|
1999-10-25 14:18:30 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
2001-11-12 17:43:21 +00:00
|
|
|
/// the filename of the in pipe
|
|
|
|
string const inPipeName() {
|
|
|
|
return pipename + ".in";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// the filename of the out pipe
|
|
|
|
string const outPipeName() {
|
|
|
|
return pipename + ".out";
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Open pipes
|
|
|
|
void openConnection();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Close pipes
|
|
|
|
void closeConnection();
|
|
|
|
|
2001-10-19 15:13:49 +00:00
|
|
|
/// start a pipe
|
2001-11-12 17:43:21 +00:00
|
|
|
int startPipe(string const &, bool);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-10-19 15:13:49 +00:00
|
|
|
/// finish a pipe
|
2002-07-30 22:35:43 +00:00
|
|
|
void endPipe(int &, string const &, bool);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// 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.
|
2002-03-21 17:27:08 +00:00
|
|
|
// 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) {}
|
2002-03-21 17:27:08 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
~LyXServer();
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
void notifyClient(string const &);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2001-10-19 15:13:49 +00:00
|
|
|
/// whilst crashing etc.
|
|
|
|
void emergencyCleanup() {
|
|
|
|
pipes.emergencyCleanup();
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
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 ========================================== */
|