X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxserver.C;h=719412757e8930080993a5691f35a3dabbed1ee7;hb=a858be7332e331e0244e4dba7b0931b6072ffd3d;hp=903e5a1ae06c95645fae673f6fabed538ba00122;hpb=0eccdd1c3613e5170deb77b22174dd0afde833e9;p=lyx.git diff --git a/src/lyxserver.C b/src/lyxserver.C index 903e5a1ae0..719412757e 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -5,7 +5,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-1998 The LyX Team. + * Copyright 1995-1999 The LyX Team. * * ======================================================*/ @@ -53,7 +53,7 @@ #include "lyxserver.h" #include "lyxfunc.h" #include "lyx_main.h" -#include "error.h" +#include "debug.h" #include "support/lstrings.h" #ifdef __EMX__ @@ -79,15 +79,19 @@ int mkfifo( char *__path, mode_t __mode ) { extern LyXAction lyxaction; +// C wrapper +extern "C" void C_LyXComm_callback(int fd, void *v); + + // LyXComm class // Open pipes void LyXComm::openConnection() { - lyxerr.debug("LyXComm: Opening connection", Error::LYXSERVER); + lyxerr[Debug::LYXSERVER] << "LyXComm: Opening connection" << endl; // If we are up, that's an error if (ready) { - lyxerr.print("LyXComm: Already connected"); + lyxerr << "LyXComm: Already connected" << endl; return; } // We assume that we don't make it @@ -111,32 +115,32 @@ void LyXComm::openConnection() { #else if (access(tmp.c_str(), F_OK) == 0) { #endif - lyxerr.print("LyXComm: Pipe " + tmp + " already exists."); - lyxerr.print("If no other LyX program is active, please delete" - " the pipe by hand and try again."); + lyxerr << "LyXComm: Pipe " << tmp << " already exists.\n" + << "If no other LyX program is active, please delete" + " the pipe by hand and try again." << endl; pipename = string(); return; } #ifndef __EMX__ if (mkfifo(tmp.c_str(), 0600) < 0) { - lyxerr.print("LyXComm: Could not create pipe " + tmp); - lyxerr.print(strerror(errno)); + lyxerr << "LyXComm: Could not create pipe " << tmp << '\n' + << strerror(errno) << endl; return; }; infd = open(tmp.c_str(), O_RDONLY|O_NONBLOCK); #else if (rc != NO_ERROR) { errnum = TranslateOS2Error(rc); - lyxerr.print("LyXComm: Could not create pipe " + tmp); - lyxerr.print(strerror(errnum)); + lyxerr <<"LyXComm: Could not create pipe " << tmp + << strerror(errnum) << endl; return; }; // Listen to it. rc = DosConnectNPipe(fd); if (rc != NO_ERROR && rc != ERROR_PIPE_NOT_CONNECTED) { errnum = TranslateOS2Error(rc); - lyxerr.print("LyXComm: Could not create pipe " + tmp); - lyxerr.print(strerror(errnum)); + lyxerr <<"LyXComm: Could not create pipe " + tmp); + lyxerr < -1) { - fl_remove_io_callback(infd, FL_READ, callback); + fl_remove_io_callback(infd, FL_READ, C_LyXComm_callback); string tmp = pipename + ".in"; #ifdef __EMX__ // Notify the operating system. rc = DosDisConnectNPipe(infd); if (rc != NO_ERROR) { errnum = TranslateOS2Error(rc); - lyxerr.print("LyXComm: Could not disconnect pipe " + tmp); - lyxerr.print(strerror(errnum)); + lyxerr << "LyXComm: Could not disconnect pipe " << tmp + << '\n' << strerror(errnum) << endl; return; } #endif if (close(infd) < 0) { - lyxerr.print("LyXComm: Could not close pipe " + tmp); - lyxerr.print(strerror(errno)); + lyxerr << "LyXComm: Could not close pipe " << tmp + << '\n' << strerror(errno) << endl; } #ifndef __EMX__ // OS/2 named pipes will be automatically removed. if (unlink(tmp.c_str()) < 0){ - lyxerr.print("LyXComm: Could not remove pipe " + tmp); - lyxerr.print(strerror(errno)); + lyxerr << "LyXComm: Could not remove pipe " << tmp + << '\n' << strerror(errno) << endl; }; #endif } @@ -261,19 +267,19 @@ void LyXComm::closeConnection() { rc = DosDisConnectNPipe(outfd); if (rc != NO_ERROR) { errnum = TranslateOS2Error(rc); - lyxerr.print("LyXComm: Could not disconnect pipe " + tmp); - lyxerr.print(strerror(errnum)); + lyxerr << "LyXComm: Could not disconnect pipe " << tmp + << '\n' << strerror(errnum) << endl; return; } #endif if (close(outfd) < 0) { - lyxerr.print("LyXComm: Could not close pipe " + tmp); - lyxerr.print(strerror(errno)); + lyxerr << "LyXComm: Could not close pipe " << tmp + << '\n' << strerror(errno) << endl; } #ifndef __EMX__ if (unlink(tmp.c_str()) < 0){ - lyxerr.print("LyXComm: Could not remove pipe " + tmp); - lyxerr.print(strerror(errno)); + lyxerr << "LyXComm: Could not remove pipe " << tmp + << '\n' << strerror(errno) << endl; }; #endif } @@ -285,8 +291,8 @@ void LyXComm::callback(int fd, void *v) { LyXComm * c = (LyXComm *) v; - if (lyxerr.debugging(Error::LYXSERVER)) { - lyxerr.print(string("LyXComm: Receiving from fd ") + tostr(fd)); + if (lyxerr.debugging(Debug::LYXSERVER)) { + lyxerr << "LyXComm: Receiving from fd " << fd << endl; } const int CMDBUFLEN = 100; @@ -312,10 +318,10 @@ void LyXComm::callback(int fd, void *v) // split() grabs the entire string if // the delim /wasn't/ found. ?:-P lsbuf=split(lsbuf, cmd,'\n'); - lyxerr.debug(string("LyXComm: status:") - + tostr(status) + ", lsbuf:" + lsbuf - + ", cmd:" + cmd, - Error::LYXSERVER); + lyxerr[Debug::LYXSERVER] + << "LyXComm: status:" << status + << ", lsbuf:" << lsbuf + << ", cmd:" << cmd << endl; if(!cmd.empty()) c->clientcb(c->client, cmd); //\n or not \n? @@ -330,12 +336,12 @@ void LyXComm::callback(int fd, void *v) } if(errno != 0 ) { - lyxerr.print(string("LyXComm: ") + strerror(errno)); + lyxerr << "LyXComm: " << strerror(errno) << endl; if(!lsbuf.empty()) { - lyxerr.print("LyxComm: truncated command: " - + lsbuf); - lsbuf.erase(); + lyxerr << "LyxComm: truncated command: " + << lsbuf << endl; + lsbuf.clear(); } break; // reset connection } @@ -344,25 +350,33 @@ void LyXComm::callback(int fd, void *v) c->openConnection(); errno=0; } + +extern "C" void C_LyXComm_callback(int fd, void *v) +{ + LyXComm::callback(fd, v); +} + void LyXComm::send(string const & msg) { if (msg.empty()) { - lyxerr.print("LyXComm: Request to send empty string. Ignoring."); + lyxerr << "LyXComm: Request to send empty string. Ignoring." + << endl; return; } - if (lyxerr.debugging(Error::LYXSERVER)) { - lyxerr.print("LyXComm: Sending '" + msg + '\''); + if (lyxerr.debugging(Debug::LYXSERVER)) { + lyxerr << "LyXComm: Sending '" << msg << '\'' << endl; } if (pipename.empty()) return; if (!ready) { - lyxerr.print("LyXComm: Pipes are closed. Could not send "+ msg); + lyxerr << "LyXComm: Pipes are closed. Could not send " + << msg << endl; } else if (write(outfd, msg.c_str(), msg.length()) < 0) { - lyxerr.print("LyXComm: Error sending message: " + msg); - lyxerr.print(strerror(errno)); - lyxerr.print("LyXComm: Resetting connection"); + lyxerr << "LyXComm: Error sending message: " << msg + << '\n' << strerror(errno) + << "\nLyXComm: Resetting connection" << endl; closeConnection(); openConnection(); } @@ -372,8 +386,8 @@ void LyXComm::send(string const & msg) { rc = DosResetBuffer(outfd); // To avoid synchronization problems. if (rc != NO_ERROR) { errnum = TranslateOS2Error(rc); - lyxerr.print("LyXComm: Message could not be flushed: " +msg); - lyxerr.print(strerror(errnum)); + lyxerr <<"LyXComm: Message could not be flushed: " +msg); + lyxerr <numclients==MAX_CLIENTS){ //paranoid check - lyxerr.debug("LyXServer: too many clients...", Error::LYXSERVER); + lyxerr[Debug::LYXSERVER] + << "LyXServer: too many clients..." + << endl; return; } int i=0; //find place in clients[] @@ -462,7 +482,9 @@ void LyXServer::callback(LyXServer * serv, string const & msg) serv->clients[i] = client; serv->numclients++; buf = "LYXSRV:" + client + ":hello\n"; - lyxerr.debug("LyXServer: Greeting " + client, Error::LYXSERVER); + lyxerr[Debug::LYXSERVER] + << "LyXServer: Greeting " + << client << endl; serv->pipes.send(buf); } else if (cmd == "bye") { // If clients==0 maybe we should reset the pipes @@ -473,15 +495,19 @@ void LyXServer::callback(LyXServer * serv, string const & msg) } if (inumclients) { serv->numclients--; - serv->clients[i].erase(); - lyxerr.debug("LyXServer: Client " + client + " said goodbye", - Error::LYXSERVER); + serv->clients[i].clear(); + lyxerr[Debug::LYXSERVER] + << "LyXServer: Client " + << client << " said goodbye" + << endl; } else { - lyxerr.debug("LyXServer: ignoring bye messge from unregistered client" + - client + "\n", Error::LYXSERVER); + lyxerr[Debug::LYXSERVER] + << "LyXServer: ignoring bye messge from unregistered client" + << client << endl; } } else { - lyxerr.print("LyXServer: Undefined server command " + cmd + "."); + lyxerr <<"LyXServer: Undefined server command " + << cmd << "." << endl; } return; }