X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FServer.cpp;h=6a6ed2f837a8be8a57a48dbe5248d01368a32624;hb=f5123ccfa82215030c70561af881175d92244492;hp=08867d837c354d781fe9cbe55f0b205414e0f052;hpb=9919ec3625edb268bf63a91b37c1220bd16c9b02;p=lyx.git diff --git a/src/Server.cpp b/src/Server.cpp index 08867d837c..6a6ed2f837 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -34,16 +34,18 @@ received LyX will inform the client that it's listening its messages, and 'bye' will inform that lyx is closing. - See development/server_monitor.c for an example client. + See development/lyxserver/server_monitor.cpp for an example client. Purpose: implement a client/server lib for LyX */ #include #include "Server.h" + +#include "DispatchResult.h" #include "FuncRequest.h" +#include "LyX.h" #include "LyXAction.h" -#include "LyXFunc.h" #include "frontends/Application.h" @@ -53,7 +55,7 @@ #include "support/lstrings.h" #include "support/os.h" -#include +#include "support/bind.h" #ifdef _WIN32 #include @@ -319,8 +321,8 @@ bool LyXComm::pipeServer() QCoreApplication::postEvent(this, static_cast(event)); // Wait for completion - while (pipe_[i].nbytes && !checkStopServer()) - Sleep(100); + while (pipe_[i].nbytes && !checkStopServer(100)) + ; pipe_[i].pending_io = false; pipe_[i].state = READING_STATE; continue; @@ -354,7 +356,7 @@ bool LyXComm::pipeServer() // We get here when a reader is started // well before a reply is ready, so delay // a bit in order to not burden the cpu. - Sleep(100); + checkStopServer(100); pipe_[i].pending_io = true; continue; } @@ -406,15 +408,17 @@ bool LyXComm::event(QEvent * e) } -bool LyXComm::checkStopServer() +bool LyXComm::checkStopServer(DWORD timeout) { - return WaitForSingleObject(stopserver_, 0) == WAIT_OBJECT_0; + return WaitForSingleObject(stopserver_, timeout) == WAIT_OBJECT_0; } bool LyXComm::startPipe(DWORD index) { pipe_[index].pending_io = false; + pipe_[index].overlap.Offset = 0; + pipe_[index].overlap.OffsetHigh = 0; // Overlapped ConnectNamedPipe should return zero. if (ConnectNamedPipe(pipe_[index].handle, &pipe_[index].overlap)) { @@ -664,8 +668,7 @@ void LyXComm::send(string const & msg) << "\nLyXComm: Resetting connection" << endl; ReleaseMutex(outbuf_mutex_); closeConnection(); - if (!checkStopServer()) - openConnection(); + openConnection(); } } @@ -837,7 +840,7 @@ int LyXComm::startPipe(string const & file, bool write) if (!write) { theApp()->registerSocketCallback(fd, - boost::bind(&LyXComm::read_ready, this)); + bind(&LyXComm::read_ready, this)); } return fd; @@ -985,8 +988,8 @@ void ServerCallback(Server * server, string const & msg) server->callback(msg); } -Server::Server(LyXFunc * f, string const & pipes) - : numclients_(0), func_(f), pipes_(pipes, this, &ServerCallback) +Server::Server(string const & pipes) + : numclients_(0), pipes_(pipes, this, &ServerCallback) {} @@ -1107,17 +1110,19 @@ void Server::callback(string const & msg) // The correct solution would be to have a // specialized (non-gui) BufferView. But how do // we do it now? Probably we should just let it - // connect to the lyxfunc in the single LyXView we + // connect to the lyxfunc in the single GuiView we // support currently. (Lgb) - func_->dispatch(FuncRequest(lyxaction.lookupFunc(cmd), arg)); - string const rval = to_utf8(func_->getMessage()); + FuncRequest const fr(lyxaction.lookupFunc(cmd), arg); + DispatchResult dr; + theApp()->dispatch(fr, dr); + string const rval = to_utf8(dr.message()); // all commands produce an INFO or ERROR message // in the output pipe, even if they do not return // anything. See chapter 4 of Customization doc. string buf; - if (func_->errorStat()) + if (dr.error()) buf = "ERROR:"; else buf = "INFO:";