[rkward-cvs] SF.net SVN: rkward:[3180] branches/2010_10_18_backend_restructuring_branch/ rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Sun Nov 7 12:22:08 UTC 2010


Revision: 3180
          http://rkward.svn.sourceforge.net/rkward/?rev=3180&view=rev
Author:   tfry
Date:     2010-11-07 12:22:07 +0000 (Sun, 07 Nov 2010)

Log Message:
-----------
Yet more dividing frontend and backend apart.

Modified Paths:
--------------
    branches/2010_10_18_backend_restructuring_branch/rkward/agents/showedittextfileagent.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/core/rkvariable.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/CMakeLists.txt
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrsupport.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.h

Added Paths:
-----------
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.h
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.cpp
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.h

Removed Paths:
-------------
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol.h

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/agents/showedittextfileagent.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/agents/showedittextfileagent.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/agents/showedittextfileagent.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -28,7 +28,7 @@
 
 #include "../windows/rkcommandeditorwindow.h"
 #include "../rbackend/rinterface.h"
-#include "../rbackend/rkrbackendprotocol.h"
+#include "../rbackend/rkrbackendprotocol_frontend.h"
 #include "../windows/rkworkplace.h"
 #include "../rkglobals.h"
 #include "../rkward.h"

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/core/rkvariable.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/core/rkvariable.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/core/rkvariable.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -19,7 +19,6 @@
 #include <qstringlist.h>
 #include "float.h"
 #include "math.h"
-#include "limits.h"
 
 #include "rcontainerobject.h"
 #include "robjectlist.h"
@@ -161,7 +160,7 @@
 			QVector<double> dd;
 			dd.reserve (len);
 			for (unsigned int i = 0; i < len; ++i) {
-				if (cdata->getIntVector ()[i] == INT_MIN) dd[i] = NAN;
+				if (RInterface::isNaInt (cdata->getIntVector ()[i])) dd[i] = NAN;
 				else dd[i] = (double) cdata->getIntVector ()[i];
 			}
 			setNumericFromR (0, getLength () - 1, dd);

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/CMakeLists.txt
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/CMakeLists.txt	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/CMakeLists.txt	2010-11-07 12:22:07 UTC (rev 3180)
@@ -26,6 +26,7 @@
 	rkstructuregetter.cpp
 	rkrbackendprotocol_backend.cpp
 	rkrbackendprotocol_frontend.cpp
+	rkrbackendprotocol_shared.cpp
 )
 
 

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -19,6 +19,7 @@
 #include "rcommandreceiver.h"
 #include "rinterface.h"
 #include "../windows/rkcommandlog.h"
+#include "rkrbackendprotocol_shared.h"
 
 #include "../debug.h"
 #include "../rkglobals.h"
@@ -167,43 +168,25 @@
 	return ret;
 }
 
-
-
-RCommandProxy::RCommandProxy (RCommand *from) : RData () {
+void RCommand::mergeAndDeleteProxy (RCommandProxy *proxy) {
 	RK_TRACE (RBACKEND);
-	RK_ASSERT (from);
 
-	command = from->_command;
-	type = from->_type;
-	id = from->_id;
-	status = from->status;
-	RK_ASSERT (status == 0);	// Initialization from an already touched command is not a real problem, but certainly no expected usage
-	RK_ASSERT (from->getDataType () == RData::NoData);
-}
+	RK_ASSERT (proxy);
+	RK_ASSERT (proxy->id == _id);
+	RK_ASSERT (proxy->type == _type);
 
-RCommandProxy::RCommandProxy (const QString &command, int type) {
-	RK_TRACE (RBACKEND);
-
-	RCommandProxy::command = command;
-	RCommandProxy::type = type;
-	RK_ASSERT (type & RCommand::Internal);
-	id = -1;
-	status = 0;
+	status = proxy->status;
+	swallowData (*proxy);
+	delete proxy;
 }
 
-RCommandProxy::~RCommandProxy () {
+RCommandProxy* RCommand::makeProxy () const {
 	RK_TRACE (RBACKEND);
+	RK_ASSERT (status == 0);	// Initialization from an already touched command is not a real problem, but certainly no expected usage
+	RK_ASSERT (getDataType () == RData::NoData);
 
-	RK_ASSERT ((type & RCommand::Internal) || (getDataType () == RData::NoData));
+	RCommandProxy *ret = new RCommandProxy (_command, _type);
+	ret->id = _id,
+	ret->status = status;
+	return ret;
 }
-
-void RCommandProxy::mergeAndDelete (RCommand *to) {
-	RK_TRACE (RBACKEND);
-	RK_ASSERT (to);
-	RK_ASSERT (to->_id == id);
-	RK_ASSERT (to->_type == type);
-
-	to->status = status;
-	to->swallowData (*this);
-	delete this;
-}

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rcommand.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -95,7 +95,6 @@
 	kept around very long, so they should not be a memory issue.
   *@author Thomas Friedrichsmeier
   */
-  
 class RCommand : public RData, public RCommandBase {
 public:
 /** constructs an RCommand.
@@ -187,8 +186,11 @@
 	ROutputList &getOutput () { return output_list; };
 /** modify the command string. DO NOT CALL THIS after the command has been submitted! */
 	void setCommand (const QString &command) { _command = command; };
+
+/** creates a proxy for this RCommand */
+	RCommandProxy* makeProxy () const;
+	void mergeAndDeleteProxy (RCommandProxy *proxy);
 private:
-friend class RCommandProxy;
 friend class RInterface;
 friend class RCommandStack;
 friend class RCommandStackModel;
@@ -207,22 +209,4 @@
 	RCommandReceiver *receivers[MAX_RECEIVERS_PER_RCOMMAND];
 };
 
-/** This is a reduced version of an RCommand, intended for use in the R backend. */
-class RCommandProxy : public RData {
-public:
-/** creates a proxy for the given RCommand */
-	RCommandProxy (RCommand *from);
-	~RCommandProxy ();
-/** update the given RCommand with the status / data of the proxy command. */
-	void mergeAndDelete (RCommand *to);
-protected:
-friend class RKRBackend;
-	RCommandProxy (const QString &command, int type);
-public:		// all these are public for technical reasons, only.
-	QString command;
-	int type;
-	int id;
-	int status;
-};
-
 #endif

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -1,5 +1,5 @@
 /***************************************************************************
-                          rembedinternal  -  description
+                          rkrbackend  -  description
                              -------------------
     begin                : Sun Jul 25 2004
     copyright            : (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 by Thomas Friedrichsmeier
@@ -17,7 +17,7 @@
 
 #include "rembedinternal.h"
 
-// static
+// statics
 RKRBackend *RKRBackend::this_pointer = 0;
 RKRBackend::RKReplStatus RKRBackend::repl_status = { QByteArray (), 0, true, 0, 0, RKRBackend::RKReplStatus::NoUserCommand, 0, false, false };
 void* RKRBackend::default_global_context = 0;
@@ -107,7 +107,6 @@
 #include <R_ext/eventloop.h>
 }
 
-#include "../rkglobals.h"
 #include "rdata.h"
 
 extern SEXP RKWard_RData_Tag;
@@ -567,8 +566,6 @@
 
 // ############## R Standard callback overrides END ####################
 
-char *RKRBackend::na_char_internal = new char;
-
 RKRBackend::RKRBackend () {
 	RK_TRACE (RBACKEND);
 
@@ -841,7 +838,10 @@
 	R_Interactive = (Rboolean) TRUE;
 #endif
 
-	RKGlobals::na_double = NA_REAL;
+	RBackendRequest req (false, RBackendRequest::SetParamsFromBackend);
+	req.params["na_real"] = NA_REAL;	// may not be initialized before setup_Rmainloop!
+	req.params["na_int"] = NA_INTEGER;
+	handleRequest (&req);
 
 	RKWard_RData_Tag = Rf_install ("RKWard_RData_Tag");
 	R_LastvalueSymbol = Rf_install (".Last.value");

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.h	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rembedinternal.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -1,5 +1,5 @@
 /***************************************************************************
-                          rembedinternal  -  description
+                          rkrbackend  -  description
                              -------------------
     begin                : Sun Jul 25 2004
     copyright            : (C) 2004, 2005, 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
@@ -28,7 +28,7 @@
 
 #include "rcommand.h"
 #include "rcommandstack.h"
-#include "rkrbackendprotocol.h"
+#include "rkrbackendprotocol_backend.h"
 
 #ifdef Q_WS_WIN
 extern "C" {
@@ -126,7 +126,6 @@
 
 /** only one instance of this class may be around. This pointer keeps the reference to it, for interfacing to from C to C++ */
 	static RKRBackend *this_pointer;
-	static char *na_char_internal;
 	static void tryToDoEmergencySave ();
 	bool r_running;
 /** Check whether the runtime version of R is at least the given version. Valid only *after* startR() has been called! */

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -18,7 +18,7 @@
 #include "rinterface.h"
 
 #include "rcommandstack.h"
-#include "rkrbackendprotocol.h"
+#include "rkrbackendprotocol_frontend.h"
 #include "../rkward.h"
 #include "../settings/rksettingsmoduler.h"
 #include "../settings/rksettingsmodulegeneral.h"
@@ -67,6 +67,10 @@
 #define SET_RUNTIME_OPTS 3
 #define STARTUP_PHASE2_COMPLETE 4
 
+// statics
+double RInterface::na_real;
+int RInterface::na_int;
+
 RInterface::RInterface () {
 	RK_TRACE (RBACKEND);
 	
@@ -149,7 +153,7 @@
 
 				// notify ourselves...
 				popPreviousCommand ();
-				handleCommandOut (new RCommandProxy (command));
+				handleCommandOut (command->makeProxy ());
 				return;
 			}
 
@@ -177,7 +181,7 @@
 	RK_ASSERT (proxy);
 	RK_ASSERT (previous_command);
 	RCommand* command = previous_command;
-	proxy->mergeAndDelete (command);
+	command->mergeAndDeleteProxy (proxy);
 
 	#ifdef RKWARD_DEBUG
 		int dl = DL_WARNING;		// failed application commands are an issue worth reporting, failed user commands are not
@@ -227,7 +231,7 @@
 	flushOutput (true);
 	RCommandProxy *proxy = 0;
 	if (command) {
-		proxy = new RCommandProxy (command);
+		proxy = command->makeProxy ();
 
 		RK_DO (qDebug ("running command: %s", command->command ().toLatin1().data ()), RBACKEND, DL_DEBUG);
 		command->status |= RCommand::Running;
@@ -682,6 +686,9 @@
 			filename = KFileDialog::getOpenFileName ();
 		}
 		request->params["result"] = QVariant (filename);
+	} else if (type == RBackendRequest::SetParamsFromBackend) {
+			na_real = request->params["na_real"].toDouble ();
+			na_int = request->params["na_int"].toInt ();
 	} else if (type == RBackendRequest::BackendExit) {
 		QString message = request->params["message"].toString ();
 		message += i18n ("\nIt will be shut down immediately. This means, you can not use any more functions that rely on the R backend. I.e. you can do hardly anything at all, not even save the workspace (but if you're lucky, R already did that). What you can do, however, is save any open command-files, the output, or copy data out of open data editors. Quit RKWard after that.\nSince this should never happen, please write a mail to rkward-devel at lists.sourceforge.net, and tell us, what you were trying to do, when this happened. Sorry!");

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.h	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rinterface.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -72,6 +72,8 @@
 
 	bool backendIsDead () { return backend_dead; };
 	bool backendIsIdle ();
+	static bool isNaReal (double value) { return na_real == value; };
+	static bool isNaInt (int value) { return na_int == value; };
 private slots:
 /** called periodically to flush output buffer in RThread */
 	void flushOutput ();
@@ -122,6 +124,8 @@
 	bool startup_phase2_error;
 friend class RKRBackendProtocolFrontend;
 	bool backend_dead;
+	static double na_real;
+	static int na_int;
 friend class RKWardMainWindow;
 friend class RCommand;
 protected:
@@ -376,8 +380,9 @@
 
 Even lower level API:
 
-- \ref RThread
-- \ref REmbedInternal
+- \ref RRBackendProtcolFrontend
+- \ref RBackend
+- \ref RRBackendProtcolBackend
 
 */
 

Deleted: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol.h	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -1,143 +0,0 @@
-/***************************************************************************
-                          rkrbackendprotocol  -  description
-                             -------------------
-    begin                : Thu Nov 04 2010
-    copyright            : (C) 2010 by Thomas Friedrichsmeier
-    email                : tfry at users.sourceforge.net
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef RKRBACKENDPROTOCOL_H
-#define RKRBACKENDPROTOCOL_H
-
-#include <QVariantMap>
-#include <QObject>
-
-#include "rcommand.h"
-
-#ifndef RKWARD_SPLIT_PROCESS
-#	define RKWARD_THREADED
-#endif
-
-class RKRBackendProtocolFrontend;
-class RKRBackendProtocolBackend;
-class RKRBackend;
-class RInterface;
-
-class RBackendRequest {
-public:
-	enum RCallbackType {
-		BackendExit,
-		ShowMessage,
-		ShowFiles,
-		ChooseFile,
-		EditFiles,
-		ReadLine,
-		CommandOut,
-		Started,
-		EvalRequest,
-		CallbackRequest,
-		HistoricalSubstackRequest,
-		OtherRequest		/**< Any other type of request. Note: which requests are in the enum, and which are not has mostly historical reasons. @see params */
-	};
-
-	RBackendRequest (bool synchronous, RCallbackType type) {
-		RBackendRequest::synchronous = synchronous;
-		RBackendRequest::type = type;
-		done = false;
-		command = 0;
-	}
-	~RBackendRequest () {};
-
-/** Should this request be handled synchronously? False by default. */
-	bool synchronous;
-/** For synchronous requests, only: The frontend-thread will set this to true (using completed()), once the request has been "completed". Important: The backend thread MUST NOT touch a request after it has been sent, and before "done" has been set to true. */
-	bool done;
-	RCallbackType type;
-/** For synchronous requests, only: If the the frontend wants any commands to be executed, it will place the next one in this slot. The backend thread should keep executing commands (in a sub-eventloop) while this is non-zero. Also, the backend-thread may place here any command that has just finished. */
-	RCommandProxy *command;
-/** Any other parameters, esp. for RCallbackType::OtherRequest. Can be used in both directions. */
-	QVariantMap params;
-protected:
-	friend class RKRBackendProtocolFrontend;
-	friend class RKRBackendProtocolBackend;
-
-	void completed () {
-		if (!synchronous) delete this;
-		else done = true;
-	}
-
-	RBackendRequest *duplicate () {
-		RBackendRequest* ret = new RBackendRequest (synchronous, type);
-		ret->done = done;
-		ret->command = command;
-		ret->params = params;
-		return ret;
-	}
-};
-
-#ifdef RKWARD_THREADED
-#	include <QEvent>
-	/** Simple event class to relay information from the RKRBackend to the main thread. This is basically like QCustomEvent in Qt3*/
-	class RKRBackendEvent : public QEvent {
-	public:
-		enum EventType {
-			RKWardEvent = QEvent::User + 1
-		};
-		RKRBackendEvent (RBackendRequest* data=0) : QEvent ((QEvent::Type) RKWardEvent) { _data = data; };
-		RKRBackendEvent ();
-
-		RBackendRequest* data () { return _data; };
-	private:
-		RBackendRequest* _data;
-	};
-#endif
-
-class RKRBackendProtocolFrontend : public QObject {
-public:
-	RKRBackendProtocolFrontend (RInterface* parent);
-	~RKRBackendProtocolFrontend ();
-
-	static void setRequestCompleted (RBackendRequest *request);
-	ROutputList flushOutput (bool force);
-	void interruptProcessing ();
-	void terminateBackend ();
-	void setupBackend (QVariantMap backend_params);
-	static RKRBackendProtocolFrontend* instance () { return _instance; };
-protected:
-#ifdef RKWARD_THREADED
-/** needed to handle the QEvents, the R thread is sending (notifications on what's happening in the backend thread) */
-	void customEvent (QEvent *e);
-#endif
-private:
-	static RKRBackendProtocolFrontend* _instance;
-	RInterface *frontend;
-};
-
-class RKRBackendProtocolBackend {
-public:
-	static bool inRThread ();
-protected:
-friend class RKRBackendProtocolFrontend;
-friend class RKRBackend;
-friend class RKRBackendThread;
-	RKRBackendProtocolBackend ();
-	~RKRBackendProtocolBackend ();
-
-	void sendRequest (RBackendRequest *request);
-	static void msleep (int delay);
-	static void interruptProcessing ();
-	static RKRBackendProtocolBackend* instance () { return _instance; };
-private:
-	static RKRBackendProtocolBackend* _instance;
-};
-
-#endif

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -15,7 +15,7 @@
  *                                                                         *
  ***************************************************************************/
 
-#include "rkrbackendprotocol.h"
+#include "rkrbackendprotocol_backend.h"
 
 #include "rembedinternal.h"
 
@@ -28,6 +28,7 @@
 #	endif
 #	include <QThread>
 #	include <QApplication>
+#	include "rkrbackendprotocol_frontend.h"
 #else
 #	include <unistd.h>
 #endif

Added: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.h	                        (rev 0)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_backend.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -0,0 +1,41 @@
+/***************************************************************************
+                          rkrbackendprotocol  -  description
+                             -------------------
+    begin                : Thu Nov 04 2010
+    copyright            : (C) 2010 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKRBACKENDPROTOCOL_BACKEND_H
+#define RKRBACKENDPROTOCOL_BACKEND_H
+
+#include "rkrbackendprotocol_shared.h"
+
+class RKRBackendProtocolBackend {
+public:
+	static bool inRThread ();
+protected:
+friend class RKRBackendProtocolFrontend;
+friend class RKRBackend;
+friend class RKRBackendThread;
+	RKRBackendProtocolBackend ();
+	~RKRBackendProtocolBackend ();
+
+	void sendRequest (RBackendRequest *request);
+	static void msleep (int delay);
+	static void interruptProcessing ();
+	static RKRBackendProtocolBackend* instance () { return _instance; };
+private:
+	static RKRBackendProtocolBackend* _instance;
+};
+
+#endif

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -15,12 +15,13 @@
  *                                                                         *
  ***************************************************************************/
 
