2003-10-13 12:25:11 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/**
|
|
|
|
|
* \file lyxsocket.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
|
|
|
|
|
* \author Jo<EFBFBD>o Luis M. Assirati
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LYXSOCKET_H
|
|
|
|
|
#define LYXSOCKET_H
|
|
|
|
|
|
2007-04-06 17:38:11 +00:00
|
|
|
|
#include "support/filename.h"
|
2003-10-13 12:25:11 +00:00
|
|
|
|
#include "support/socktools.h"
|
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
|
2004-07-21 19:03:21 +00:00
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
2003-10-13 12:25:11 +00:00
|
|
|
|
#include <string>
|
2004-07-21 19:03:21 +00:00
|
|
|
|
#include <map>
|
2003-10-13 12:25:11 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2003-10-13 12:25:11 +00:00
|
|
|
|
class LyXServerSocket;
|
|
|
|
|
class LyXDataSocket;
|
|
|
|
|
|
2004-07-21 19:03:21 +00:00
|
|
|
|
|
2003-10-13 12:25:11 +00:00
|
|
|
|
/** Sockets can be in two states: listening and connected.
|
|
|
|
|
* Connected sockets are used to transfer data, and will therefore
|
|
|
|
|
* be called Data Sockets. Listening sockets are used to create
|
|
|
|
|
* Data Sockets when clients connect, and therefore will be called
|
|
|
|
|
* Server Sockets.
|
|
|
|
|
|
|
|
|
|
* This class encapsulates local (unix) server socket operations and
|
|
|
|
|
* manages LyXDataSockets objects that are created when clients connect.
|
|
|
|
|
*/
|
2004-07-21 19:03:21 +00:00
|
|
|
|
class LyXServerSocket {
|
2003-10-13 12:25:11 +00:00
|
|
|
|
public:
|
2004-07-21 19:03:21 +00:00
|
|
|
|
///
|
2007-04-06 17:38:11 +00:00
|
|
|
|
LyXServerSocket(LyXFunc *, support::FileName const &);
|
2004-07-21 19:03:21 +00:00
|
|
|
|
///
|
2003-10-13 12:25:11 +00:00
|
|
|
|
~LyXServerSocket();
|
|
|
|
|
/// Address of the local socket
|
2007-04-06 17:38:11 +00:00
|
|
|
|
std::string const address() const;
|
2003-10-13 12:25:11 +00:00
|
|
|
|
/// To be called when there is activity in the server socket
|
|
|
|
|
void serverCallback();
|
|
|
|
|
/// To be called when there is activity in the data socket
|
2004-07-21 19:03:21 +00:00
|
|
|
|
void dataCallback(int fd);
|
2003-10-13 12:25:11 +00:00
|
|
|
|
private:
|
2004-07-21 19:03:21 +00:00
|
|
|
|
///
|
|
|
|
|
void writeln(std::string const &);
|
|
|
|
|
///
|
2003-10-13 12:25:11 +00:00
|
|
|
|
LyXFunc * func;
|
|
|
|
|
/// File descriptor for the server socket
|
|
|
|
|
int fd_;
|
|
|
|
|
/// Stores the socket filename
|
2007-04-06 17:38:11 +00:00
|
|
|
|
support::FileName address_;
|
2003-10-13 12:25:11 +00:00
|
|
|
|
/// Maximum number of simultaneous clients
|
|
|
|
|
enum {
|
2004-10-05 10:11:42 +00:00
|
|
|
|
MAX_CLIENTS = 10
|
|
|
|
|
};
|
2003-10-13 12:25:11 +00:00
|
|
|
|
/// All connections
|
2004-07-21 19:03:21 +00:00
|
|
|
|
std::map<int, boost::shared_ptr<LyXDataSocket> > clients;
|
2003-10-13 12:25:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** This class encapsulates data socket operations.
|
|
|
|
|
* It provides read and write IO operations on the socket.
|
|
|
|
|
*/
|
2004-07-21 19:03:21 +00:00
|
|
|
|
class LyXDataSocket {
|
2003-10-13 12:25:11 +00:00
|
|
|
|
public:
|
2004-07-21 19:03:21 +00:00
|
|
|
|
///
|
|
|
|
|
LyXDataSocket(int fd);
|
|
|
|
|
///
|
2003-10-13 12:25:11 +00:00
|
|
|
|
~LyXDataSocket();
|
|
|
|
|
/// Connection status
|
|
|
|
|
bool connected() const;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
/// Line buffered input from the socket
|
2003-10-13 12:25:11 +00:00
|
|
|
|
bool readln(std::string &);
|
|
|
|
|
/// Write the string + '\n' to the socket
|
|
|
|
|
void writeln(std::string const &);
|
|
|
|
|
private:
|
|
|
|
|
/// File descriptor for the data socket
|
|
|
|
|
int fd_;
|
|
|
|
|
/// True if the connection is up
|
|
|
|
|
bool connected_;
|
|
|
|
|
/// buffer for input data
|
2004-07-21 19:03:21 +00:00
|
|
|
|
std::string buffer_;
|
2003-10-13 12:25:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-19 07:20:32 +00:00
|
|
|
|
/// Implementation is in lyx_main.C
|
|
|
|
|
extern LyXServerSocket & theLyXServerSocket();
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2003-10-13 12:25:11 +00:00
|
|
|
|
#endif // LYXSOCKET_H
|