[Uml-devel] KDE/kdesdk/umbrello/umbrello

Sharan Rao sharanrao at gmail.com
Fri Aug 10 18:19:40 UTC 2007


SVN commit 698690 by sharan:

fix some race conditions and some memory leaks.



 M  +21 -2     docgenerators/docbookgenerator.cpp  
 M  +7 -0      docgenerators/docbookgenerator.h  
 M  +17 -5     docgenerators/xhtmlgenerator.cpp  
 M  +9 -1      docgenerators/xhtmlgenerator.h  
 M  +1 -0      uml.cpp  


--- trunk/KDE/kdesdk/umbrello/umbrello/docgenerators/docbookgenerator.cpp #698689:698690
@@ -22,6 +22,8 @@
 #include <kio/netaccess.h>
 #include <kio/job.h>
 
+#include <QApplication>
+
 #include <qfile.h>
 #include <qregexp.h>
 #include <qtextstream.h>
@@ -36,6 +38,8 @@
 {
   umlDoc = UMLApp::app()->getDocument();
   m_pStatus = true;
+  m_pThreadFinished = false;
+  docbookGeneratorJob = 0;
 }
 
 DocbookGenerator::~DocbookGenerator() {}
@@ -56,6 +60,7 @@
 {
     m_destDir = destDir;
     umlDoc->writeToStatusBar(i18n("Exporting all views..."));
+
     QStringList errors = UMLViewImageExporterModel().exportAllViews(
         UMLViewImageExporterModel::mimeTypeToImageType("image/png"), destDir, false);
     if (!errors.empty()) {
@@ -64,15 +69,17 @@
     }
 
     umlDoc->writeToStatusBar(i18n("Generating Docbook..."));
-    DocbookGeneratorJob* docbookGeneratorJob = new DocbookGeneratorJob( this );
+
+    docbookGeneratorJob = new DocbookGeneratorJob( this );
     connect( docbookGeneratorJob , SIGNAL(docbookGenerated(const QString&)), this, SLOT(slotDocbookGenerationFinished(const QString&)));
+    connect( docbookGeneratorJob, SIGNAL( finished() ), this, SLOT( threadFinished() ) );
     kDebug()<<k_funcinfo<<"Threading";
     docbookGeneratorJob->start();
 }
 
 void DocbookGenerator::slotDocbookGenerationFinished(const QString& tmpFileName)
 {
-    kDebug()<<"Generation Finished"<<tmpFileName;
+    kDebug()<<k_funcinfo<<"Generation Finished"<<tmpFileName;
     KUrl url = umlDoc->url();
     QString fileName = url.fileName();
     fileName.replace(QRegExp(".xmi$"),".docbook");
@@ -88,7 +95,19 @@
         m_pStatus = false;
     }
 
+    while ( m_pThreadFinished == false ) {
+        // wait for thread to finish
+        qApp->processEvents();
+    }
+
     emit finished(m_pStatus);
 }
 
+void DocbookGenerator::threadFinished() {
+    m_pThreadFinished = true;
+    delete docbookGeneratorJob;
+    docbookGeneratorJob = 0;
+}
+
+
 #include "docbookgenerator.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/docgenerators/docbookgenerator.h #698689:698690
@@ -23,6 +23,7 @@
 
 class UMLDoc;
 
+class DocbookGeneratorJob;
 /**
  * class DocbookGenerator is a documentation generator for UML documents.
  * It uses libxslt to convert the XMI generated by UMLDoc::saveToXMI through
@@ -78,9 +79,15 @@
   private slots:
   
     void slotDocbookGenerationFinished(const QString&);
+   
+    void threadFinished();
 
   private:
+
+    DocbookGeneratorJob* docbookGeneratorJob;
+
     bool m_pStatus;
+    bool m_pThreadFinished;
     KUrl m_destDir;
     UMLDoc* umlDoc;
 };
--- trunk/KDE/kdesdk/umbrello/umbrello/docgenerators/xhtmlgenerator.cpp #698689:698690
@@ -21,6 +21,8 @@
 #include <kio/netaccess.h>
 #include <kio/job.h>
 
+#include <QApplication>
+
 #include <qfile.h>
 #include <qregexp.h>
 #include <qtextstream.h>
@@ -35,6 +37,8 @@
 {
   umlDoc = UMLApp::app()->getDocument();
   m_pStatus = true;
+  m_pThreadFinished = false;
+  d2xg = 0;
 }
 
 XhtmlGenerator::~XhtmlGenerator(){}
@@ -79,9 +83,9 @@
     url.addPath(fileName);
 
     umlDoc->writeToStatusBar( i18n( "Generating XHTML..." ) );
-    Docbook2XhtmlGeneratorJob* d2xg  = new Docbook2XhtmlGeneratorJob( url, this );
+    d2xg  = new Docbook2XhtmlGeneratorJob( url, this );
     connect( d2xg, SIGNAL( xhtmlGenerated( const QString& ) ), this, SLOT( slotHtmlGenerated(const QString&) ) );
-    connect( d2xg, SIGNAL( finished() ), this, SLOT( cleanUpAndExit() ) );
+    connect( d2xg, SIGNAL( finished() ), this, SLOT( threadFinished() ) );
     kDebug()<<k_funcinfo<<"Threading";
     d2xg->start();
   }
@@ -90,7 +94,7 @@
 void XhtmlGenerator::slotHtmlGenerated(const QString& tmpFileName)
 {
 
-    kDebug() << "HTML Generated"<<tmpFileName;
+    kDebug() << k_funcinfo<< "HTML Generated"<<tmpFileName;
     KUrl url = umlDoc->url();
     QString fileName = url.fileName();
     fileName.replace(QRegExp(".xmi$"),".html");
@@ -120,10 +124,18 @@
         m_pStatus = false;
     }
 
-}
+    while ( m_pThreadFinished == false ) {
+        // wait for thread to finish
+        qApp->processEvents();
+    }
 
-void XhtmlGenerator::cleanUpAndExit() {
     emit finished( m_pStatus );
 }
 
+void XhtmlGenerator::threadFinished() {
+    m_pThreadFinished = true;
+    delete d2xg;
+    d2xg = 0;
+}
+
 #include "xhtmlgenerator.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/docgenerators/xhtmlgenerator.h #698689:698690
@@ -24,6 +24,7 @@
 
 class UMLDoc;
 
+class Docbook2XhtmlGeneratorJob;
 /**
  * class XhtmlGenerator is a documentation generator for UML documents.
  * It uses first @ref DocbookGenerator to convert the XMI generated by
@@ -91,10 +92,17 @@
      */
     void slotHtmlGenerated(const QString&);
 
-    void cleanUpAndExit();
+    /**
+     * Invoked when a thread is finished
+     */
+    void threadFinished();
+
   private:
 
+    Docbook2XhtmlGeneratorJob* d2xg;
+
     bool m_pStatus;
+    bool m_pThreadFinished;
     /** The destination directory where the final documentation will be
      * written.
      */
--- trunk/KDE/kdesdk/umbrello/umbrello/uml.cpp #698689:698690
@@ -992,6 +992,7 @@
 {
   DocbookGenerator* docbookGenerator = new DocbookGenerator;
   docbookGenerator->generateDocbookForProject();
+  connect( docbookGenerator, SIGNAL( finished( bool ) ), docbookGenerator, SLOT( deleteLater() ) );
 }
 
 void UMLApp::slotFileExportXhtml()




More information about the umbrello-devel mailing list