[education/rkward/kf5] rkward/rbackend: Modernize output flush handling

Thomas Friedrichsmeier null at kde.org
Wed Apr 10 16:12:08 BST 2024


Git commit 5627048a28e5afd56ae8ed40bdaf7b4bbdcf3f9c by Thomas Friedrichsmeier.
Committed on 06/04/2024 at 12:39.
Pushed by tfry into branch 'kf5'.

Modernize output flush handling

M  +3    -17   rkward/rbackend/rkrinterface.cpp
M  +1    -3    rkward/rbackend/rkrinterface.h

https://invent.kde.org/education/rkward/-/commit/5627048a28e5afd56ae8ed40bdaf7b4bbdcf3f9c

diff --git a/rkward/rbackend/rkrinterface.cpp b/rkward/rbackend/rkrinterface.cpp
index a9ec01280..16a4f9215 100644
--- a/rkward/rbackend/rkrinterface.cpp
+++ b/rkward/rbackend/rkrinterface.cpp
@@ -1,6 +1,6 @@
 /*
 rkrinterface.cpp - This file is part of RKWard (https://rkward.kde.org). Created: Fri Nov 1 2002
-SPDX-FileCopyrightText: 2002-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2002-2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -79,7 +79,6 @@ RInterface::RInterface () {
 	previously_idle = false;
 	locked = 0;
 	backend_dead = false;
-	flush_timer_id = 0;
 	dummy_command_on_stack = nullptr;
 
 	// create a fake init command
@@ -322,8 +321,8 @@ void RInterface::handleRequest (RBackendRequest* request) {
 	RK_TRACE (RBACKEND);
 
 	if (request->type == RBackendRequest::OutputStartedNotification) {
-		RK_ASSERT (flush_timer_id == 0);
-		flush_timer_id = startTimer (FLUSH_INTERVAL);	// calls flushOutput (false); see timerEvent ()
+		// We do _not_ flush the output right away, as it is likely to arrive in minuscule chunks. But we _do_ want to check, soon
+		QTimer::singleShot(FLUSH_INTERVAL, [this]() { flushOutput(false); });
 		RKRBackendProtocolFrontend::setRequestCompleted (request);
 		return;
 	}
@@ -444,24 +443,11 @@ void RInterface::handleRequest (RBackendRequest* request) {
 	}
 }
 
-void RInterface::timerEvent (QTimerEvent *) {
-// do not trace. called periodically
-	flushOutput (false);
-}
-
 void RInterface::flushOutput (bool forced) {
 // do not trace. called periodically
 //	RK_TRACE (RBACKEND);
 	const ROutputList list = RKRBackendProtocolFrontend::instance ()->flushOutput (forced);
 
-	// this must come _after_ the output has been flushed.
-	if (forced || !list.isEmpty ()) {
-		if (flush_timer_id != 0) {
-			killTimer (flush_timer_id);
-			flush_timer_id = 0;
-		}
-	}
-
 	for (ROutput *output : list) {
 		if (all_current_commands.isEmpty ()) {
 			RK_DEBUG (RBACKEND, DL_DEBUG, "output without receiver'%s'", qPrintable (output->output));
diff --git a/rkward/rbackend/rkrinterface.h b/rkward/rbackend/rkrinterface.h
index 17ff3bcf7..ea936115c 100644
--- a/rkward/rbackend/rkrinterface.h
+++ b/rkward/rbackend/rkrinterface.h
@@ -1,6 +1,6 @@
 /*
 rkrinterface.h - This file is part of the RKWard project. Created: Fri Nov 1 2002
-SPDX-FileCopyrightText: 2002-2020 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2002-2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
 SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
 SPDX-License-Identifier: GPL-2.0-or-later
 */
@@ -82,8 +82,6 @@ not be interrupted. */
 	static bool isNaReal (double value) { return na_real == value; };
 	static bool isNaInt (int value) { return na_int == value; };
 private:
-	void timerEvent (QTimerEvent *) override;
-	int flush_timer_id;
 /** Calls RThread::flushOutput(), and takes care of adding the output to all applicable commands */
 	void flushOutput (bool forced);
 /** pointer to the RThread */



More information about the rkward-tracker mailing list