[rkward-cvs] rkward/rkward/scriptbackends phpbackend.cpp,1.10,1.11 phpbackend.h,1.3,1.4 scriptbackend.h,1.3,1.4

Thomas Friedrichsmeier tfry at users.sourceforge.net
Sun Mar 19 16:41:28 UTC 2006


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

Modified Files:
	phpbackend.cpp phpbackend.h scriptbackend.h 
Log Message:
RKStandardComponent code generation/display works

Index: scriptbackend.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/scriptbackends/scriptbackend.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** scriptbackend.h	24 Nov 2005 12:35:46 -0000	1.3
--- scriptbackend.h	19 Mar 2006 16:41:26 -0000	1.4
***************
*** 22,25 ****
--- 22,27 ----
  #include <qstring.h>
  
+ class RKComponentPropertyCode;
+ 
  /**
  Abstract base class for scripting-language backends. Mostly pure virtual functions only.
***************
*** 30,38 ****
  	Q_OBJECT
  public:
!     ScriptBackend();
  
!     ~ScriptBackend();
! 	
! 	virtual bool initialize (const QString &filename) = 0;
  	virtual void destroy () = 0;
  	
--- 32,53 ----
  	Q_OBJECT
  public:
! 	ScriptBackend ();
  
! 	~ScriptBackend ();
! 
! 	enum CallType {
! 		Preprocess = 0,
! 		Calculate = 1,
! 		Printout = 2,
! 		Cleanup = 3,
! 		Ignore = 4,
! 		User = 5
! 	};
! 
! /** initialize backend
! @param filename Filename of the template to work on
! @param code_property If you supply a pointer to an RKComponentPropertyCode, The backend will directly set values for this property in response to calls to preproces (), calculate (), printout (), and cleanup ().
! @returns true on successful initialization, false on errors */
! 	virtual bool initialize (const QString &filename, RKComponentPropertyCode *code_property=0) = 0;
  	virtual void destroy () = 0;
  	
***************
*** 56,59 ****
--- 71,75 ----
  	void haveError ();
  protected:
+ 	RKComponentPropertyCode *code_property;
  	QString _output;
  	bool busy;

Index: phpbackend.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/scriptbackends/phpbackend.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** phpbackend.h	24 Nov 2005 12:35:46 -0000	1.3
--- phpbackend.h	19 Mar 2006 16:41:26 -0000	1.4
***************
*** 41,51 ****
  	~PHPBackend ();
  
! 	bool initialize (const QString &filename);
  	void destroy ();
  	
! 	void preprocess (int flags) { callFunction ("preprocess ();", flags); };
! 	void calculate (int flags) { callFunction ("calculate ();", flags); };
! 	void printout (int flags) { callFunction ("printout ();", flags); };
! 	void cleanup (int flags) { callFunction ("cleanup ();", flags); };
  	void writeData (const QString &data);
  public slots:
--- 41,51 ----
  	~PHPBackend ();
  
! 	bool initialize (const QString &filename, RKComponentPropertyCode *code_property=0);
  	void destroy ();
  	
! 	void preprocess (int flags) { callFunction ("preprocess ();", flags, Preprocess); };
! 	void calculate (int flags) { callFunction ("calculate ();", flags, Calculate); };
! 	void printout (int flags) { callFunction ("printout ();", flags, Printout); };
! 	void cleanup (int flags) { callFunction ("cleanup ();", flags, Cleanup); };
  	void writeData (const QString &data);
  public slots:
***************
*** 72,84 ****
  	/// flags attached to this command by the parent
  		int flags;
  	/// whether command has finished
  		bool complete;
  	};
! 	QValueList <PHPCommand *> command_stack;
  
  	int current_flags;
! 	
  /** call a PHP-function on the current template. */
! 	void callFunction (const QString &function, int flags);
  };
  
--- 72,90 ----
  	/// flags attached to this command by the parent
  		int flags;
+ 	/// internal type (used to find out, if this is a preproces, calculate, printout, or cleanup call)
+ 		int type;
  	/// whether command has finished
  		bool complete;
  	};
! 	QValueList<PHPCommand *> command_stack;
  
  	int current_flags;
! 	int current_type;
! 
! /** Invalidate all previous calls of the given type */
! 	void invalidateCalls (int type);
! 
  /** call a PHP-function on the current template. */
! 	void callFunction (const QString &function, int flags, int type);
  };
  

Index: phpbackend.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/scriptbackends/phpbackend.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** phpbackend.cpp	15 Mar 2006 13:21:19 -0000	1.10
--- phpbackend.cpp	19 Mar 2006 16:41:26 -0000	1.11
***************
*** 25,28 ****
--- 25,29 ----
  
  #include "../settings/rksettingsmodulephp.h"
+ #include "../plugin/rkcomponentproperties.h"
  #include "../debug.h"
  
***************
*** 42,46 ****
  }
  
! bool PHPBackend::initialize (const QString &filename) {
  	RK_TRACE (PHP);
  
--- 43,47 ----
  }
  
! bool PHPBackend::initialize (const QString &filename, RKComponentPropertyCode *code_property) {
  	RK_TRACE (PHP);
  
***************
*** 68,75 ****
  	busy_writing = doing_command = startup_done = false;
  	busy = true;
! 		
  	// start the real template
! 	callFunction ("include (\"" + filename + "\");", 0);
! 		
  	return true;
  }
--- 69,77 ----
  	busy_writing = doing_command = startup_done = false;
  	busy = true;
! 
  	// start the real template
! 	callFunction ("include (\"" + filename + "\");", 0, Ignore);
! 
! 	PHPBackend::code_property = code_property;
  	return true;
  }
***************
*** 93,97 ****
  }
  
