[rkward-cvs] rkward/rkward/rbackend rcommand.h,1.21,1.22 rcommandreceiver.h,1.4,1.5 rembedinternal.cpp,1.26,1.27 rinterface.cpp,1.36,1.37 rthread.cpp,1.25,1.26 rthread.h,1.18,1.19

Thomas Friedrichsmeier tfry at users.sourceforge.net
Wed Nov 2 21:11:40 UTC 2005


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

Modified Files:
	rcommand.h rcommandreceiver.h rembedinternal.cpp 
	rinterface.cpp rthread.cpp rthread.h 
Log Message:
real time display of output in console (and only in console, so far)

Index: rthread.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rthread.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** rthread.h	21 Oct 2005 15:23:36 -0000	1.18
--- rthread.h	2 Nov 2005 21:11:38 -0000	1.19
***************
*** 26,29 ****
--- 26,30 ----
  class RInterface;
  struct RCallbackArgs;
+ struct ROutput;
  
  #define RCOMMAND_IN_EVENT 10001
***************
*** 31,34 ****
--- 32,36 ----
  #define RBUSY_EVENT 10003
  #define RIDLE_EVENT 10004
+ #define RCOMMAND_OUTPUT_EVENT 10005
  #define RSTARTED_EVENT 11001
  #define R_EVAL_REQUEST_EVENT 12001
***************
*** 133,136 ****
--- 135,146 ----
  already/still running. */
  	RCommand *current_command;
+ 
+ /** convenience struct for event passing */
+ 	struct ROutputContainer {
+ 		/** the actual output fragment */
+ 		ROutput *output;
+ 		/** the corresponding command */
+ 		RCommand *command;
+ 	};
  protected:
  /** the main loop. See \ref RThread for a more detailed description */

