Author: locilka Date: Wed Mar 5 10:23:40 2008 New Revision: 45198 URL: http://svn.opensuse.org/viewcvs/yast?rev=45198&view=rev Log: - Extended .process agent with 'buffer_empty' function that returns whether the stdout buffer is empty (needed for backup). - 2.16.40 Modified: trunk/core/VERSION trunk/core/agent-process/conf/process.scr trunk/core/agent-process/src/Process.cc trunk/core/agent-process/src/Process.h trunk/core/agent-process/src/ProcessAgent.cc trunk/core/package/yast2-core.changes Modified: trunk/core/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/VERSION?rev=45198&r1=45197&r2=45198&view=diff ============================================================================== --- trunk/core/VERSION (original) +++ trunk/core/VERSION Wed Mar 5 10:23:40 2008 @@ -1 +1 @@ -2.16.39 +2.16.40 Modified: trunk/core/agent-process/conf/process.scr URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-process/conf/process.scr?rev=45198&r1=45197&r2=45198&view=diff ============================================================================== --- trunk/core/agent-process/conf/process.scr (original) +++ trunk/core/agent-process/conf/process.scr Wed Mar 5 10:23:40 2008 @@ -48,11 +48,18 @@ * (nil) * * // read complete output + * // check whether the buffer (output) is empty + * // (even if process is dead, buffer might contain something) * `Write(.process, 14900,"the first line\nthe second line\n") * (true) + * // buffer is not empty + * `Read (.process.buffer_empty, 14900) + * (false) * `Read(.process.read, 14900) * ("the first line\nthe second line\n") - * + * // buffer is empty after .read + * `Read (.process.buffer_empty, 14900) + * (true) * // close input/output * `Read(.process.running, 14900) * (true) Modified: trunk/core/agent-process/src/Process.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-process/src/Process.cc?rev=45198&r1=45197&r2=45198&view=diff ============================================================================== --- trunk/core/agent-process/src/Process.cc (original) +++ trunk/core/agent-process/src/Process.cc Wed Mar 5 10:23:40 2008 @@ -64,15 +64,28 @@ return ExternalProgram::kill(); } -// read a line from stdout -std::string Process::readLine() +void Process::BufferNewStdoutLines () { const std::string new_output = receiveUpto('\n'); stdout_buffer += new_output; +} + +// read a line from stdout +std::string Process::readLine() +{ + BufferNewStdoutLines(); return GetLineFromBuffer(stdout_buffer); } +// return whether stdout buffer contains any (finished) line +bool Process::anyLineInStdout() +{ + BufferNewStdoutLines(); + + return IsAnyLineInBuffer(stdout_buffer); +} + void Process::readStdoutToBuffer() { const size_t b_size = 4096; @@ -144,6 +157,12 @@ return std::string(); } +// returns whether the buffer is empty +bool Process::IsAnyLineInBuffer(const std::string &buffer) +{ + return buffer.empty(); +} + // read a line from stderr std::string Process::readErrLine() { Modified: trunk/core/agent-process/src/Process.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-process/src/Process.h?rev=45198&r1=45197&r2=45198&view=diff ============================================================================== --- trunk/core/agent-process/src/Process.h (original) +++ trunk/core/agent-process/src/Process.h Wed Mar 5 10:23:40 2008 @@ -60,6 +60,13 @@ // a helper function std::string GetLineFromBuffer(std::string &buffer); + // a helper function + // reads the new stdout lines and adds them to stdout buffer + void BufferNewStdoutLines(); + + // checks emptines of the stdout buffer + bool IsAnyLineInBuffer(const std::string &buffer); + public: /** @@ -134,6 +141,10 @@ */ void readStderrToBuffer(); + /** + * Read whether there are some buffered lines + */ + bool anyLineInStdout(); }; #endif // Process_h Modified: trunk/core/agent-process/src/ProcessAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/agent-process/src/ProcessAgent.cc?rev=45198&r1=45197&r2=45198&view=diff ============================================================================== --- trunk/core/agent-process/src/ProcessAgent.cc (original) +++ trunk/core/agent-process/src/ProcessAgent.cc Wed Mar 5 10:23:40 2008 @@ -227,6 +227,16 @@ return YCPInteger(proc->second->close()); } } + else if (cmd == "buffer_empty") + { + /** + * @builtin Read (.process.buffer_empty, integer id) -> boolean + * Returns boolean whether the stdout buffer is empty, if buffer is not empty, false is returned. + * + * @example Read (.process.buffer_empty, 12345) -> false + */ + return YCPBoolean (proc->second->anyLineInStdout()); + } y2error("Wrong path '%s' in Read().", path->toString().c_str()); return YCPNull(); Modified: trunk/core/package/yast2-core.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/package/yast2-core.changes?rev=45198&r1=45197&r2=45198&view=diff ============================================================================== --- trunk/core/package/yast2-core.changes (original) +++ trunk/core/package/yast2-core.changes Wed Mar 5 10:23:40 2008 @@ -1,4 +1,11 @@ ------------------------------------------------------------------- +Wed Mar 5 09:58:00 CET 2008 - locilka@suse.cz + +- Extended .process agent with 'buffer_empty' function that returns + whether the stdout buffer is empty (needed for backup). +- 2.16.40 + +------------------------------------------------------------------- Tue Mar 4 13:30:39 CET 2008 - mvidner@suse.cz - Do not stop registering agents after UnregisterAgent (bnc#365116). -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org