[rkward-cvs] rkward/rkward/rbackend rembed.cpp,1.19,1.20 rembedinternal.cpp,1.18,1.19 rembedinternal.h,1.11,1.12 rinterface.cpp,1.25,1.26 rthread.cpp,1.16,1.17

Thomas Friedrichsmeier tfry at users.sourceforge.net
Wed Sep 14 16:32:27 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/rbackend
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv667/rkward/rbackend

Modified Files:
	rembed.cpp rembedinternal.cpp rembedinternal.h rinterface.cpp 
	rthread.cpp 
Log Message:
Implemented R_EditFile(s), R_ShowFiles, R_ChooseFile, R_Cleanup, R_Suicide.
Override for q () and quit () in R.
Make help (...)-calls open HTML-help in rkward-HTML-window (via DCOP).

Index: rembedinternal.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembedinternal.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** rembedinternal.h	14 Sep 2005 12:06:02 -0000	1.11
--- rembedinternal.h	14 Sep 2005 16:32:25 -0000	1.12
***************
*** 39,42 ****
--- 39,43 ----
  	char **chars_b;
  	char **chars_c;
+ 	char **chars_d;
  	int int_a;
  	int int_b;
***************
*** 70,73 ****
--- 71,77 ----
  		OtherError=3		/**< Other error, usually a semantic error, e.g. object not found */
  	};
+ 
+ /** clean shutdown of R. If suicidal, perform only the most basic shutdown operations */
+ 	void shutdown (bool suicidal);
  protected:
  /** low-level initialization of R
***************
*** 76,81 ****
  @param argv Arguments as would be passed on the commandline to R */
  	bool startR (const char* r_home, int argc, char **argv);
