[rkward-cvs] rkward/rkward/rbackend rcommand.cpp, 1.7, 1.8 rcommand.h, 1.23, 1.24 rcommandreceiver.h, 1.6, 1.7 rinterface.cpp, 1.48, 1.49 rinterface.h, 1.22, 1.23

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Sep 1 15:38:19 UTC 2006


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

Modified Files:
	rcommand.cpp rcommand.h rcommandreceiver.h rinterface.cpp 
	rinterface.h 
Log Message:
Allow commands to have more than one receiver (and the command log is just a receiver that will always be added). Will allow for improvements of RKCancelDialog and probably RKErrorDialog

Index: rcommand.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rcommand.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** rcommand.h	5 May 2006 13:05:31 -0000	1.23
--- rcommand.h	1 Sep 2006 15:38:17 -0000	1.24
***************
*** 124,128 ****
  @param flags A freely assignable integer, that you can use to identify what the command was all about. Only the RCommandReceiver handling the results will have to know what exactly the flags mean.
  */
! 	RCommand(const QString &command, int type = 0, const QString &rk_equiv = QString::null, RCommandReceiver *receiver=0, int flags=0);
  /** destructor. Note: you should not delete RCommands manually. This is done in RInterface. TODO: make protected */
  	~RCommand();
--- 124,128 ----
  @param flags A freely assignable integer, that you can use to identify what the command was all about. Only the RCommandReceiver handling the results will have to know what exactly the flags mean.
  */
! 	RCommand (const QString &command, int type = 0, const QString &rk_equiv = QString::null, RCommandReceiver *receiver=0, int flags=0);
  /** destructor. Note: you should not delete RCommands manually. This is done in RInterface. TODO: make protected */
  	~RCommand();
***************
*** 207,215 ****
  /** return the flags associated with the command. Those are the same that you specified in the constructor, RKWard does not touch them. @see RCommand::RCommand */
  	int getFlags () { return (_flags); };
  private:
  friend class RThread;
  friend class RInterface;
! /** internal function will be called by the backend, as the command gets passed through. Takes care of sending this command (back) to its receiver */
  	void finished ();
  	QValueList<ROutput*> output_list;
  	QString _command;
--- 207,219 ----
  /** return the flags associated with the command. Those are the same that you specified in the constructor, RKWard does not touch them. @see RCommand::RCommand */
  	int getFlags () { return (_flags); };
+ /** Add an additional listener to the command */
+ 	void addReceiver (RCommandReceiver *receiver);
  private:
  friend class RThread;
  friend class RInterface;
! /** internal function will be called by the backend, as the command gets passed through. Takes care of sending this command (back) to its receiver(s) */
  	void finished ();
+ /** new output was generated. Pass on to receiver(s) */
+ 	void newOutput (ROutput *output);
  	QValueList<ROutput*> output_list;
  	QString _command;
***************
*** 226,230 ****
  	int _id;
  	static int next_id;
! 	RCommandReceiver *receiver;
  };
  
--- 230,235 ----
  	int _id;
  	static int next_id;
! 	int num_receivers;
! 	RCommandReceiver **receivers;
  };
  