-#include "rkrbackendprotocol.h"
+#include "rkrbackendprotocol_frontend.h"
 
 #include "rinterface.h"
 #ifdef RKWARD_THREADED
 #	include <QThread>
 #	include "rembedinternal.h"
+#	include "rkrbackendprotocol_backend.h"
 #endif
 
 #include "../debug.h"
@@ -98,7 +99,6 @@
 
 #ifdef RKWARD_THREADED
 void RKRBackendProtocolFrontend::customEvent (QEvent *e) {
-qDebug ("got it");
 	if (((int) e->type ()) == ((int) RKRBackendEvent::RKWardEvent)) {
 		RKRBackendEvent *ev = static_cast<RKRBackendEvent*> (e);
 		frontend->handleRequest (ev->data ());

Added: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.h	                        (rev 0)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_frontend.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -0,0 +1,48 @@
+/***************************************************************************
+                          rkrbackendprotocol  -  description
+                             -------------------
+    begin                : Thu Nov 04 2010
+    copyright            : (C) 2010 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKRBACKENDPROTOCOL_FRONTEND_H
+#define RKRBACKENDPROTOCOL_FRONTEND_H
+
+#include "rkrbackendprotocol_shared.h"
+
+#include <QObject>
+
+class RInterface;
+
+class RKRBackendProtocolFrontend : public QObject {
+public:
+	RKRBackendProtocolFrontend (RInterface* parent);
+	~RKRBackendProtocolFrontend ();
+
+	static void setRequestCompleted (RBackendRequest *request);
+	ROutputList flushOutput (bool force);
+	void interruptProcessing ();
+	void terminateBackend ();
+	void setupBackend (QVariantMap backend_params);
+	static RKRBackendProtocolFrontend* instance () { return _instance; };
+protected:
+#ifdef RKWARD_THREADED
+/** needed to handle the QEvents, the R thread is sending (notifications on what's happening in the backend thread) */
+	void customEvent (QEvent *e);
+#endif
+private:
+	static RKRBackendProtocolFrontend* _instance;
+	RInterface *frontend;
+};
+
+#endif

Added: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.cpp	                        (rev 0)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -0,0 +1,35 @@
+/***************************************************************************
+                          rkrbackendprotocol  -  description
+                             -------------------
+    begin                : Thu Nov 04 2010
+    copyright            : (C) 2010 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "rkrbackendprotocol_shared.h"
+
+#include "../debug.h"
+
+RCommandProxy::RCommandProxy (const QString &command, int type) {
+	RK_TRACE (RBACKEND);
+
+	RCommandProxy::command = command;
+	RCommandProxy::type = type;
+	id = -1;
+	status = 0;
+}
+
+RCommandProxy::~RCommandProxy () {
+	RK_TRACE (RBACKEND);
+
+	RK_ASSERT ((type & RCommand::Internal) || (getDataType () == RData::NoData));
+}

Copied: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.h (from rev 3179, branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol.h)
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.h	                        (rev 0)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrbackendprotocol_shared.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -0,0 +1,116 @@
+/***************************************************************************
+                          rkrbackendprotocol  -  description
+                             -------------------
+    begin                : Thu Nov 04 2010
+    copyright            : (C) 2010 by Thomas Friedrichsmeier
+    email                : tfry at users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef RKRBACKENDPROTOCOL_SHARED_H
+#define RKRBACKENDPROTOCOL_SHARED_H
+
+#ifndef RKWARD_SPLIT_PROCESS
+#	define RKWARD_THREADED
+#endif
+
+#include <QVariantMap>
+
+class RCommandProxy;
+
+class RBackendRequest {
+public:
+	enum RCallbackType {
+		BackendExit,
+		ShowMessage,
+		ShowFiles,
+		ChooseFile,
+		EditFiles,
+		ReadLine,
+		CommandOut,
+		Started,
+		EvalRequest,
+		CallbackRequest,
+		HistoricalSubstackRequest,
+		SetParamsFromBackend,
+		OtherRequest		/**< Any other type of request. Note: which requests are in the enum, and which are not has mostly historical reasons. @see params */
+	};
+
+	RBackendRequest (bool synchronous, RCallbackType type) {
+		RBackendRequest::synchronous = synchronous;
+		RBackendRequest::type = type;
+		done = false;
+		command = 0;
+	}
+	~RBackendRequest () {};
+
+/** Should this request be handled synchronously? False by default. */
+	bool synchronous;
+/** For synchronous requests, only: The frontend-thread will set this to true (using completed()), once the request has been "completed". Important: The backend thread MUST NOT touch a request after it has been sent, and before "done" has been set to true. */
+	bool done;
+	RCallbackType type;
+/** For synchronous requests, only: If the the frontend wants any commands to be executed, it will place the next one in this slot. The backend thread should keep executing commands (in a sub-eventloop) while this is non-zero. Also, the backend-thread may place here any command that has just finished. */
+	RCommandProxy *command;
+/** Any other parameters, esp. for RCallbackType::OtherRequest. Can be used in both directions. */
+	QVariantMap params;
+protected:
+	friend class RKRBackendProtocolFrontend;
+	friend class RKRBackendProtocolBackend;
+
+	void completed () {
+		if (!synchronous) delete this;
+		else done = true;
+	}
+
+	RBackendRequest *duplicate () {
+		RBackendRequest* ret = new RBackendRequest (synchronous, type);
+		ret->done = done;
+		ret->command = command;
+		ret->params = params;
+		return ret;
+	}
+};
+
+#ifdef RKWARD_THREADED
+#	include <QEvent>
+	/** Simple event class to relay information from the RKRBackend to the main thread. This is basically like QCustomEvent in Qt3*/
+	class RKRBackendEvent : public QEvent {
+	public:
+		enum EventType {
+			RKWardEvent = QEvent::User + 1
+		};
+		RKRBackendEvent (RBackendRequest* data=0) : QEvent ((QEvent::Type) RKWardEvent) { _data = data; };
+		RKRBackendEvent ();
+
+		RBackendRequest* data () { return _data; };
+	private:
+		RBackendRequest* _data;
+	};
+#endif
+
+#include "rcommand.h"
+
+/** This is a reduced version of an RCommand, intended for use in the R backend. */
+class RCommandProxy : public RData {
+protected:
+friend class RCommand;
+friend class RKRBackend;
+	RCommandProxy ();
+	~RCommandProxy ();
+	RCommandProxy (const QString &command, int type);
+public:		// all these are public for technical reasons, only.
+	QString command;
+	int type;
+	int id;
+	int status;
+};
+
+#endif

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrsupport.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrsupport.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rkrsupport.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -25,7 +25,6 @@
 
 #include <QTextCodec>
 