- /** clean shutdown of R. Not yet implemented! (TODO!) */
- 	void shutdown ();
  /** low-level running of a command.
  @param command char* of the command to be run
--- 80,83 ----

Index: rinterface.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rinterface.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** rinterface.cpp	14 Sep 2005 12:06:02 -0000	1.25
--- rinterface.cpp	14 Sep 2005 16:32:25 -0000	1.26
***************
*** 41,44 ****
--- 41,45 ----
  #include <kmessagebox.h>
  #include <kinputdialog.h>
+ #include <kfiledialog.h>
  #include <klocale.h>
  
***************
*** 267,270 ****
--- 268,275 ----
  			issueCommand (".rk.rkreply <- \"Too few arguments in call to require.\"", RCommand::App | RCommand::Sync, "", 0, 0, request->in_chain);
  		}
+ 	} else if (call == "quit") {
+ 		RKGlobals::rkApp ()->slotFileQuit ();
+ 		// if we're still alive, quitting was cancelled
+ 		issueCommand (".rk.rkreply <- \"Quitting was cancelled\"", RCommand::App | RCommand::Sync, "", 0, 0, request->in_chain);
  #ifndef DISABLE_RKWINDOWCATCHER
   // does not work, yet :-( R crashes.
***************
*** 298,304 ****
  		qstrcpy (*(args->chars_b), res.latin1 ());
  	} else if ((type == RCallbackArgs::RShowFiles) || (type == RCallbackArgs::REditFiles)) {
! 		ShowEditTextFileAgent::showEditFiles (args);
! 		MUTEX_UNLOCK;
! 		return;
  	}
  
--- 303,337 ----
  		qstrcpy (*(args->chars_b), res.latin1 ());
  	} else if ((type == RCallbackArgs::RShowFiles) || (type == RCallbackArgs::REditFiles)) {
! 		if ((type == RCallbackArgs::RShowFiles) && (QString (*(args->chars_d)) == "rkwardhtml")) {
! 			// not to worry, just some help file to display
! 			// TODO: maybe move this to ShowEditTextFileAgent instead
! 			for (int n=0; n < args->int_a; ++n) {
! 				RKGlobals::rkApp ()->openHTML (args->chars_a[n]);
! 			}
! 		} else {
! 			ShowEditTextFileAgent::showEditFiles (args);
! 			MUTEX_UNLOCK;
! 			return;
! 		}
! 	} else if (type ==RCallbackArgs::RChooseFile) {
! 		QString filename;
! 		if (args->int_a) {
! 			filename = KFileDialog::getSaveFileName ();
! 		} else {
! 			filename = KFileDialog::getOpenFileName ();
! 		}
! 		filename = filename.left (args->int_b - 2);
! 		args->int_c = filename.length ();
! 		qstrcpy (*(args->chars_a), filename.latin1 ());
! 	} else if (type ==RCallbackArgs::RSuicide) {
! 		QString message = i18n ("The R engine has encountered a fatal error:\n") + QString (*(args->chars_a));
! 		message += i18n ("It 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. 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. Sorry!");
! 		KMessageBox::error (0, message, i18n ("R engine has died"));
! 		r_thread->terminate ();
! 	} else if (type ==RCallbackArgs::RCleanUp) {
! 		QString message = i18n ("The R engine has shut down with status: ") + QString::number (args->int_a);
! 		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. Hopefully, however, R has already saved the workspace. 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!");
! 		KMessageBox::error (0, message, i18n ("R engine has died"));
! 		r_thread->terminate ();
  	}
  

Index: rthread.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rthread.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** rthread.cpp	14 Sep 2005 12:06:02 -0000	1.16
--- rthread.cpp	14 Sep 2005 16:32:25 -0000	1.17
***************
*** 75,78 ****
--- 75,79 ----
  		
  			if (killed) {
+ 				embeddedR->shutdown (false);
  				MUTEX_UNLOCK
  				return;
***************
*** 89,93 ****
  		// if no commands are in queue, sleep for a while
  		MUTEX_UNLOCK;
! 		if (killed) return;
  		msleep (10);
  	}
--- 90,97 ----
  		// if no commands are in queue, sleep for a while
  		MUTEX_UNLOCK;
! 		if (killed) {
! 			embeddedR->shutdown (false);
! 			return;
! 		}
  		msleep (10);
  	}

Index: rembedinternal.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembedinternal.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** rembedinternal.cpp	14 Sep 2005 12:06:02 -0000	1.18
--- rembedinternal.cpp	14 Sep 2005 16:32:25 -0000	1.19
***************
*** 30,33 ****
--- 30,34 ----
  #include "Rinternals.h"
  #include "Rinterface.h"
+ #include "Rdevices.h"
  
  #include <stdlib.h>
***************
*** 40,44 ****
  /// ############## R Standard callback overrides BEGIN ####################
  void RSuicide (char* message) {
! // TODO
  }
  
--- 41,49 ----
  /// ############## R Standard callback overrides BEGIN ####################
  void RSuicide (char* message) {
! 	RCallbackArgs args;
! 	args.type = RCallbackArgs::RSuicide;
! 	args.chars_a = &message;
! 	REmbedInternal::this_pointer->handleStandardCallback (&args);
! 	REmbedInternal::this_pointer->shutdown (true);
  }
  
***************
*** 90,97 ****
  
  void RCleanUp (SA_TYPE saveact, int status, int RunLast) {
! // TODO
  }
  
! int RShowFiles (int nfile, char **file, char **headers, char *wtitle, Rboolean del, char */*pager*/) {
  	RCallbackArgs args;
  	args.type = RCallbackArgs::RShowFiles;
--- 95,121 ----
  
  void RCleanUp (SA_TYPE saveact, int status, int RunLast) {
! 	if (saveact != SA_SUICIDE) {
! 		RCallbackArgs args;
! 		args.type = RCallbackArgs::RCleanUp;
! 		args.int_a = status;
! 		args.int_b = RunLast;
! 		REmbedInternal::this_pointer->handleStandardCallback (&args);
! 
! 		if(saveact == SA_DEFAULT) saveact = SA_SAVE;
! 		if (saveact == SA_SAVE) {
! 				if (RunLast) R_dot_Last ();
! 				if( R_DirtyImage) R_SaveGlobalEnv ();
! 		} else {
! 				if (RunLast) R_dot_Last ();
! 		}
! 
! 		REmbedInternal::this_pointer->shutdown (false);
! 	}
! 	/*else {
! 		we've already informed the user, and shut down the backend in RSuicide
! 	}*/
  }
  
! int RShowFiles (int nfile, char **file, char **headers, char *wtitle, Rboolean del, char *pager) {
  	RCallbackArgs args;
  	args.type = RCallbackArgs::RShowFiles;
***************
*** 100,103 ****
--- 124,128 ----
  	args.chars_b = headers;		// what exactly are the "headers"?!?
  	args.chars_c = &wtitle;
+ 	args.chars_d = &pager;
  	args.int_b = del;
  	// we ingnore the pager-parameter for now.
***************
*** 110,116 ****
  
  int RChooseFile (int isnew, char *buf, int len) {
! // TODO
  // return length of filename (strlen (buf))
! 	return 0;
  }
  
--- 135,148 ----
  
  int RChooseFile (int isnew, char *buf, int len) {
! 	RCallbackArgs args;
! 	args.type = RCallbackArgs::RChooseFile;
! 	args.int_a = isnew;
! 	args.int_b = len;
! 	args.chars_a = &buf;
! 
! 	REmbedInternal::this_pointer->handleStandardCallback (&args);
! 
  // return length of filename (strlen (buf))
! 	return args.int_c;
  }
  
***************
*** 155,159 ****
  
  // connect R standard callback to our own functions. Important: Don't do so, before our own versions are ready to be used!
! //	ptr_R_Suicide = RSuicide;
  	ptr_R_ShowMessage = RShowMessage;			// when exactly does this ever get used?
  	ptr_R_ReadConsole = RReadConsole;
--- 187,191 ----
  
  // connect R standard callback to our own functions. Important: Don't do so, before our own versions are ready to be used!
! 	ptr_R_Suicide = RSuicide;
  	ptr_R_ShowMessage = RShowMessage;			// when exactly does this ever get used?
  	ptr_R_ReadConsole = RReadConsole;
***************
*** 163,171 ****
  	ptr_R_ClearerrConsole = RClearerrConsole;
  //	ptr_R_Busy = RBusy;				// probably we don't have any use for this
! //	ptr_R_CleanUp = RCleanUp;
  	ptr_R_ShowFiles = RShowFiles;
! //	ptr_R_ChooseFile = RChooseFile;
  	ptr_R_EditFile = REditFile;
! //	ptr_R_EditFiles = REditFiles;
  
  // these two, we won't override
--- 195,203 ----
  	ptr_R_ClearerrConsole = RClearerrConsole;
  //	ptr_R_Busy = RBusy;				// probably we don't have any use for this
! 	ptr_R_CleanUp = RCleanUp;			// unfortunately, it seems, we can't safely cancel quitting anymore, here!
  	ptr_R_ShowFiles = RShowFiles;
! 	ptr_R_ChooseFile = RChooseFile;
  	ptr_R_EditFile = REditFile;
! //	ptr_R_EditFiles = REditFiles;		// undefined reference
  
  // these two, we won't override
***************
*** 177,181 ****
  }
  
! void REmbedInternal::shutdown () {
  }
  
--- 209,232 ----
  }
  
