[rkward-cvs] SF.net SVN: rkward: [2101] branches/KDE4_port/rkward/rbackend

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Oct 22 00:05:56 UTC 2007


Revision: 2101
          http://rkward.svn.sourceforge.net/rkward/?rev=2101&view=rev
Author:   tfry
Date:     2007-10-21 17:05:56 -0700 (Sun, 21 Oct 2007)

Log Message:
-----------
I think I got the basic logic right in RCommandStackModel right, now. Will need to elaborate on this, though

Modified Paths:
--------------
    branches/KDE4_port/rkward/rbackend/rcommandstack.cpp
    branches/KDE4_port/rkward/rbackend/rcommandstack.h
    branches/KDE4_port/rkward/rbackend/rinterface.h

Modified: branches/KDE4_port/rkward/rbackend/rcommandstack.cpp
===================================================================
--- branches/KDE4_port/rkward/rbackend/rcommandstack.cpp	2007-10-21 23:51:43 UTC (rev 2100)
+++ branches/KDE4_port/rkward/rbackend/rcommandstack.cpp	2007-10-22 00:05:56 UTC (rev 2101)
@@ -54,10 +54,12 @@
 	RK_TRACE (RBACKEND);
 	if (!chain) chain = regular_stack;
 
+	RCommandStackModel::getModel ()->aboutToAdd (command);
+
 	chain->commands.append (command);
 	command->parent = chain;
 
-	RCommandStackModel::getModel ()->newCommand ();
+	RCommandStackModel::getModel ()->addComplete (command);
 }
 
 RCommandChain *RCommandStack::startChain (RCommandChain *parent) {
@@ -65,11 +67,13 @@
 	if (!parent) parent = regular_stack;
 
 	RCommandChain *chain = new RCommandChain ();
+	RCommandStackModel::getModel ()->aboutToAdd (chain);
+
 	chain->closed = false;
 	chain->parent = parent;
 	parent->commands.append (chain);
 
-	RCommandStackModel::getModel ()->newChain ();
+	RCommandStackModel::getModel ()->addComplete (chain);
 
 	return chain;
 }
@@ -79,12 +83,12 @@
 	if (!chain) return;
 
 	chain->closed = true;
-	chainStack (chain)->clearFinishedChains ();
 }
 
 RCommand* RCommandStack::currentCommand () {
 	RK_TRACE (RBACKEND);
 
+	clearFinishedChains ();
 	RCommandBase *coc = current_chain;
 	while (coc->chainPointer ()) {
 		current_chain = coc->chainPointer ();
@@ -143,12 +147,11 @@
 	RK_TRACE (RBACKEND);
 
 	if (!isActive ()) return;
-	RCommandBase* popped = current_chain->commands.takeFirst ();
+	RCommandBase* popped = current_chain->commands.first ();
 	RK_ASSERT (popped->commandPointer ());
-
-	RCommandStackModel::getModel ()->commandPop (popped->commandPointer ());
-
-	clearFinishedChains ();
+	RCommandStackModel::getModel ()->aboutToPop (popped->commandPointer ());
+	current_chain->commands.removeFirst ();
+	RCommandStackModel::getModel ()->popComplete (popped->commandPointer ());
 }
 
 void RCommandStack::clearFinishedChains () {
@@ -157,10 +160,11 @@
 	// reached end of chain and chain is closed? walk up
 	while (current_chain->commands.isEmpty () && current_chain->closed && current_chain->parent) {
 		RCommandChain *prev_chain = current_chain;
+		RCommandStackModel::getModel ()->aboutToPop (prev_chain);
 		current_chain->parent->commands.removeFirst ();
 		current_chain = current_chain->parent;
-		RCommandStackModel::getModel ()->chainPop (prev_chain);
 		delete prev_chain;
+		RCommandStackModel::getModel ()->popComplete (prev_chain);
 	}
 }
 
@@ -178,14 +182,23 @@
 	have_mutex_lock = false;
 
 	connect (this, SIGNAL (change()), this, SLOT (relayChange()), Qt::BlockingQueuedConnection);
+	connect (this, SIGNAL (aboutToChange()), this, SLOT (relayAboutToChange()), Qt::BlockingQueuedConnection);
 }
 
 RCommandStackModel::~RCommandStackModel () {
 	RK_TRACE (RBACKEND);
 
 	static_model = 0;
+	RK_ASSERT (!listeners);
 }
 
+void RCommandStackModel::removeListener () {
+	RK_TRACE (RBACKEND);
+qDebug ("remove");
+	--listeners;
+	if (!listeners) unlockMutex ();
+}
+
 QModelIndex RCommandStackModel::index (int row, int column, const QModelIndex& parent) const {
 	RK_ASSERT (listeners > 0);
 	RK_TRACE (RBACKEND);
@@ -309,39 +322,35 @@
 	return QVariant ();
 }
 
-void RCommandStackModel::commandPop (RCommand* popped) {
+void RCommandStackModel::aboutToPop (RCommandBase* popped) {
 	if (!listeners) return;
 	RK_TRACE (RBACKEND);
 
 	RK_ASSERT (RInterface::inRThread ());
 	MUTEX_UNLOCK;	// release the mutex in the R thread, as the main thread will need it.
-	emit (change ());
+	emit (aboutToChange ());
 	MUTEX_LOCK;
 }
 
-void RCommandStackModel::chainPop (RCommandChain* popped) {
+void RCommandStackModel::popComplete (RCommandBase* popped) {
 	if (!listeners) return;
 	RK_TRACE (RBACKEND);
 
-	// chains can be popped from both threads!
-	if (RInterface::inRThread ()) {
-		MUTEX_UNLOCK;
-		emit (change ());
-		MUTEX_LOCK;
-	} else {
-		relayChange ();
-	}
+	RK_ASSERT (RInterface::inRThread ());
+	MUTEX_UNLOCK;	// release the mutex in the R thread, as the main thread will need it.
+	emit (change ());
+	MUTEX_LOCK;
 }
 
-void RCommandStackModel::newCommand () {
+void RCommandStackModel::aboutToAdd (RCommandBase* added) {
 	if (!listeners) return;
 	RK_TRACE (RBACKEND);
 
 	RK_ASSERT (!RInterface::inRThread ());
-	relayChange ();
+	relayAboutToChange ();
 }
 
-void RCommandStackModel::newChain () {
+void RCommandStackModel::addComplete (RCommandBase* added) {
 	if (!listeners) return;
 	RK_TRACE (RBACKEND);
 
@@ -380,9 +389,19 @@
 	RK_ASSERT (!RInterface::inRThread ());
 // TODO: for now we update everything on every change
 // TODO: will need mutex locking for real solution
-	emit (layoutAboutToBeChanged ());
+
 	emit (layoutChanged ());
 }
 
+void RCommandStackModel::relayAboutToChange () {
+	RK_TRACE (RBACKEND);
 
+	RK_ASSERT (!RInterface::inRThread ());
+// TODO: for now we update everything on every change
+// TODO: will need mutex locking for real solution
+
+	emit (layoutAboutToBeChanged ());
+}
+
+
 #include "rcommandstack.moc"

Modified: branches/KDE4_port/rkward/rbackend/rcommandstack.h
===================================================================
--- branches/KDE4_port/rkward/rbackend/rcommandstack.h	2007-10-21 23:51:43 UTC (rev 2100)
+++ branches/KDE4_port/rkward/rbackend/rcommandstack.h	2007-10-22 00:05:56 UTC (rev 2101)
@@ -107,17 +107,19 @@
 	static RCommandStackModel* getModel () { return static_model; };
 
 	void addListener () { ++listeners; };
-	void removeListener () { --listeners; };
+	void removeListener ();
 
-	void commandPop (RCommand* popped);
-	void chainPop (RCommandChain* popped);
-	void newCommand ();
-	void newChain ();
+	void aboutToPop (RCommandBase* popped);
+	void popComplete (RCommandBase* popped);
+	void aboutToAdd (RCommandBase* added);
+	void addComplete (RCommandBase* added);
 private slots:
 	void unlockMutex ();
+	void relayAboutToChange ();
 	void relayChange ();
 signals:
 	void change ();
+	void aboutToChange ();
 private:
 	void lockMutex () const;
 	int listeners;

Modified: branches/KDE4_port/rkward/rbackend/rinterface.h
===================================================================
--- branches/KDE4_port/rkward/rbackend/rinterface.h	2007-10-21 23:51:43 UTC (rev 2100)
+++ branches/KDE4_port/rkward/rbackend/rinterface.h	2007-10-22 00:05:56 UTC (rev 2101)
@@ -27,7 +27,7 @@
 
 //#define DEBUG_MUTEX
 #ifdef DEBUG_MUTEX
-#define MUTEX_LOCK qDebug ("mutex locks: %d, locked in %s, %s, %d", ++RInterface::mutex_counter, __FILE__, __FUNCTION__, __LINE__); RInterface::mutex.lock ();
+#define MUTEX_LOCK RInterface::mutex.lock (); qDebug ("mutex locks: %d, locked in %s, %s, %d", ++RInterface::mutex_counter, __FILE__, __FUNCTION__, __LINE__); 
 #define MUTEX_UNLOCK qDebug ("mutex locks: %d, unlocked in %s, %s, %d", --RInterface::mutex_counter, __FILE__, __FUNCTION__, __LINE__); RInterface::mutex.unlock ();
 #else
 #define MUTEX_LOCK RInterface::mutex.lock ();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list