]> git.lyx.org Git - lyx.git/blobdiff - src/lyxserver.C
fix two crashes related to dEPM. Some crashes remain
[lyx.git] / src / lyxserver.C
index 0f38a4520472784cddbfd2f7bb93ea2d1e7e0604..ad743460a1ac0072500370ec80d551c8b35e2dd8 100644 (file)
 
 #include <config.h>
 
-#include <fcntl.h>
-
 #include "lyxserver.h"
 #include "debug.h"
+#include "funcrequest.h"
+#include "LyXAction.h"
 #include "lyxfunc.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 #include "frontends/lyx_gui.h"
 
-#ifdef __EMX__
-#define OS2EMX_PLAIN_CHAR
-#define INCL_DOSNMPIPES
-#define INCL_DOSERRORS
+#include <boost/bind.hpp>
+
+#include <cerrno>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
 #endif
+#include <fcntl.h>
 
+#ifdef __EMX__
+# include <cstdlib>
+# include <io.h>
+# define OS2EMX_PLAIN_CHAR
+# define INCL_DOSNMPIPES
+# define INCL_DOSERRORS
+# include <os2.h>
+# include "support/os2_errortable.h"
+#endif
 
-using namespace lyx::support;
+using lyx::support::compare;
+using lyx::support::rtrim;
+using lyx::support::split;
+using lyx::support::unlink;
 
 using std::endl;
+using std::string;
+
+
+#if !defined (HAVE_MKFIFO)
+// We provide a stub class that disables the lyxserver.
+
+void LyXComm::openConnection()
+{}
 
-// provide an empty mkfifo() if we do not have one. This disables the
-// lyxserver.
-#ifndef HAVE_MKFIFO
-int mkfifo(char const * __path, mode_t __mode) {
-       return 0;
+
+void LyXComm::closeConnection()
+{}
+
+
+int LyXComm::startPipe(string const & filename, bool write)
+{
+       return -1;
 }
-#endif
+
+
+void LyXComm::endPipe(int & fd, string const & filename, bool write)
+{}
+
+
+void LyXComm::emergencyCleanup()
+{}
+
+void LyXComm::read_ready()
+{}
+
+
+void LyXComm::send(string const & msg)
+{}
+
+
+#else // defined (HAVE_MKFIFO)
 
 
 void LyXComm::openConnection()
@@ -130,10 +172,9 @@ void LyXComm::closeConnection()
        ready = false;
 }
 
+
 int LyXComm::startPipe(string const & filename, bool write)
 {
-       int fd;
-
 #ifdef __EMX__
        HPIPE os2fd;
        APIRET rc;
@@ -166,7 +207,7 @@ int LyXComm::startPipe(string const & filename, bool write)
        };
        // Imported handles can be used both with OS/2 APIs and emx
        // library functions.
-       fd = _imphandle(os2fd);
+       int const fd = _imphandle(os2fd);
 #else
        if (::access(filename.c_str(), F_OK) == 0) {
                lyxerr << "LyXComm: Pipe " << filename << " already exists.\n"
@@ -181,7 +222,8 @@ int LyXComm::startPipe(string const & filename, bool write)
                       << strerror(errno) << endl;
                return -1;
        };
-       fd = ::open(filename.c_str(), write ? (O_RDWR) : (O_RDONLY|O_NONBLOCK));
+       int const fd = ::open(filename.c_str(),
+                             write ? (O_RDWR) : (O_RDONLY|O_NONBLOCK));
 #endif
 
        if (fd < 0) {
@@ -192,7 +234,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;
@@ -205,7 +247,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__
@@ -339,6 +381,20 @@ void LyXComm::send(string const & msg)
 #endif
 }
 
+#endif // defined (HAVE_MKFIFO)
+
+
+string const LyXComm::inPipeName() const
+{
+       return pipename + string(".in");
+}
+
+
+string const LyXComm::outPipeName() const
+{
+       return pipename + string(".out");
+}
+
 
 // LyXServer class
 
@@ -470,7 +526,7 @@ void LyXServer::callback(LyXServer * serv, string const & msg)
                        // support currently. (Lgb)
 
 
-                       serv->func->dispatch(cmd + ' ' + arg);
+                       serv->func->dispatch(FuncRequest(lyxaction.lookupFunc(cmd), arg));
                        string const rval = serv->func->getMessage();
 
                        //modified june 1999 stefano@zool.su.se: