Author: dmacvicar Date: Thu Aug 2 12:38:05 2007 New Revision: 6383 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6383&view=rev Log: use incremental xml parsing Modified: trunk/updater-kde/updater/zypp/ZYppUpdater.cpp trunk/updater-kde/updater/zypp/ZYppUpdater.h Modified: trunk/updater-kde/updater/zypp/ZYppUpdater.cpp URL: http://svn.opensuse.org/viewcvs/zypp/trunk/updater-kde/updater/zypp/ZYppUpdater.cpp?rev=6383&r1=6382&r2=6383&view=diff ============================================================================== --- trunk/updater-kde/updater/zypp/ZYppUpdater.cpp (original) +++ trunk/updater-kde/updater/zypp/ZYppUpdater.cpp Thu Aug 2 12:38:05 2007 @@ -59,7 +59,6 @@ , _patchList(0) , _packageList(0) , _found_update_status_tag(false) - , _end_document_reached(false) , _error(false) , restartUpdater(false) @@ -69,6 +68,11 @@ // For ease announce that we have been loaded. kdDebug() << "ZyppUpdater plugin loaded" << endl; kdDebug() << "Initializing zypp backend" << endl; + + _xml_reader.setContentHandler(this); + _xml_reader.parse( &_xml_source, + true /* incremental parsing*/); + } UpdaterCapabilities ZYppUpdater::capabilities() @@ -157,14 +161,9 @@ _process = 0L; // parse the xml - QXmlInputSource xml_source; - xml_source.setData(_buffer); - QXmlSimpleReader reader; - reader.setContentHandler(this); - reader.parse(xml_source); - if ( !_end_document_reached ) + if ( ! _last_xml_parse_code ) { kdDebug() << "Houston, we have a problem." << endl; if ( _buffer.isEmpty() && !_stderr_buffer.isEmpty() ) @@ -179,6 +178,10 @@ // clear the buffer _stderr_buffer.truncate(0); _buffer.truncate(0); + + // remove if 2 programs are run at the same time + _xml_source.reset(); + emit(populateDone()); return; } @@ -243,14 +246,26 @@ void ZYppUpdater::slotReceivedStdout(KProcess *proc, char *buffer, int buflen) { - kdDebug() << "got..." << endl; - // add stdout to a buffer - // we can parse it when process finishes - _buffer += QString::fromUtf8( buffer, buflen ); + kdDebug() << "got data... Xml buffer size (before): " << _xml_source.data().length() << endl; + + // refill the xml data + _xml_source.setData( QString::fromUtf8(buffer, buflen) ); + kdDebug() << "Xml buffer size (after): " << _xml_source.data().length() << endl; + // continue incremental parsing + if ( buflen > 0 ) + _last_xml_parse_code = _xml_reader.parseContinue(); + + if ( !_last_xml_parse_code ) + { + kdDebug() << "Incremental parsing error. should we reset the Xml source? buffer size: " << _xml_source.data().length() << endl; + //_xml_source.reset() + } } void ZYppUpdater::slotInstallReceivedStdout(KProcess *proc, char *buffer, int buflen) { + // move this code when zypper outputs xml + // We show the progress popup casue we have got the first answer from install process. if (_install_stdout_buffer.isEmpty()) emit(showProgress(true)); @@ -271,18 +286,6 @@ } -void ZYppUpdater::slotInstallReceivedStderr(KProcess *proc, char *buffer, int buflen) -{ - kdDebug() << "got stderror from install helper..." << endl; - kdDebug() << buffer << endl; - - _install_stderr_buffer += QString::fromUtf8( buffer, buflen ); -} - - - - - void ZYppUpdater::slotReceivedStderr(KProcess *proc, char *buffer, int buflen) { _stderr_buffer += QString::fromUtf8( buffer, buflen ); @@ -346,8 +349,6 @@ doCheckForUpdates(); } - - void ZYppUpdater::resolvableSelected(QListViewItem *item, int resolvableType) { // retrieve description @@ -364,10 +365,6 @@ } } - - - - void ZYppUpdater::startInstall() { if (!_patchList || !_packageList) @@ -377,8 +374,6 @@ return; } - - QStringList installPatchList; QStringList installPackageList; QStringList installPkgMgrList; @@ -452,13 +447,19 @@ *_install_process << command << "--patch" << installPatchList << "--package" << installPackageList << "--pkgmgr" << installPkgMgrList; +// QObject::connect( _install_process, SIGNAL( processExited( KProcess * ) ), +// SLOT( slotInstallProcessExited( KProcess * ) ) ); +// QObject::connect( _install_process, SIGNAL( receivedStdout(KProcess *, char *, int ) ), +// SLOT( slotInstallReceivedStdout(KProcess *, char *, int ) ) ); +// QObject::connect( _install_process, SIGNAL( receivedStderr(KProcess *, char *, int ) ), +// SLOT( slotInstallReceivedStderr(KProcess *, char *, int ) ) ); + QObject::connect( _install_process, SIGNAL( processExited( KProcess * ) ), - SLOT( slotInstallProcessExited( KProcess * ) ) ); + SLOT( slotProcessExited( KProcess * ) ) ); QObject::connect( _install_process, SIGNAL( receivedStdout(KProcess *, char *, int ) ), - SLOT( slotInstallReceivedStdout(KProcess *, char *, int ) ) ); + SLOT( slotReceivedStdout(KProcess *, char *, int ) ) ); QObject::connect( _install_process, SIGNAL( receivedStderr(KProcess *, char *, int ) ), - SLOT( slotInstallReceivedStderr(KProcess *, char *, int ) ) ); - + SLOT( slotReceivedStderr(KProcess *, char *, int ) ) ); bool result = _install_process->start( KProcess::NotifyOnExit, KProcess::AllOutput ); if ( ! result ) @@ -498,7 +499,6 @@ { kdDebug() << "start document..." << endl; _found_update_status_tag = false; - _end_document_reached = false; _error = false; _resolvables.setAutoDelete(true); _resolvables.clear(); @@ -607,14 +607,7 @@ bool ZYppUpdater::endDocument() { - _end_document_reached = true; kdDebug() << "end document" << endl; -/* if ( ! _found_update_status_tag ) - { - kdDebug() << "Wrong xml output" << endl; - emit(updateAppletError(_buffer)); - return false; - } */ return true; } Modified: trunk/updater-kde/updater/zypp/ZYppUpdater.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/updater-kde/updater/zypp/ZYppUpdater.h?rev=6383&r1=6382&r2=6383&view=diff ============================================================================== --- trunk/updater-kde/updater/zypp/ZYppUpdater.h (original) +++ trunk/updater-kde/updater/zypp/ZYppUpdater.h Thu Aug 2 12:38:05 2007 @@ -143,7 +143,6 @@ void slotInstallProcessExited( KProcess * ); void slotInstallReceivedStdout(KProcess *, char *, int ) ; - void slotInstallReceivedStderr(KProcess *, char *, int ) ; @@ -186,13 +185,17 @@ QListView *_patchList; QListView *_packageList; bool _found_update_status_tag; - bool _end_document_reached; + bool _last_xml_parse_code; bool _error; // QProgressDialog *progressDialog; LicenseDialog *licenseDialog; bool restartUpdater; + + // Continous xml parsing + QXmlInputSource _xml_source; + QXmlSimpleReader _xml_reader; }; #endif -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org