! void PHPBackend::callFunction (const QString &function, int flags) {
  	RK_TRACE (PHP);
  	RK_DO (qDebug ("callFunction %s", function.latin1 ()), PHP, DL_DEBUG);
--- 95,99 ----
  }
  
! void PHPBackend::callFunction (const QString &function, int flags, int type) {
  	RK_TRACE (PHP);
  	RK_DO (qDebug ("callFunction %s", function.latin1 ()), PHP, DL_DEBUG);
***************
*** 100,112 ****
  	command->command = function;
  	command->flags = flags;
  	command->complete = false;
  	command_stack.append (command);
  	tryNextFunction ();
  }
  
  void PHPBackend::tryNextFunction () {
  	RK_TRACE (PHP);
  
! 	if ((!busy_writing) && php_process && php_process->isRunning () && (!busy) && command_stack.count ()) {
  	/// clean up previous command if applicable
  		if (command_stack.first ()->complete) {
--- 102,150 ----
  	command->command = function;
  	command->flags = flags;
+ 	command->type = type;
  	command->complete = false;
+ 
+ 	if (code_property) {
+ 		if (type == Preprocess) {
+ 			code_property->setPreprocess (QString::null);
+ 			invalidateCalls (Preprocess);
+ 		} else if (type == Calculate) {
+ 			code_property->setCalculate (QString::null);
+ 			invalidateCalls (Calculate);
+ 		} else if (type == Printout) {
+ 			code_property->setPrintout (QString::null);
+ 			invalidateCalls (Printout);
+ 		} else if (type == Cleanup) {
+ 			code_property->setCleanup (QString::null);
+ 		}
+ 	}
+ 
  	command_stack.append (command);
  	tryNextFunction ();
  }
  
+ void PHPBackend::invalidateCalls (int type) {
+ 	RK_TRACE (PHP);
+ 
+ 	if (current_type == type) {
+ 		current_type = Ignore;
+ 	}
+ 
+ 	QValueList<PHPCommand *>::iterator it = command_stack.begin ();
+ 	while (it != command_stack.end ()) {
+ 		if ((*it)->type == type) {
+ 			delete (*it);
+ 			it = command_stack.erase (it);		// it now points to next item
+ 		} else {
+ 			++it;
+ 		}
+ 	}
+ }
+ 
+ 
  void PHPBackend::tryNextFunction () {
  	RK_TRACE (PHP);
  
! 	if ((!busy_writing) && php_process && php_process->isRunning () && (!busy) && (!command_stack.isEmpty ())) {
  	/// clean up previous command if applicable
  		if (command_stack.first ()->complete) {
***************
*** 123,126 ****
--- 161,165 ----
  		command_stack.first ()->complete = true;
  		current_flags = command_stack.first ()->flags;
+ 		current_type = command_stack.first ()->type;
  	}
  }
***************
*** 135,139 ****
  	RK_TRACE (PHP);
  
! 	if ((!busy_writing) && php_process && php_process->isRunning () && busy && (data_stack.count ())) {
  		RK_DO (qDebug ("submitting data: %s", data_stack.first ().latin1 ()), PHP, DL_DEBUG);
  		php_process->writeStdin (data_stack.first ().latin1 (), data_stack.first ().length ());
--- 174,178 ----
  	RK_TRACE (PHP);
  
! 	if ((!busy_writing) && php_process && php_process->isRunning () && busy && (!data_stack.isEmpty ())) {
  		RK_DO (qDebug ("submitting data: %s", data_stack.first ().latin1 ()), PHP, DL_DEBUG);
  		php_process->writeStdin (data_stack.first ().latin1 (), data_stack.first ().length ());
***************
*** 143,147 ****
  }
  
! void PHPBackend::doneWriting (KProcess *proc) {
  	RK_TRACE (PHP);
  
--- 182,186 ----
  }
  
! void PHPBackend::doneWriting (KProcess *) {
  	RK_TRACE (PHP);
  
***************
*** 149,155 ****
  	if (!doing_command) data_stack.pop_front ();
  	tryWriteData ();
  }
  
! void PHPBackend::gotOutput (KProcess *proc, char* buf, int len) {
  	RK_TRACE (PHP);
  
--- 188,195 ----
  	if (!doing_command) data_stack.pop_front ();
  	tryWriteData ();
+ 	tryNextFunction ();
  }
  
! void PHPBackend::gotOutput (KProcess *, char* buf, int len) {
  	RK_TRACE (PHP);
  
***************
*** 192,196 ****
  			startup_done = true;
  			busy = false;
! 			emit (commandDone (current_flags));
  			tryNextFunction ();
  			if (!busy) {
--- 232,258 ----
  			startup_done = true;
  			busy = false;
! 			RK_DO (qDebug ("got type: %d, stack %d", current_type, command_stack.count ()), PHP, DL_DEBUG);
! 			if (current_type != Ignore) {
! 				if (code_property) {
! 					if (_output.isNull ()) _output = "";			// must not be null for the code property!
! 					if (current_type == Preprocess) {
! 						code_property->setPreprocess (retrieveOutput ());
! 						resetOutput ();
! 					} else if (current_type == Calculate) {
! 						code_property->setCalculate (retrieveOutput ());
! 						resetOutput ();
! 					} else if (current_type == Printout) {
! 						code_property->setPrintout (retrieveOutput ());
! 						resetOutput ();
! 					} else if (current_type == Cleanup) {
! 						code_property->setCleanup (retrieveOutput ());
! 						resetOutput ();
! 					} else {
! 						emit (commandDone (current_flags));
! 					}
! 				} else {
! 					emit (commandDone (current_flags));
! 				}
! 			}
  			tryNextFunction ();
  			if (!busy) {





More information about the rkward-tracker mailing list