Index: rinterface.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rinterface.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** rinterface.cpp	5 May 2006 13:18:06 -0000	1.48
--- rinterface.cpp	1 Sep 2006 15:38:17 -0000	1.49
***************
*** 116,121 ****
  	if (e->type () == RCOMMAND_OUTPUT_EVENT) {
  		RThread::ROutputContainer *container = (static_cast <RThread::ROutputContainer *> (e->data ()));
! 		if (container->command->receiver) container->command->receiver->newOutput (container->command, container->output);
! 		watch->addOutput (container->command, container->output);
  		delete container;
  
--- 116,120 ----
  	if (e->type () == RCOMMAND_OUTPUT_EVENT) {
  		RThread::ROutputContainer *container = (static_cast <RThread::ROutputContainer *> (e->data ()));
! 		container->command->newOutput (container->output);
  		delete container;
  
***************
*** 136,142 ****
  			out->output = ("--- interrupted ---");
  			command->output_list.append (out);
! 			if (command->receiver) {
! 				command->receiver->newOutput (command, out);
! 			}
  			if (running_command_canceled) {
  				RK_ASSERT (command == running_command_canceled);
--- 135,139 ----
  			out->output = ("--- interrupted ---");
  			command->output_list.append (out);
! 			command->newOutput (out);
  			if (running_command_canceled) {
  				RK_ASSERT (command == running_command_canceled);

Index: rinterface.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rinterface.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** rinterface.h	3 Nov 2005 15:24:56 -0000	1.22
--- rinterface.h	1 Sep 2006 15:38:17 -0000	1.23
***************
*** 101,104 ****
--- 101,105 ----
  	void processRCallbackRequest (RCallbackArgs *args);
  friend class RKwardApp;
+ friend class RCommand;
  /** pointer to the RKwatch. TODO: (re-)move this pointer */
  	RKwatch *watch;

Index: rcommandreceiver.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rcommandreceiver.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** rcommandreceiver.h	5 May 2006 13:05:31 -0000	1.6
--- rcommandreceiver.h	1 Sep 2006 15:38:17 -0000	1.7
***************
*** 19,23 ****
  
  /**
! Use this class as a base for all classes that need to handle RCommands. Provides a pure virtual function (rCommandDone ()) for handling of RCommand-results. Reimplement this to interpret the command-results.
  For windows/dialogs which interpret RCommand results, the receiver provides a special mechanism. The problem with those windows/dialogs is, that the user may close them, while there are still RCommands due to come in, i.e. they can't be deleted, but rather need to wait for the remaining results to come in.
  This class will keep track of which RCommands are still out there (and expected to return to this receiver). If you call deleteThis (), the RCommandReceiver will either self-destruct immediately or wait for any remaining commands to come in. Warning: This means, your class may be delelted immediately. You should return at once after calling deleteThis ().
--- 19,23 ----
  
  /**
! Use this class as a base for all classes that need to handle RCommands. Most importantly it provides a virtual function (rCommandDone ()) for handling of RCommand-results. Reimplement this to interpret the command-results.
  For windows/dialogs which interpret RCommand results, the receiver provides a special mechanism. The problem with those windows/dialogs is, that the user may close them, while there are still RCommands due to come in, i.e. they can't be deleted, but rather need to wait for the remaining results to come in.
  This class will keep track of which RCommands are still out there (and expected to return to this receiver). If you call deleteThis (), the RCommandReceiver will either self-destruct immediately or wait for any remaining commands to come in. Warning: This means, your class may be delelted immediately. You should return at once after calling deleteThis ().
***************
*** 44,48 ****
  /** 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. Default implementation does nothing. Reimplement if you want to get at a command's output immediately (i.e. before the command is fully completed).
  @param command A pointer to the command
--- 44,48 ----
  /** 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 *) {};
  /** This function is called when there is new output for a command or this receiver. Default implementation does nothing. Reimplement if you want to get at a command's output immediately (i.e. before the command is fully completed).
  @param command A pointer to the command

Index: rcommand.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/rbackend/rcommand.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** rcommand.cpp	23 Sep 2005 14:29:47 -0000	1.7
--- rcommand.cpp	1 Sep 2006 15:38:17 -0000	1.8
***************
*** 18,25 ****
--- 18,29 ----
  #include "rcommand.h"
  #include "rcommandreceiver.h"
+ #include "rinterface.h"
+ #include "../rkwatch.h"
  
  #include "../debug.h"
  #include "../rkglobals.h"
  
+ #define MAX_RECEIVERS 3
+ 
  int RCommand::next_id = 0;
  
***************
*** 40,45 ****
  	string_count = real_count = integer_count = 0;
  	_rk_equiv = rk_equiv;
! 	RCommand::receiver = receiver;
! 	if (receiver) receiver->addCommand ();
  }
  
--- 44,51 ----
  	string_count = real_count = integer_count = 0;
  	_rk_equiv = rk_equiv;
! 	RCommand::receivers = new RCommandReceiver* [MAX_RECEIVERS];
! 	num_receivers = 0;
! 	addReceiver (receiver);
! 	addReceiver (RKGlobals::rInterface ()->watch);
  }
  
***************
*** 59,67 ****
  }
  
  void RCommand::finished () {
  	RK_TRACE (RBACKEND);
! 	if (receiver) {
! 		receiver->rCommandDone (this);
! 		receiver->delCommand ();
  	}
  }
--- 65,97 ----
  }
  
+ void RCommand::addReceiver (RCommandReceiver *receiver) {
+ 	RK_TRACE (RBACKEND);
+ 
+ 	if (!receiver) return;
+ 
+ 	if (num_receivers >= MAX_RECEIVERS) {
+ 		RK_DO (qDebug ("Too many receivers for command"), RBACKEND, DL_ERROR);
+ 		return;
+ 	}
+ 
+ 	receivers[num_receivers++] = receiver;
+ 	receiver->addCommand ();
+ }
+ 
+ 
  void RCommand::finished () {
  	RK_TRACE (RBACKEND);
! 
! 	for (int i=0; i < num_receivers; ++i) {
! 		receivers[i]->rCommandDone (this);
! 		receivers[i]->delCommand ();
! 	}
! }
! 
! void RCommand::newOutput (ROutput *output) {
! 	RK_TRACE (RBACKEND);
! 
! 	for (int i=0; i < num_receivers; ++i) {
! 		receivers[i]->newOutput (this, output);
  	}
  }





More information about the rkward-tracker mailing list