-#include "../rkglobals.h"
 #include "rembedinternal.h"
 #include "../debug.h"
 
@@ -144,7 +143,6 @@
 	integers.reserve (count);
 	for (unsigned int i = 0; i < count; ++i) {
 		integers.append (INTEGER (from_exp)[i]);
-		if (integers[i] == R_NaInt) integers[i] = INT_MIN;		// this has no effect for now, but if R ever chnages it's R_NaInt, then it will
 	}
 	return integers;
 }
@@ -177,7 +175,7 @@
 	reals.reserve (count);
 	for (unsigned int i = 0; i < count; ++i) {
 		reals.append (REAL (from_exp)[i]);
-		if (R_IsNaN (reals[i]) || R_IsNA (reals[i]) ) reals[i] = RKGlobals::na_double;
+		if (R_IsNaN (reals[i]) || R_IsNA (reals[i])) reals[i] = NA_REAL;	// for our purposes, treat all non-numbers as missing
 	}
 	return reals;
 }

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rthread.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -16,8 +16,7 @@
  ***************************************************************************/
 #include "rembedinternal.h"
 
-#include "rkrbackendprotocol.h"
-#include "../rkglobals.h"
+#include "rkrbackendprotocol_backend.h"
 #include "../version.h"
 
 #include "../debug.h"

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.cpp
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.cpp	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.cpp	2010-11-07 12:22:07 UTC (rev 3180)
@@ -21,8 +21,6 @@
 RInterface *RKGlobals::rinter;
 RKModificationTracker *RKGlobals::mtracker;
 
-double RKGlobals::na_double;
-
 RKGlobals::RKGlobals () {
 }
 

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.h
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.h	2010-11-06 20:26:20 UTC (rev 3179)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rkglobals.h	2010-11-07 12:22:07 UTC (rev 3180)
@@ -44,9 +44,6 @@
 /// static pointer to the RKModificationTracker
 	static RKModificationTracker *tracker () { return mtracker; };
 
-/// a NA double
-	static double na_double;
-	
 /// returns KDialog::marginHint (), without the need to include kdialog.h in all the sources
 	static int marginHint ();
 /// returns KDialog::spacingHint (), without the need to include kdialog.h in all the sources


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