[rkward-cvs] SF.net SVN: rkward-code:[4614] branches/development_branches/ rkward_graphpics_device/rkward/rbackend

tfry at users.sf.net tfry at users.sf.net
Thu Mar 21 11:11:14 UTC 2013


Revision: 4614
          http://sourceforge.net/p/rkward/code/4614
Author:   tfry
Date:     2013-03-21 11:11:13 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
Compile what we have so far. (Still completely unfinished / unused, of course)

Modified Paths:
--------------
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/CMakeLists.txt
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.h
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

Added Paths:
-----------
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/CMakeLists.txt
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp
    branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/CMakeLists.txt
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/CMakeLists.txt	2013-03-21 09:32:12 UTC (rev 4613)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/CMakeLists.txt	2013-03-21 11:11:13 UTC (rev 4614)
@@ -5,6 +5,7 @@
 ENDIF(NOT WIN32)
 
 ADD_SUBDIRECTORY( rpackages )
+ADD_SUBDIRECTORY( rkwarddevice )
 
 INCLUDE_DIRECTORIES( ${R_INCLUDEDIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
 
@@ -46,7 +47,7 @@
 	)
 	QT4_AUTOMOC(${rbackend_FRONTEND_SRCS})
 	ADD_LIBRARY(rbackend STATIC ${rbackend_FRONTEND_SRCS})
-	TARGET_LINK_LIBRARIES(rbackend ${CMAKE_THREAD_LIBS_INIT})
+	TARGET_LINK_LIBRARIES(rbackend rkgraphicsdevice.frontend ${CMAKE_THREAD_LIBS_INIT})
 
 	SET (
 		rbackend_BACKEND_SRCS
@@ -60,7 +61,7 @@
 	LINK_DIRECTORIES(${R_SHAREDLIBDIR})
 	ADD_EXECUTABLE(rkward.rbackend ${rbackend_BACKEND_SRCS})
 	FIND_PACKAGE(Gettext REQUIRED)
-	TARGET_LINK_LIBRARIES(rkward.rbackend ${R_USED_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY} ${GETTEXT_LIBRARIES})
+	TARGET_LINK_LIBRARIES(rkward.rbackend rkgraphicsdevice.backend ${R_USED_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${QT_QTNETWORK_LIBRARY} ${QT_QTCORE_LIBRARY} ${GETTEXT_LIBRARIES})
 
 	IF(WIN32)
 		# on Widows, we install to the rbackend subdirectory, because 1) LIBEXEC_INSTALL_DIR == BIN_INSTALL_DIR and 2) we don't want the backend to pick up
@@ -80,5 +81,5 @@
 	QT4_AUTOMOC(${rbackend_ALL_SRCS})
 	LINK_DIRECTORIES(${R_SHAREDLIBDIR})
 	ADD_LIBRARY(rbackend STATIC ${rbackend_ALL_SRCS})
-	TARGET_LINK_LIBRARIES(rbackend ${R_USED_LIBS} ${CMAKE_THREAD_LIBS_INIT})
+	TARGET_LINK_LIBRARIES(rbackend rkgraphicsdevice.backend rkgraphicsdevice.frontend ${R_USED_LIBS} ${CMAKE_THREAD_LIBS_INIT})
 ENDIF(RBACKEND_SPLIT)

Added: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/CMakeLists.txt
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/CMakeLists.txt	                        (rev 0)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/CMakeLists.txt	2013-03-21 11:11:13 UTC (rev 4614)
@@ -0,0 +1,19 @@
+INCLUDE_DIRECTORIES( ${R_INCLUDEDIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
+
+SET (
+	rkgraphicsdevice_backend_SRCS
+	rkgraphicsdevice_backendtransmitter.cpp
+	rkgraphicsdevice_setup.cpp
+#	rkgraphicsdevice_stubs.cpp is included by rkgraphicsdevice_setup.cpp
+)
+
+SET (
+	rkgraphicsdevice_frontend_SRCS
+	rkgraphicsdevice_frontendtransmitter.cpp
+)
+
+QT4_AUTOMOC(${rkgraphicsdevice_frontend_SRCS})
+ADD_LIBRARY(rkgraphicsdevice.frontend STATIC ${rkgraphicsdevice_frontend_SRCS})
+
+QT4_AUTOMOC(${rkgraphicsdevice_backend_SRCS})
+ADD_LIBRARY(rkgraphicsdevice.backend STATIC ${rkgraphicsdevice_backend_SRCS})

Added: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp	                        (rev 0)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.cpp	2013-03-21 11:11:13 UTC (rev 4614)
@@ -0,0 +1,60 @@
+/***************************************************************************
+                          rkgraphicsdevice  -  description
+                             -------------------
+    begin                : Mon Mar 18 20:06:08 CET 2013
+    copyright            : (C) 2013 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 "rkgraphicsdevice_backendtransmitter.h"
+
+#include "../../debug.h"
+
+QByteArray RKGraphicsDeviceBackendTransmitter::buffer;
+QDataStream RKGraphicsDeviceBackendTransmitter::protocol (&buffer, QIODevice::ReadWrite);
+QAbstractSocket* RKGraphicsDeviceBackendTransmitter::connection = 0;
+QMutex RKGraphicsDeviceBackendTransmitter::mutex;
+
+RKGraphicsDeviceBackendTransmitter::RKGraphicsDeviceBackendTransmitter (QAbstractSocket* _connection) : QThread () {
+	RK_TRACE (RBACKEND);
+
+	RK_ASSERT (!connection);
+	RK_ASSERT (_connection);
+	connection = _connection;
+	alive = true;
+	start ();
+}
+
+RKGraphicsDeviceBackendTransmitter::~RKGraphicsDeviceBackendTransmitter () {
+	RK_TRACE (RBACKEND);
+}
+
+void RKGraphicsDeviceBackendTransmitter::run () {
+	RK_TRACE (RBACKEND);
+
+	while (alive) {
+		msleep (10);	// it's ok to be lazy. If a request expects a reply, RKGraphicsDataStreamReadGuard will take care of pushing everything, itself. Essentially, this thread's job is simply to make sure we don't lag *too* far behind.
+		mutex.lock ();
+		connection->waitForBytesWritten (100);
+		mutex.unlock ();
+	}
+
+	RK_TRACE (RBACKEND);
+}
+
+void RKGraphicsDeviceBackendTransmitter::kill () {
+	RK_TRACE (RBACKEND);
+	mutex.lock ();
+	alive = false;
+	mutex.unlock ();
+	wait (1000);
+}

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.h	2013-03-21 09:32:12 UTC (rev 4613)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_backendtransmitter.h	2013-03-21 11:11:13 UTC (rev 4614)
@@ -1,7 +1,38 @@
+/***************************************************************************
+                          rkgraphicsdevice  -  description
+                             -------------------
+    begin                : Mon Mar 18 20:06:08 CET 2013
+    copyright            : (C) 2013 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 <QAbstractSocket>
+#include <QThread>
+#include <QMutex>
 
-QByteArray buffer;
-QDataStream protocol (&buffer);
-QAbstractSocket* connection;
-QMutex rkwarddeviceprotocolmutex;
- 
+/** This simple class is responsible for handling the backend side of transmitting data / requests for the RKGraphicsDevice
+ Also it provides the namespace for some statics.
+ As the protocol is really quite simple (only the backend send requests, only one request at a time), so is the transmitter. */
+class RKGraphicsDeviceBackendTransmitter : public QThread {
+	RKGraphicsDeviceBackendTransmitter (QAbstractSocket *connection);
+	~RKGraphicsDeviceBackendTransmitter ();
+
+	void kill ();
+public:
+	static QByteArray buffer;
+	static QDataStream protocol;
+	static QAbstractSocket* connection;
+	static QMutex mutex;
+private:
+	bool alive;
+	void run ();
+};

Added: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
===================================================================
Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h	2013-03-21 09:32:12 UTC (rev 4613)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h	2013-03-21 11:11:13 UTC (rev 4614)
@@ -15,7 +15,7 @@
  *                                                                         *
  ***************************************************************************/
 
-enum {
+enum RKDOpcodes {
 	// Asynchronous operations
 	RKDCreate,
 	RKDCircle,
@@ -37,4 +37,4 @@
 	RKDMetricInfo,
 	RKDLocator,
 	RKDNewPageConfirm
-} OpCodes;
+};

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp	2013-03-21 09:32:12 UTC (rev 4613)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp	2013-03-21 11:11:13 UTC (rev 4614)
@@ -25,8 +25,18 @@
 
 #include "../rkrsupport.h"
 
-#include "rkgraphicsdevice_stubs.cpp"
+#ifdef TRUE
+#	undef TRUE
+#endif
+#ifdef FALSE
+#	undef FALSE
+#endif
+#define R_USE_PROTOTPYES 1
 
+extern "C" {
+#include <R_ext/GraphicsEngine.h>
+}
+
 struct RKGraphicsDeviceDesc {
 	bool initRDevDesc (pDevDesc dev, double pointsize);
 	int devnum;
@@ -35,6 +45,8 @@
 	pDevDesc rdevdesc;
 };
 
+#include "rkgraphicsdevice_stubs.cpp"
+
 #define RKGD_DPI 72
 
 void RKStartGraphicsDevice (double width, double height, double pointsize, const QString &family) {
@@ -45,32 +57,34 @@
 	desc->width = width * RKGD_DPI;
 	desc->height = height * RKGD_DPI;
 	desc->default_family = family;
-//	_scene->setSceneRect(0.0, 0.0, width, height);
 
 	R_GE_checkVersionOrDie (R_GE_version);
 	R_CheckDeviceAvailable ();
+	pDevDesc dev;
 	BEGIN_SUSPEND_INTERRUPTS {
-		pDevDesc dev;
 		/* Allocate and initialize the device driver data */
-		if (!(dev = (pDevDesc) calloc (1, sizeof(DevDesc))))
-			return 0; /* or error() */
-		/* set up device driver or free 'dev' and error() */
-		if (!desc->initRDevDesc (dev, pointsize, desc)) {
+		dev = (pDevDesc) calloc (1, sizeof(DevDesc));
+		if (!(dev && desc->initRDevDesc (dev, pointsize))) {
 			free (dev);
 			delete (desc);
-			Rf_error("unable to start device");
+			desc = 0;
+		} else {
+			pGEDevDesc gdd = GEcreateDevDesc (dev);
+			gdd->displayList = R_NilValue;
+			GEaddDevice2 (gdd, "RKGraphicsDevice");
 		}
-		pGEDevDesc gdd = GEcreateDevDesc (dev);
-		gdd->displayList = R_NilValue;
-		GEaddDevice2 (gdd, "QTScene");
 	} END_SUSPEND_INTERRUPTS;
 
-	desc->devnum = curDevice ();
-	RKD_Create (width, height, desc);
+	if (desc) {
+		desc->devnum = curDevice ();
+		RKD_Create (desc->width, desc->height, dev);
+	} else {
+		Rf_error("unable to start device");
+	}
 }
 
 SEXP RKStartGraphicsDevice (SEXP width, SEXP height, SEXP pointsize, SEXP family
-#warning TODO: add more params for compatibility with X11
+#warning TODO: add more params for compatibility with X11()
 ) {
 	RKStartGraphicsDevice (Rf_asReal (width), Rf_asReal (height), Rf_asReal (pointsize), RKRSupport::SEXPToString (family));
 	return R_NilValue;
@@ -113,8 +127,8 @@
 	dev->displayListOn = TRUE;
 
 	dev->hasTextUTF8 = TRUE;
-	dev->textUTF8 = (void (*)()) RKD_TextUTF8;
-	dev->strWidthUTF8 = (double (*)()) RKD_StrWidthUTF8;
+	dev->textUTF8 = RKD_TextUTF8;
+	dev->strWidthUTF8 = RKD_StrWidthUTF8;
 	dev->wantSymbolUTF8 = TRUE;
 	dev->useRotatedTextInContour = TRUE;
 
@@ -138,23 +152,23 @@
 	/*
 	* Device functions
 	*/
-	dev->activate =    (void (*)()) RKD_Activate;
-	dev->circle =      (void (*)()) RKD_Circle;
-	dev->clip =        (void (*)()) RKD_Clip;
-	dev->close =       (void (*)()) RKD_Close;
-	dev->deactivate =  (void (*)()) RKD_Deactivate;
-	dev->locator = (Rboolean (*)()) RKD_Locator;
-	dev->line =        (void (*)()) RKD_Line;
-	dev->metricInfo =  (void (*)()) RKD_MetricInfo;
-	dev->mode =        (void (*)()) RKD_Mode;
-	dev->newPage =     (void (*)()) RKD_NewPage;
-	dev->polygon =     (void (*)()) RKD_Polygon;
-	dev->polyline =    (void (*)()) RKD_Polyline;
-	dev->rect =        (void (*)()) RKD_Rect;
-	dev->size =        NULL; // (void (*)()) RKD_Size;
-	// dev->onexit =      (void (*)()) RKD_OnExit; NULL is OK
+	dev->activate = RKD_Activate;
+	dev->circle = RKD_Circle;
+	dev->clip = RKD_Clip;
+	dev->close = RKD_Close;
+	dev->deactivate = RKD_Deactivate;
+	dev->locator = RKD_Locator;
+	dev->line = RKD_Line;
+	dev->metricInfo = RKD_MetricInfo;
+	dev->mode = RKD_Mode;
+	dev->newPage = RKD_NewPage;
+	dev->polygon = RKD_Polygon;
+	dev->polyline = RKD_Polyline;
+	dev->rect = RKD_Rect;
+	dev->size = NULL; // RKD_Size;
+	// dev->onexit = RKD_OnExit; NULL is OK
 	// dev->getEvent = SEXP (*getEvent)(SEXP, const char *);
-	dev->newFrameConfirm = (Rboolean (*)()) RKD_NewFrameConfirm;
+	dev->newFrameConfirm = RKD_NewFrameConfirm;
 
 	return true;
 }

Modified: branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
===================================================================
--- branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-03-21 09:32:12 UTC (rev 4613)
+++ branches/development_branches/rkward_graphpics_device/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp	2013-03-21 11:11:13 UTC (rev 4614)
@@ -17,14 +17,26 @@
 
 #include "rkgraphicsdevice_protocol_shared.h"
 #include "rkgraphicsdevice_backendtransmitter.h"
+#include "../rkrbackend.h"
 
+extern "C" {
+#include <R_ext/GraphicsEngine.h>
+}
+
 #include <QRectF>
 
+#define RKD_PROTOCOL RKGraphicsDeviceBackendTransmitter::protocol
+
 /** This class is essentially like QMutexLocker. In addition, the constructor waits until the next chunk of the transmission is ready (and does event processing) */
-class RKSocketDataStreamReadGuard {
-	RKSocketDataStreamReadGuard () {
+class RKGraphicsDataStreamReadGuard {
+public:
+	RKGraphicsDataStreamReadGuard () {
 #warning TODO: handle cancellation
-		rkwarddeviceprotocolmutex.lock ();
+/* How shall we handle cancellation? If an interrupt is pending, _while waiting for the reply_, we push an RKD_Cancel
+ * request down the line. This tells the frontend to send a reply to the last request ASAP (if the frontend has already sent the reply, it will ignore the RKD_Cancel). From there, we simply process the reply as usual, and leave it to R to actually
+ * do the interrupt. */
+		RKGraphicsDeviceBackendTransmitter::mutex.lock ();
+		QAbstractSocket* connection = RKGraphicsDeviceBackendTransmitter::connection;
 		BEGIN_SUSPEND_INTERRUPTS {
 			while (connection->bytesToWrite ()) {
 				connection->waitForBytesWritten (10);
@@ -35,157 +47,161 @@
 				connection->waitForReadyRead (10);
 			}
 			quint32 transmisison_size;
-			transmisison_size << protocol;
+			RKD_PROTOCOL >> transmisison_size;
 			while (connection->bytesAvailable () < transmisison_size) {
 				RKRBackend::processX11Events ();
 				connection->waitForReadyRead (10);
 			}
+			RKGraphicsDeviceBackendTransmitter::buffer = connection->read (transmisison_size);
 		} END_SUSPEND_INTERRUPTS;
 	}
-	~RKSocketDataStreamReadGuard () {
-		buffer.resize (0);
-		rkwarddeviceprotocolmutex.unlock ();
+
+	~RKGraphicsDataStreamReadGuard () {
+		RKGraphicsDeviceBackendTransmitter::buffer.resize (0);
+		RKGraphicsDeviceBackendTransmitter::mutex.unlock ();
 	}
 };
 
 /** This class is essentially like QMutexLocker. In addition, the destructor takes care of pushing anything that was written to the protocol buffer during it lifetime to the transmitter. (Does NOT wait for the transmission itself). */
-class RKSocketDataStreamWriteGuard {
-	RKSocketDataStreamWriteGuard () {
-		rkwarddeviceprotocolmutex.lock ();
+class RKGraphicsDataStreamWriteGuard {
+public:
+	RKGraphicsDataStreamWriteGuard () {
+		RKGraphicsDeviceBackendTransmitter::mutex.lock ();
 	}
-	~RKSocketDataStreamWriteGuard () {
-		aux_stream << (quint32) buffer.size ();		// TODO: is uint32 always enough?
-		connection->write (aux_buffer);
+	~RKGraphicsDataStreamWriteGuard () {
+		aux_stream << (quint32) RKGraphicsDeviceBackendTransmitter::buffer.size ();		// TODO: is uint32 always enough?
+		RKGraphicsDeviceBackendTransmitter::connection->write (aux_buffer);
 		aux_buffer.resize (0);
-		connection->write (buffer);
-		buffer.resize (0);
-		rkwarddeviceprotocolmutex.unlock ();
+		RKGraphicsDeviceBackendTransmitter::connection->write (RKGraphicsDeviceBackendTransmitter::buffer);
+		RKGraphicsDeviceBackendTransmitter::buffer.resize (0);
+		RKGraphicsDeviceBackendTransmitter::mutex.unlock ();
 	}
-
+private:
 	static QByteArray aux_buffer;
 	static QDataStream aux_stream;
 };
 
-#include <R_ext/GraphicsEngine.h>
+QByteArray RKGraphicsDataStreamWriteGuard::aux_buffer;
+QDataStream RKGraphicsDataStreamWriteGuard::aux_stream (&RKGraphicsDataStreamWriteGuard::aux_buffer, QIODevice::WriteOnly);
 
 #define WRITE_HEADER(x,dev) (qint8) x << (quint8) static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific)->devnum
 #define WRITE_COL() (qint32) gc->col
-#define WRITE_PEN() WRITE_COL() << (double) gc->lwd << (qint32) << gc->lty
+#define WRITE_PEN() WRITE_COL() << gc->col << (double) gc->lwd << (qint32) gc->lty
 #define WRITE_LINE_ENDS() (quint8) gc->lend << (quint8) gc->ljoin << gc->lmitre
 #define WRITE_FILL() (qint32) gc->fill
-#define WRITE_FONT(dev) gc->cex << gc->ps << gc->lineheight << (quint8) gc->fontface << gc->fontfamily[0] ? QString (gc->fontfamily) : (static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific)->default_family)
+#define WRITE_FONT(dev) gc->cex << gc->ps << gc->lineheight << (quint8) gc->fontface << (gc->fontfamily[0] ? QString (gc->fontfamily) : (static_cast<RKGraphicsDeviceDesc*> (dev->deviceSpecific)->default_family))
 
 static void RKD_Create (double width, double height, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDCreate, dev);
-	protocol << width << height;
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDCreate, dev);
+	RKD_PROTOCOL << width << height;
 }
 
 static void RKD_Circle (double x, double y, double r, R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDCircle, dev);
-	protocol << x << y << r;
-	protocol << WRITE_PEN ();
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDCircle, dev);
+	RKD_PROTOCOL << x << y << r;
+	RKD_PROTOCOL << WRITE_PEN ();
 }
 
 static void RKD_Line (double x1, double y1, double x2, double y2, R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDLine, dev);
-	protocol << x1 << y1 << x2 << y2;
-	protocol << WRITE_PEN ();
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDLine, dev);
+	RKD_PROTOCOL << x1 << y1 << x2 << y2;
+	RKD_PROTOCOL << WRITE_PEN ();
 }
 
 static void RKD_Polygon (int n, double *x, double *y, R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDPolygon, dev);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDPolygon, dev);
 	quint32 _n = qMax (n, 1 << 25);	// skip stuff exceeding reasonable limits to keep protocol simple
-	protocol << _n;
-	for (quint32 i; i < _n; ++i) {
-		protocol << x[i] << y[i];
+	RKD_PROTOCOL << _n;
+	for (quint32 i = 0; i < _n; ++i) {
+		RKD_PROTOCOL << x[i] << y[i];
 	}
-	protocol << WRITE_PEN ();
-	protocol << WRITE_LINE_ENDS ();
-	protocol << WRITE_FILL ();
+	RKD_PROTOCOL << WRITE_PEN ();
+	RKD_PROTOCOL << WRITE_LINE_ENDS ();
+	RKD_PROTOCOL << WRITE_FILL ();
 }
 
 static void RKD_Polyline (int n, double *x, double *y, R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDPolyline, dev);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDPolyline, dev);
 	quint32 _n = qMax (n, 1 << 25);	// skip stuff exceeding reasonable limits to keep protocol simple
-	protocol << _n;
-	for (quint32 i; i < _n; ++i) {
-		protocol << x[i] << y[i];
+	RKD_PROTOCOL << _n;
+	for (quint32 i = 0; i < _n; ++i) {
+		RKD_PROTOCOL << x[i] << y[i];
 	}
-	protocol << WRITE_PEN ();
-	protocol << WRITE_LINE_ENDS ();
+	RKD_PROTOCOL << WRITE_PEN ();
+	RKD_PROTOCOL << WRITE_LINE_ENDS ();
 }
 
 static void RKD_Rect (double x0, double y0, double x1, double y1, R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDPolyline, dev);
-	protocol << QRectF (x0, y0, x1-x0, y1-y0);
-	protocol << WRITE_PEN ();
-	protocol << WRITE_LINE_ENDS ();
-	protocol << WRITE_FILL ();
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDPolyline, dev);
+	RKD_PROTOCOL << QRectF (x0, y0, x1-x0, y1-y0);
+	RKD_PROTOCOL << WRITE_PEN ();
+	RKD_PROTOCOL << WRITE_LINE_ENDS ();
+	RKD_PROTOCOL << WRITE_FILL ();
 }
 
-static void RKD_TextUTF8 (double x, double y, char *str, double rot, double hadj, R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDTextUTF8, dev);
-	protocol << x << y << QString::fromUtf8 (str) << rot << hadj;
-	protocol << WRITE_COL ();
-	protocol << WRITE_FONT (dev);
+static void RKD_TextUTF8 (double x, double y, const char *str, double rot, double hadj, R_GE_gcontext *gc, pDevDesc dev) {
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDTextUTF8, dev);
+	RKD_PROTOCOL << x << y << QString::fromUtf8 (str) << rot << hadj;
+	RKD_PROTOCOL << WRITE_COL ();
+	RKD_PROTOCOL << WRITE_FONT (dev);
 }
 
-static double RKD_StrWidthUTF8 (char *str, R_GE_gcontext *gc, pDevDesc dev) {
+static double RKD_StrWidthUTF8 (const char *str, R_GE_gcontext *gc, pDevDesc dev) {
 	{
-		RKSocketDataStreamWriteGuard guard;
-		protocol << WRITE_HEADER (RKDStrWidthUTF8, dev);
-		protocol << QString::fromUtf8 (str);
-		protocol << WRITE_FONT (dev);
+		RKGraphicsDataStreamWriteGuard guard;
+		RKD_PROTOCOL << WRITE_HEADER (RKDStrWidthUTF8, dev);
+		RKD_PROTOCOL << QString::fromUtf8 (str);
+		RKD_PROTOCOL << WRITE_FONT (dev);
 	}
 	double ret;
 	{
-		RKSocketDataStreamReadGuard guard;
-		ret << protocol;
+		RKGraphicsDataStreamReadGuard guard;
+		RKD_PROTOCOL >> ret;
 	}
 	return ret;
 }
 
 static void RKD_NewPage (R_GE_gcontext *gc, pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDNewPage, dev);
-	protocol << WRITE_FILL ();
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDNewPage, dev);
+	RKD_PROTOCOL << WRITE_FILL ();
 }
 
 static void RKD_MetricInfo (int c, R_GE_gcontext *gc, double* ascent, double* descent, double* width, pDevDesc dev) {
 	{
-		RKSocketDataStreamWriteGuard wguard;
-		protocol << WRITE_HEADER (RKDMetricInfo, dev);
-		protocol << QChar (c);
-		protocol << WRITE_FONT (dev);
+		RKGraphicsDataStreamWriteGuard wguard;
+		RKD_PROTOCOL << WRITE_HEADER (RKDMetricInfo, dev);
+		RKD_PROTOCOL << QChar (c);
+		RKD_PROTOCOL << WRITE_FONT (dev);
 	}
 	{
-		RKSocketDataStreamReadGuard rguard;
-		*ascent << protocol;
-		*descent << protocol;
-		*width << protocol;
+		RKGraphicsDataStreamReadGuard rguard;
+		RKD_PROTOCOL >> *ascent;
+		RKD_PROTOCOL >> *descent;
+		RKD_PROTOCOL >> *width;
 	}
 }
 
 static void RKD_Close (pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDClose, dev);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDClose, dev);
 }
 
 static void RKD_Activate (pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDActivate, dev);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDActivate, dev);
 }
 
 static void RKD_Deactivate (pDevDesc dev) {
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDDeActivate, dev);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDDeActivate, dev);
 }
 
 static void RKD_Clip (double left, double right, double top, double bottom, pDevDesc dev) {
@@ -193,44 +209,47 @@
 	dev->clipRight = right;
 	dev->clipTop = top;
 	dev->clipBottom = bottom;
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDClip, dev);
-	protocol << QRectF (left, top, right - left, bottom - top);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDClip, dev);
+	RKD_PROTOCOL << QRectF (left, top, right - left, bottom - top);
 }
 
 static void RKD_Mode (int mode, pDevDesc dev) {
+	Q_UNUSED (mode);
+	Q_UNUSED (dev);
 /* Left empty for now. 1 is start signal, 0 is stop signal. Might be useful for flushing, though.
 
-	RKSocketDataStreamWriteGuard guard;
-	protocol << WRITE_HEADER (RKDMode, dev);
+	RKGraphicsDataStreamWriteGuard guard;
+	RKD_PROTOCOL << WRITE_HEADER (RKDMode, dev);
 	connectoin << (qint8) mode; */
 }
 
 static Rboolean RKD_Locator (double *x, double *y, pDevDesc dev) {
 	{
-		RKSocketDataStreamWriteGuard wguard;
-		protocol << WRITE_HEADER (RKDLocator, dev);
+		RKGraphicsDataStreamWriteGuard wguard;
+		RKD_PROTOCOL << WRITE_HEADER (RKDLocator, dev);
 	}
 	{
-		RKSocketDataStreamReadGuard rguard;
+		RKGraphicsDataStreamReadGuard rguard;
 		bool ok;
-		ok << protocol;
-		*x << protocol;
-		*y << protocol;
-		if (ok) return TRUE;
-		return FALSE;
+		RKD_PROTOCOL >> ok;
+		RKD_PROTOCOL >> *x;
+		RKD_PROTOCOL >> *y;
+		if (ok) return (Rboolean) TRUE;
+		return (Rboolean) FALSE;
 	}
 }
 
 static Rboolean RKD_NewFrameConfirm (pDevDesc dev) {
 	{
-		RKSocketDataStreamWriteGuard wguard;
-		protocol << WRITE_HEADER (RKDNewPageConfirm, dev);
+		RKGraphicsDataStreamWriteGuard wguard;
+		RKD_PROTOCOL << WRITE_HEADER (RKDNewPageConfirm, dev);
 	}
 	{
-		RKSocketDataStreamReadGuard rguard;
-		bool ok << protocol;
-		if (ok) return TRUE;
-		return FALSE;
+		RKGraphicsDataStreamReadGuard rguard;
+		bool ok;
+		RKD_PROTOCOL >> ok;
+		if (ok) return (Rboolean) TRUE;
+		return (Rboolean) FALSE;
 	}
 }





More information about the rkward-tracker mailing list