From: Lars Gullik Bjønnes Date: Thu, 22 Jul 2004 13:44:40 +0000 (+0000) Subject: the lyxserver modifications X-Git-Tag: 1.6.10~15150 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d9bf52e7c5af5ad439398718b6c2b37b53d927dc;p=features.git the lyxserver modifications git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8842 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 926fa454ec..a6b1fa2d08 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-07-22 Lars Gullik Bjonnes + + * lyxserver.C (startPipe): call register_socket_callback + (endPipe): call unregister_socket_callback + 2004-07-21 Lars Gullik Bjonnes * lyxsocket.C (LyXServerSocket): reduce max outstanding clients to 3 diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 797133d05c..0535f6123b 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ +2004-07-22 Lars Gullik Bjonnes + + * lyx_gui.h (set_read_callback,remove_read_callback): remove + declaration + 2004-06-18 Lars Gullik Bjonnes * screen.C (fitCursor): Use Debug::DEBUG diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index fee29d3083..50a6880344 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,12 @@ +2004-07-22 Lars Gullik Bjonnes + + * lyx_gui.C (register_socket_callback,unregister_socket_callback): + implement + (set_read_callback,remove_read_callback): remove implementation + + * io_callback.[Ch]: new files + * Makefile.am (libgtk_la_SOURCES): handle them + 2004-07-21 Lars Gullik Bjonnes * lyx_gui.C (register_socket_callback): add stub diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 5d5898be93..efebc5b8e8 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -47,6 +47,8 @@ libgtk_la_SOURCES = \ GView.C \ IdSc.h \ IdSc.C \ + io_callback.h \ + io_callback.C \ Dialogs.C \ GAboutlyx.h \ GAboutlyx.C \ diff --git a/src/frontends/gtk/io_callback.C b/src/frontends/gtk/io_callback.C new file mode 100644 index 0000000000..d5b507c9ac --- /dev/null +++ b/src/frontends/gtk/io_callback.C @@ -0,0 +1,28 @@ +/** + * \file io_callback.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author João Luis M. Assirati + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "io_callback.h" + + +io_callback::io_callback(int fd, boost::function func) + : func_(func) +{ + conn_ = Glib::signal_io().connect(SigC::slot(*this, &io_callback::data_received), fd, Glib::IO_IN); +} + + +bool io_callback::data_received(Glib::IOCondition /*condition*/) +{ + func_(); + return true; +} diff --git a/src/frontends/gtk/io_callback.h b/src/frontends/gtk/io_callback.h new file mode 100644 index 0000000000..24da391263 --- /dev/null +++ b/src/frontends/gtk/io_callback.h @@ -0,0 +1,41 @@ +// -*- C++ -*- +/** + * \file io_callback.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author João Luis M. Assirati + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef IO_CALLBACK_H +#define IO_CALLBACK_H + + +#include + +#include + + +/** + * io_callback - a simple wrapper for asynchronous socket notification + * + * This is used by the lyxsocket to notice the socket is ready to be + * connected/read. + * + */ +class io_callback : public SigC::Object { +public: + /// connect a connection notification from the LyXServerSocket + io_callback(int fd, boost::function func); +private: + bool data_received(Glib::IOCondition); + /// our notifier + SigC::Connection conn_; + /// The callback function + boost::function func_; +}; + +#endif // IO_CALLBACK_H diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index ac996808b3..6c4f31cf9d 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -31,6 +31,8 @@ #include "lyxfont.h" #include "graphics/LoaderQueue.h" +#include "io_callback.h" + // FIXME: move this stuff out again #include "bufferlist.h" #include "buffer_funcs.h" @@ -50,6 +52,7 @@ #include #include #include +#include //just for xforms #include "lyx_forms.h" @@ -414,44 +417,24 @@ bool lyx_gui::font_available(LyXFont const & font) namespace { +std::map > callbacks; -bool readCallback(Glib::IOCondition /*condition*/, LyXComm * comm) -{ - comm->read_ready(); - return true; -} - - -std::map gReadCallbackMap; +} // NS anon -} - -void lyx_gui::set_read_callback(int fd, LyXComm * comm) +void lyx_gui::register_socket_callback(int fd, + boost::function func) { - gReadCallbackMap[fd] = Glib::signal_io().connect( - SigC::bind(SigC::slot(readCallback), comm), - fd, - Glib::IO_IN); + callbacks[fd] = boost::shared_ptr(new io_callback(fd, func)); } -void lyx_gui::remove_read_callback(int fd) +void lyx_gui::unregister_socket_callback(int fd) { - gReadCallbackMap[fd].disconnect(); - gReadCallbackMap.erase(fd); + callbacks.erase(fd); } -void lyx_gui::register_socket_callback(int /*fd*/, - boost::function /*func*/) -{} - - -void lyx_gui::unregister_socket_callback(int /*fd*/) -{} - - string const lyx_gui::roman_font_name() { return "times"; diff --git a/src/frontends/lyx_gui.h b/src/frontends/lyx_gui.h index 3ce1729ff8..153c46fa54 100644 --- a/src/frontends/lyx_gui.h +++ b/src/frontends/lyx_gui.h @@ -95,16 +95,15 @@ void update_fonts(); bool font_available(LyXFont const & font); /** - * add a callback for I/O read notification + * add a callback for socket read notification + * @param fd socket descriptor (file/socket/etc) */ -void set_read_callback(int fd, LyXComm * comm); void register_socket_callback(int fd, boost::function func); /** * remove a I/O read callback - * @param fd file descriptor + * @param fd socket descriptor (file/socket/etc) */ -void remove_read_callback(int fd); void unregister_socket_callback(int fd); } // namespace lyx_gui diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 13f19787ac..90064bf3dd 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,10 @@ +2004-07-22 Lars Gullik Bjonnes + + * lyx_gui.C (set_read_callback,remove_read_callback): delete funcs + + * Makefile.dialogs (MOCFILES): remove io_callback.[Ch] + * io_callback.[Ch]: delete files + 2004-07-21 Lars Gullik Bjonnes * socket_callback.C (data_received): simplify diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index 9ca2495d45..1b1ada508d 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -74,7 +74,6 @@ MOCFILES = \ FileDialog_private.C FileDialog_private.h \ floatplacement.C floatplacement.h \ iconpalette.C iconpalette.h \ - io_callback.C io_callback.h \ lengthcombo.C lengthcombo.h \ panelstack.C panelstack.h \ QAboutDialog.C QAboutDialog.h \ diff --git a/src/frontends/qt2/io_callback.C b/src/frontends/qt2/io_callback.C deleted file mode 100644 index 643516ae81..0000000000 --- a/src/frontends/qt2/io_callback.C +++ /dev/null @@ -1,30 +0,0 @@ -/** - * \file io_callback.C - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author unknown - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#include - -// Qt defines a macro 'signals' that clashes with a boost namespace. -#include "lyxserver.h" - -#include "io_callback.h" - -io_callback::io_callback(int fd, LyXComm * comm) - : comm_(comm) -{ - sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this)); - connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received())); -} - - -void io_callback::data_received() -{ - comm_->read_ready(); -} diff --git a/src/frontends/qt2/io_callback.h b/src/frontends/qt2/io_callback.h deleted file mode 100644 index 9b6f7dd18a..0000000000 --- a/src/frontends/qt2/io_callback.h +++ /dev/null @@ -1,45 +0,0 @@ -// -*- C++ -*- -/** - * \file io_callback.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author unknown - * \author John Levon - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef IO_CALLBACK_H -#define IO_CALLBACK_H - - -#include -#include -#include - -class LyXComm; - -/** - * io_callback - a simple wrapper for asynchronous pipe notification - * - * This is used by the lyxserver to notice the pipe is ready to be - * read. - * - * FIXME: this code apparently will not work on Windows. - */ -class io_callback : public QObject { - Q_OBJECT -public: - /// connect a read ready notification for fd to the LyXComm - io_callback(int fd, LyXComm * comm); -public slots: - void data_received(); -private: - /// our notifier - boost::scoped_ptr sn_; - - LyXComm * comm_; -}; - -#endif // IO_CALLBACK_H diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index 7c4e874b9e..ecc714b1d2 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -38,7 +38,6 @@ #include #include "QtView.h" -#include "io_callback.h" #include "lcolorcache.h" #include "qfont_loader.h" #include "QLImage.h" @@ -80,7 +79,6 @@ float getDPI() return 0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY()); } -map io_callbacks; map > socket_callbacks; } // namespace anon @@ -288,22 +286,6 @@ bool font_available(LyXFont const & font) } -void set_read_callback(int fd, LyXComm * comm) -{ - io_callbacks[fd] = new io_callback(fd, comm); -} - - -void remove_read_callback(int fd) -{ - map::iterator it = io_callbacks.find(fd); - if (it != io_callbacks.end()) { - delete it->second; - io_callbacks.erase(it); - } -} - - void register_socket_callback(int fd, boost::function func) { socket_callbacks[fd] = shared_ptr(new socket_callback(fd, func)); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index e9daf80c89..2d68b73f02 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2004-07-22 Lars Gullik Bjonnes + + * lyx_gui.C (C_read_callback, set_read_callback, + remove_read_callback): delete funcs + 2004-07-21 Lars Gullik Bjonnes * lyx_gui.C (register_socket_callback): new func diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index c9c27233e3..d4579ab048 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -388,28 +388,6 @@ bool font_available(LyXFont const & font) return fontloader.available(font); } -namespace { - -extern "C" -void C_read_callback(int, void * data) -{ - LyXComm * comm = static_cast(data); - comm->read_ready(); -} - -} - - -void set_read_callback(int fd, LyXComm * comm) -{ - fl_add_io_callback(fd, FL_READ, C_read_callback, comm); -} - -void remove_read_callback(int fd) -{ - fl_remove_io_callback(fd, FL_READ, C_read_callback); -} - namespace { diff --git a/src/lyxserver.C b/src/lyxserver.C index d258cb5474..093239d507 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -48,6 +48,8 @@ #include "support/lyxlib.h" #include "frontends/lyx_gui.h" +#include + #include #include #include @@ -205,7 +207,7 @@ int LyXComm::startPipe(string const & filename, bool write) } if (!write) { - lyx_gui::set_read_callback(fd, this); + lyx_gui::register_socket_callback(fd, boost::bind(&LyXComm::read_ready, *this)); } return fd; @@ -218,7 +220,7 @@ void LyXComm::endPipe(int & fd, string const & filename, bool write) return; if (!write) { - lyx_gui::remove_read_callback(fd); + lyx_gui::unregister_socket_callback(fd); } #ifdef __EMX__