1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxserver.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
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
|
|
|
|
|
2002-07-14 01:44:15 +00:00
|
|
|
|
#include <boost/signals/trackable.hpp>
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
typedef void (*ClientCallbackfct)(LyXServer *, std::string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// Construct with pipe-basename and callback to receive messages
|
2003-10-06 15:43:21 +00:00
|
|
|
|
LyXComm(std::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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void send(std::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
|
2005-01-20 15:07:36 +00:00
|
|
|
|
std::string const inPipeName() const;
|
2001-11-12 17:43:21 +00:00
|
|
|
|
|
|
|
|
|
/// the filename of the out pipe
|
2005-01-20 15:07:36 +00:00
|
|
|
|
std::string const outPipeName() const;
|
2001-11-12 17:43:21 +00:00
|
|
|
|
|
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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
int startPipe(std::string const &, bool);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-10-19 15:13:49 +00:00
|
|
|
|
/// finish a pipe
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void endPipe(int &, std::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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
LyXServer(LyXFunc * f, std::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();
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void notifyClient(std::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:
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
static void callback(LyXServer *, std::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
|
|
|
|
|
};
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::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;
|
|
|
|
|
};
|
|
|
|
|
|
2006-10-19 07:20:32 +00:00
|
|
|
|
/// Implementation is in lyx_main.C
|
|
|
|
|
extern LyXServer & theLyXServer();
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2006-10-23 14:24:04 +00:00
|
|
|
|
#endif /* _LYXSERVER_H_ */
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* === End of File: lyxserver.h ========================================== */
|