bool PHPBackend::initialize (const QString &filename, RKComponentPropertyCode *code_property, bool add_headings) { RK_TRACE (PHP); if (php_process && php_process->isRunning ()) { RK_DO (qDebug ("another template is already openend in this backend"), PHP, DL_ERROR); return false; } php_process = new KProcess (); *php_process << RKSettingsModulePHP::phpBin(); // *php_process << "-a"; // run interactively. Does this have an effect? *php_process << (RKSettingsModulePHP::filesPath() + "/common.php"); // we have to be connect at all times! Otherwise the connection will be gone for good. //connect (php_process, SIGNAL (receivedStderr (KProcess *, char*, int)), this, SLOT (gotError (KProcess *, char*, int))); connect (php_process, SIGNAL (wroteStdin (KProcess *)), this, SLOT (doneWriting (KProcess* ))); connect (php_process, SIGNAL (receivedStdout (KProcess *, char*, int)), this, SLOT (gotOutput (KProcess *, char*, int))); if (!php_process->start (KProcess::NotifyOnExit, KProcess::All)) { KMessageBox::error (0, i18n ("The PHP backend could not be started. Check whether you have correctly configured the location of the PHP-binary (Settings->Configure Settings->PHP backend)"), i18n ("PHP-Error")); emit (haveError ()); return false; } busy_writing = doing_command = startup_done = false; busy = true; // start the real template callFunction ("include (\"" + filename + "\");", 0, Ignore); PHPBackend::code_property = code_property; PHPBackend::add_headings = add_headings; return true; }
void RKComponentScriptingProxy::handleScriptError (const QString& current_file) { RK_TRACE (PHP); QString file = current_file; if (file.isEmpty ()) file = _scriptfile; if (engine.hasUncaughtException ()) { QString message = i18n ("Script Error: %1\n", engine.uncaughtException ().toString ()); KMessageBox::detailedError (0, message, engine.uncaughtExceptionBacktrace ().join ("\n")); engine.clearExceptions (); emit (haveError()); } }
// Have a socket error, set m_errorString and propagate // signal void ApcUpsMon::socketError(QAbstractSocket::SocketError) { m_errorString = socket.errorString(); if (socket.state() != QAbstractSocket::ConnectedState) { // Attempt to reconnect in two timer intervals or, // failing that, ten seconds QTimer::singleShot((timer.interval() ? timer.interval() : 10000), this, SLOT(connectToHost())); } emit haveError(m_errorString); }
void PHPBackend::gotOutput (KProcess *, char* buf, int len) { RK_TRACE (PHP); QString output = buf; QString request; QString data; int i; bool have_data = true;; bool have_request = false; // is there a request in the output stream? if ((i = output.find (eot_string)) >= 0) { have_request = true; // is there also pending data? if (i) { data = output.left (i); } else { have_data = false; } request = output.mid (i + eot_string.length (), len); } else { data = output; } RK_DO (qDebug ("request: %s\ndata: %s", request.latin1 (), data.latin1 ()), PHP, DL_DEBUG); // pending data is always first in a stream, so process it first, too if (have_data) { if (!startup_done) { php_process->detach (); KMessageBox::error (0, i18n ("There has been an error\n(\"%1\")\nwhile starting up the PHP backend. Most likely this is due to either a bug in RKWard or an invalid setting for the location of the PHP support files. Check the settings (Settings->Configure Settings->PHP backend) and try again.").arg (data.stripWhiteSpace ()), i18n ("PHP-Error")); emit (haveError ()); destroy (); return; } _output.append (data); } if (have_request) { if (request == "requesting code") { 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) { if (add_headings) code_property->setPreprocess (i18n ("## Prepare\n") + retrieveOutput ()); else code_property->setPreprocess (retrieveOutput ()); resetOutput (); } else if (current_type == Calculate) { if (add_headings) code_property->setCalculate (i18n ("## Compute\n") + retrieveOutput ()); else code_property->setCalculate (retrieveOutput ()); resetOutput (); } else if (current_type == Printout) { if (add_headings) code_property->setPrintout (i18n ("## Print result\n") + retrieveOutput ()); else code_property->setPrintout (retrieveOutput ()); resetOutput (); } else if (current_type == Cleanup) { if (add_headings) code_property->setCleanup (i18n ("## Clean up\n") + retrieveOutput ()); else code_property->setCleanup (retrieveOutput ()); resetOutput (); } else { emit (commandDone (current_flags)); } } else { emit (commandDone (current_flags)); } } tryNextFunction (); if (!busy) { emit (idle ()); return; } } else if (request.startsWith ("requesting data:")) { QString requested_object = request.remove ("requesting data:"); RK_DO (qDebug ("requested data: \"%s\"", requested_object.latin1 ()), PHP, DL_DEBUG); emit (requestValue (requested_object)); busy = true; // writeData (res + eot_string); } else if (request.startsWith ("requesting rcall:")) { QString requested_call = request.remove ("requesting rcall:"); RK_DO (qDebug ("requested rcall: \"%s\"", requested_call.latin1 ()), PHP, DL_DEBUG); emit (requestRCall (requested_call)); busy = true; // _responsible->doRCall (requested_call); } else if (request.startsWith ("requesting rvector:")) { QString requested_call = request.remove ("requesting rvector:"); RK_DO (qDebug ("requested rvector: \"%s\"", requested_call.latin1 ()), PHP, DL_DEBUG); emit (requestRVector (requested_call)); busy = true; // _responsible->getRVector (requested_call); } else if (request.startsWith ("PHP-Error")) { QString error = request.remove ("PHP-Error"); php_process->detach (); KMessageBox::error (0, i18n ("The PHP-backend has reported an error\n(\"%1\")\nand has been shut down. This is most likely due to a bug in the plugin. But of course you may want to try to close and restart the plugin to see whether it works with different settings.").arg (error.stripWhiteSpace ()), i18n ("PHP-Error")); emit (haveError ()); destroy (); return; } return; } }