From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- lskat/lskatproc/KInputChildProcess.cpp | 106 +++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 lskat/lskatproc/KInputChildProcess.cpp (limited to 'lskat/lskatproc/KInputChildProcess.cpp') diff --git a/lskat/lskatproc/KInputChildProcess.cpp b/lskat/lskatproc/KInputChildProcess.cpp new file mode 100644 index 00000000..a821aa7a --- /dev/null +++ b/lskat/lskatproc/KInputChildProcess.cpp @@ -0,0 +1,106 @@ +/*************************************************************************** + KInputChildProcess.cpp - description + ------------------- + begin : Tue May 2 2000 + copyright : (C) 2000 by Martin Heni + email : martin@heni-online.de + ***************************************************************************/ +#include +#include +#include +#include +#include + +#include "KInputChildProcess.h" +#include "KInputChildProcess.moc" + + +KInputChildProcess::~KInputChildProcess() +{ + delete buffer; + delete childConnect; +} +KInputChildProcess::KInputChildProcess(int size_buffer) + : QObject(0,0) +{ + buffersize=size_buffer; + if (buffersize<1) buffersize=1024; + buffer=new char[buffersize]; + inputbuffer=""; + terminateChild=false; +} +bool KInputChildProcess::exec() +{ + int pos; + QString s; + + childConnect=new KChildConnect; + if (!childConnect) return false; + connect(childConnect,SIGNAL(signalReceiveMsg(KEMessage *,int)), + this,SLOT(slotReceiveMsg(KEMessage *,int))); + do + { + // Wait for input + if (feof(stdin)) + { + sleep(1); + continue; + } + + if (!fgets(buffer,buffersize,stdin) ) + { + continue; + } + s=buffer; + s=inputbuffer+s; + // printf("ChildABC '%s'\n",(const char *)s); + // fflush(stdout); + pos=s.findRev(KEMESSAGE_CR); + if (pos<0) + { + inputbuffer=s; + } + else if (pos+KEMESSAGE_CR.length()==s.length()) + { + // CR at the end...calling receive + childConnect->Receive(s); + } + else + { + inputbuffer=s.right(s.length()-pos-KEMESSAGE_CR.length()); + s=s.left(pos+KEMESSAGE_CR.length()); + // printf("s='%s' in='%s'\n",(const char *)s,(const char *)inputbuffer); + childConnect->Receive(s); + } + }while(!terminateChild); + return true; +} + +void KInputChildProcess::Terminate() +{ + terminateChild=true; +} +bool KInputChildProcess::IsTerminated() +{ + return terminateChild; +} + +bool KInputChildProcess::ReceiveMsg(KEMessage *msg,int id) +{ + return false; +} +void KInputChildProcess::slotReceiveMsg(KEMessage *msg,int id) +{ + if (!ReceiveMsg(msg,id)) // made for virtual override + { + // otherwise emit signal + emit signalReceiveMsg(msg,id); + } +} +bool KInputChildProcess::SendMsg(KEMessage *msg) +{ + if (childConnect) return childConnect->SendMsg(msg); + return false; +} + + -- cgit v1.2.1