! void REmbedInternal::shutdown (bool suicidal) {
! // Code-recipe below essentially copied from http://stat.ethz.ch/R-manual/R-devel/doc/manual/R-exts.html#Linking-GUIs-and-other-front_002dends-to-R
! // modified quite a bit for our needs.
! 	char *tmpdir;
! 
! 	if (!suicidal) {
! 		R_dot_Last ();
! 	}
! 
! 	R_RunExitFinalizers();
! 
! 	if((tmpdir = getenv("R_SESSION_TMPDIR"))) {
! 		char buf[1024];
! 		snprintf((char *)buf, 1024, "rm -rf %s", tmpdir);
! 		R_system((char *)buf);
! 	}
! 
! 	/* close all the graphics devices */
! 	if (!suicidal) KillAllDevices ();
! 	fpu_setup (FALSE);
  }
  

Index: rembed.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembed.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** rembed.cpp	12 Sep 2005 17:09:59 -0000	1.19
--- rembed.cpp	14 Sep 2005 16:32:25 -0000	1.20
***************
*** 17,20 ****
--- 17,23 ----
  #include "rembed.h"
  
+ #include <kapplication.h>
+ #include <dcopclient.h>
+ 
  #include <qfile.h>
  #include <qtextstream.h>
***************
*** 92,96 ****
  	runCommandInternal ("sink (file (\"" +RKSettingsModuleLogfiles::filesPath () +"/r_err\", \"w\"), FALSE, \"message\")\n", &error);
  	if (error) status |= SinkFail;
! 	
  	outfile_offset = 0;
  	errfile_offset = 0;
--- 95,101 ----
  	runCommandInternal ("sink (file (\"" +RKSettingsModuleLogfiles::filesPath () +"/r_err\", \"w\"), FALSE, \"message\")\n", &error);
  	if (error) status |= SinkFail;
! 	runCommandInternal ("options (htmlhelp=TRUE); options (browser=\"dcop " + kapp->dcopClient ()->appId () + " rkwardapp openHTMLHelp \")", &error);
! 	// TODO: error-handling?
! 
  	outfile_offset = 0;
  	errfile_offset = 0;





More information about the rkward-tracker mailing list