lyx_mirror/src/lyxsocket.h
Abdelrazak Younes 1f8fe29384 This commit transfers the singletons defined in the Application class to the private LyX::Singletons implementation. It also put the session_ member and top_level_keymap global variable into this Singleton structure.
This commit also modifies the LyXFunc class. A LyXView is not needed any more at construction. Neither is the top level keymap. The LyXFunc key sequences are initialized only if we are in GUI mode (lyx::use_gui = true).
The next step is to rename LyXFunc::owner to LyXFunc::lyx_view_ and to put some BOOST_ASSERT. A classification between Gui and Kernel oriented LFUNs would also be welcome.

*LyX/lyx_main.[Ch]:
 - LyX::Singletons: new private structure containing all the singletons (except the main LyX one of course).
 - buffer_list_, top_level_keymap, session_: transfered to the LyX::Singletons structure.

* LyXFunc:
  - LyXFunc: default constructor does not need any arguments.
  - setupLocalKeymap(): deleted (was not used anywhere).
  - initKeySequences(): new public method called from lyx_main.C, useful only in lyx::use_gui mode.
  - new private member accessor methods

* Application:
  - Application_pimpl: deleted (transfered to LyX)
  - global singleton accessors: transfered to lyx_main.C
  - start(): code transfered to LyX::priv_exec()


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15367 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-19 07:20:32 +00:00

96 lines
2.3 KiB
C++

// -*- 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ønnes
* \author Jean-Marc Lasgouttes
* \author João Luis M. Assirati
*
* Full author contact details are available in file CREDITS.
*/
#ifndef LYXSOCKET_H
#define LYXSOCKET_H
#include "support/socktools.h"
#include "lyxfunc.h"
#include <boost/shared_ptr.hpp>
#include <string>
#include <map>
class LyXServerSocket;
class LyXDataSocket;
/** 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.
*/
class LyXServerSocket {
public:
///
LyXServerSocket(LyXFunc *, std::string const &);
///
~LyXServerSocket();
/// Address of the local socket
std::string const & address() const;
/// To be called when there is activity in the server socket
void serverCallback();
/// To be called when there is activity in the data socket
void dataCallback(int fd);
private:
///
void writeln(std::string const &);
///
LyXFunc * func;
/// File descriptor for the server socket
int fd_;
/// Stores the socket filename
std::string address_;
/// Maximum number of simultaneous clients
enum {
MAX_CLIENTS = 10
};
/// All connections
std::map<int, boost::shared_ptr<LyXDataSocket> > clients;
};
/** This class encapsulates data socket operations.
* It provides read and write IO operations on the socket.
*/
class LyXDataSocket {
public:
///
LyXDataSocket(int fd);
///
~LyXDataSocket();
/// Connection status
bool connected() const;
/// Line buffered input from the socket
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
std::string buffer_;
};
/// Implementation is in lyx_main.C
extern LyXServerSocket & theLyXServerSocket();
#endif // LYXSOCKET_H