Index: rinterface.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rinterface.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** rinterface.cpp	20 Oct 2005 19:45:54 -0000	1.36
--- rinterface.cpp	2 Nov 2005 21:11:38 -0000	1.37
***************
*** 118,122 ****
  void RInterface::customEvent (QCustomEvent *e) {
  	RK_TRACE (RBACKEND);
! 	if (e->type () == RCOMMAND_IN_EVENT) {
  		watch->addInput (static_cast <RCommand *> (e->data ()));
  		RKGlobals::controlWindow ()->setCommandRunning (static_cast <RCommand *> (e->data ()));
--- 118,127 ----
  void RInterface::customEvent (QCustomEvent *e) {
  	RK_TRACE (RBACKEND);
! 	if (e->type () == RCOMMAND_OUTPUT_EVENT) {
! 		RThread::ROutputContainer *container = (static_cast <RThread::ROutputContainer *> (e->data ()));
! 		// we've already made sure, there is an existing receiver in RThread
! 		container->command->receiver->newOutput (container->command, container->output);
! 		delete container;
! 	} else if (e->type () == RCOMMAND_IN_EVENT) {
  		watch->addInput (static_cast <RCommand *> (e->data ()));
  		RKGlobals::controlWindow ()->setCommandRunning (static_cast <RCommand *> (e->data ()));
***************
*** 129,132 ****
--- 134,140 ----
  			out->output = ("--- interrupted ---");
  			command->output_list.append (out);
+ 			if (command->receiver && (command->type () & RCommand::ImmediateOutput)) {
+ 				command->receiver->newOutput (command, out);
+ 			}
  			if (running_command_canceled) {
  				RK_ASSERT (command == running_command_canceled);

Index: rembedinternal.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rembedinternal.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** rembedinternal.cpp	2 Nov 2005 16:51:10 -0000	1.26
--- rembedinternal.cpp	2 Nov 2005 21:11:38 -0000	1.27
***************
*** 530,532 ****
  }
  
- //} // extern "C"
--- 530,531 ----

Index: rcommandreceiver.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rcommandreceiver.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** rcommandreceiver.h	26 Oct 2005 16:10:32 -0000	1.4
--- rcommandreceiver.h	2 Nov 2005 21:11:38 -0000	1.5
***************
*** 27,41 ****
  
  class RCommand;
  
  class RCommandReceiver {
  public:
      RCommandReceiver () { num_commands_waiting=0; deleted=false; };
! 
      virtual ~RCommandReceiver () {};
  	int numCommandsOut () { return num_commands_waiting; };
  	void deleteThis () { if (num_commands_waiting > 0) { deleted=true; } else { deleteThisNow (); } };
  protected:
  	friend class RCommand;
  	virtual void rCommandDone (RCommand *command) = 0;
  /** calls "delete this" immediately (called from deleteThis ()). Virtual so you can use some other method of destruction, e.g. QObject::deleteLater (). */
  	virtual void deleteThisNow () { delete this; };
--- 27,52 ----
  
  class RCommand;
+ struct ROutput;
  
  class RCommandReceiver {
  public:
+ /** constructor. No args */
      RCommandReceiver () { num_commands_waiting=0; deleted=false; };
! /** destructor */
      virtual ~RCommandReceiver () {};
+ /** number of commands issued with this RCommandReceiver as receiver, that have not returned, yet */
  	int numCommandsOut () { return num_commands_waiting; };
+ /** use this instead of "delete this". Will wait until all commands still waiting (@see numCommandsOut ()), before acutally deleting the receiver */
  	void deleteThis () { if (num_commands_waiting > 0) { deleted=true; } else { deleteThisNow (); } };
  protected:
  	friend class RCommand;
+ 	friend class RInterface;
+ /** This function is called when a command for this receiver is finished (and before it is deleted). You have to implement it in your subclass to do the actual handling.
+ @param command A pointer to the command. The pointer is still valid during this call, but the RCommand will be deleted shortly after! */
  	virtual void rCommandDone (RCommand *command) = 0;
+ /** This function is called when there is new output for a command or this receiver (only if the command has the RCommand::ImmediateOutput flag). Default implementation does nothing. Reimplement if you use commands with RCommand::ImmediateOutput flag.
+ @param command A pointer to the command
+ @param output The new output-fragment */
+ 	virtual void newOutput (RCommand *, ROutput *) {};
  /** calls "delete this" immediately (called from deleteThis ()). Virtual so you can use some other method of destruction, e.g. QObject::deleteLater (). */
  	virtual void deleteThisNow () { delete this; };

Index: rcommand.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rcommand.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** rcommand.h	16 Oct 2005 21:40:55 -0000	1.21
--- rcommand.h	2 Nov 2005 21:11:38 -0000	1.22
***************
*** 160,164 ****
  		GetStringVector=1024,	/**< Try to fetch result as an array of chars */
  		GetRealVector=2048,		/**< Try to fetch result as an array of doubles */
! 		DirectToOutput=4096		/**< Append command output to the HTML-output file */
  	};
  	enum CommandStatus {
--- 160,165 ----
  		GetStringVector=1024,	/**< Try to fetch result as an array of chars */
  		GetRealVector=2048,		/**< Try to fetch result as an array of doubles */
! 		DirectToOutput=4096,		/**< Append command output to the HTML-output file */
! 		ImmediateOutput=8192	/**< Receive notifications whenever new output is available */
  	};
  	enum CommandStatus {

Index: rthread.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rthread.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** rthread.cpp	20 Oct 2005 19:45:54 -0000	1.25
--- rthread.cpp	2 Nov 2005 21:11:38 -0000	1.26
***************
*** 190,196 ****
  	current_command->output_list.append (out);
  	current_command->status |= RCommand::HasOutput;
- 	// TODO: pass a signal to the main thread for real-time update of output
  
  	RK_DO (qDebug ("output '%s'", buf), RBACKEND, DL_DEBUG);
  }
  
--- 190,210 ----
  	current_command->output_list.append (out);
  	current_command->status |= RCommand::HasOutput;
  
  	RK_DO (qDebug ("output '%s'", buf), RBACKEND, DL_DEBUG);
+ 
+ // pass a signal to the main thread for real-time update of output
+ 	if (current_command->type () & RCommand::ImmediateOutput) {
+ 		if (!(current_command->receiver)) {
+ 			RK_ASSERT (false);
+ 			return;
+ 		}
+ 
+ 		QCustomEvent *event = new QCustomEvent (RCOMMAND_OUTPUT_EVENT);
+ 		ROutputContainer *outc = new ROutputContainer;
+ 		outc->output = out;
+ 		outc->command = current_command;
+ 		event->setData (outc);
+ 		qApp->postEvent (RKGlobals::rInterface (), event);
+ 	}
  }
  





More information about the rkward-tracker mailing list