Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Commit [d4b525] Maximize Restore History

renamed PluginWorkerThread -> WorkerThread, made usable through generic interface 'Runnable'

Thomas Eschenbacher Thomas Eschenbacher 2012-12-30

added libkwave/Runnable.h
changed libkwave/CMakeLists.txt
changed libkwave/Plugin.cpp
changed libkwave/Plugin.h
changed plugins/record/RecordThread.cpp
changed plugins/record/RecordThread.h
changed LICENSES
copied libkwave/PluginWorkerThread.cpp -> libkwave/WorkerThread.cpp
copied libkwave/PluginWorkerThread.h -> libkwave/WorkerThread.h
libkwave/Runnable.h Diff Switch to side-by-side view
Loading...
libkwave/CMakeLists.txt Diff Switch to side-by-side view
Loading...
libkwave/Plugin.cpp Diff Switch to side-by-side view
Loading...
libkwave/Plugin.h Diff Switch to side-by-side view
Loading...
plugins/record/RecordThread.cpp Diff Switch to side-by-side view
Loading...
plugins/record/RecordThread.h Diff Switch to side-by-side view
Loading...
LICENSES Diff Switch to side-by-side view
Loading...
libkwave/PluginWorkerThread.cpp to libkwave/WorkerThread.cpp
--- a/libkwave/PluginWorkerThread.cpp
+++ b/libkwave/WorkerThread.cpp
@@ -1,5 +1,5 @@
 /***************************************************************************
-    libkwave/PluginWorkerThread.cpp  -  worker thread for Kwave plugins
+    libkwave/WorkerThread.cpp  -  worker thread for Kwave
                              -------------------
     begin                : Sun Apr 06 2008
     copyright            : (C) 2008 by Thomas Eschenbacher
@@ -30,8 +30,8 @@
 #include <error.h>   // for strerror()
 #endif
 
-#include "libkwave/Plugin.h"
-#include "libkwave/PluginWorkerThread.h"
+#include "libkwave/Runnable.h"
+#include "libkwave/WorkerThread.h"
 
 //***************************************************************************
 extern "C" void _dummy_SIGHUP_handler(int)
@@ -40,10 +40,10 @@
 }
 
 //***************************************************************************
-Kwave::PluginWorkerThread::PluginWorkerThread(Kwave::Plugin *plugin,
-                                              QStringList params)
-    :QThread(plugin),
-     m_plugin(plugin),
+Kwave::WorkerThread::WorkerThread(Kwave::Runnable *runnable,
+                                              QVariant params)
+    :QThread(0),
+     m_runnable(runnable),
      m_params(params),
      m_lock(), m_lock_sighup(),
      m_should_stop(false),
@@ -54,19 +54,19 @@
 }
 
 //***************************************************************************
-Kwave::PluginWorkerThread::~PluginWorkerThread()
+Kwave::WorkerThread::~WorkerThread()
 {
     if (isRunning()) {
-	qDebug("PluginWorkerThread::~PluginWorkerThread(): waiting for normal shutdown");
+	qDebug("WorkerThread::~WorkerThread(): waiting for normal shutdown");
 	wait(2000);
-	qDebug("PluginWorkerThread::~PluginWorkerThread(): stopping");
+	qDebug("WorkerThread::~WorkerThread(): stopping");
 	stop(2000);
     }
     Q_ASSERT(!isRunning());
 }
 
 //***************************************************************************
-void Kwave::PluginWorkerThread::start()
+void Kwave::WorkerThread::start()
 {
     QMutexLocker lock(&m_lock);
 
@@ -77,7 +77,7 @@
 }
 
 //***************************************************************************
-int Kwave::PluginWorkerThread::stop(unsigned int timeout)
+int Kwave::WorkerThread::stop(unsigned int timeout)
 {
     QMutexLocker lock(&m_lock);
     if (!isRunning()) return 0; // already down
@@ -101,7 +101,7 @@
     if (!isRunning()) return 0;
 
     // try to interrupt by INT signal
-    qWarning("PluginWorkerThread::stop(): sending SIGHUP");
+    qWarning("WorkerThread::stop(): sending SIGHUP");
     for (unsigned int i=0; i < 8; i++) {
 	{
 	    QMutexLocker _lock(&m_lock_sighup);
@@ -116,7 +116,7 @@
 
 #ifdef DEBUG_FIND_DEADLOCKS
     if (running()) {
-	qDebug("PluginWorkerThread::stop(): pthread_self()=%08X",
+	qDebug("WorkerThread::stop(): pthread_self()=%08X",
 	       (unsigned int)pthread_self());
 	void *buf[256];
 	size_t n = backtrace(buf, 256);
@@ -124,19 +124,19 @@
     }
 #endif
 
-    qDebug("PluginWorkerThread::stop(): canceling thread");
+    qDebug("WorkerThread::stop(): canceling thread");
     terminate();
 
     return -1;
 }
 
 //***************************************************************************
-void Kwave::PluginWorkerThread::run()
+void Kwave::WorkerThread::run()
 {
     sighandler_t old_handler;
 
-    Q_ASSERT(m_plugin);
-    if (!m_plugin) return;
+    Q_ASSERT(m_runnable);
+    if (!m_runnable) return;
 
     /* install a SIGHUP handler and allow sending SIGHUP */
     {
@@ -149,8 +149,8 @@
 	old_handler = signal(SIGHUP, _dummy_SIGHUP_handler);
     }
 
-    /* call the plugin's run(...) function */
-    m_plugin->run_wrapper(m_params);
+    /* call the run(...) function */
+    m_runnable->run_wrapper(m_params);
 
     /* uninstall the SIGHUP handler and forbid sending SIGHUP */
     {
@@ -165,12 +165,12 @@
 }
 
 //***************************************************************************
-bool Kwave::PluginWorkerThread::shouldStop()
+bool Kwave::WorkerThread::shouldStop()
 {
     return (m_should_stop);
 }
 
 //***************************************************************************
-#include "PluginWorkerThread.moc"
+#include "WorkerThread.moc"
 //***************************************************************************
 //***************************************************************************
libkwave/PluginWorkerThread.h to libkwave/WorkerThread.h
--- a/libkwave/PluginWorkerThread.h
+++ b/libkwave/WorkerThread.h
@@ -1,5 +1,5 @@
 /***************************************************************************
-    libkwave/PluginWorkerThread.h  -  worker thread for Kwave plugins
+    libkwave/WorkerThread.h  -  worker thread for Kwave
                              -------------------
     begin                : Sun Apr 06 2008
     copyright            : (C) 2008 by Thomas Eschenbacher
@@ -15,33 +15,33 @@
  *                                                                         *
  ***************************************************************************/
 
-#ifndef _PLUGIN_WORKER_THREAD_H_
-#define _PLUGIN_WORKER_THREAD_H_
+#ifndef _WORKER_THREAD_H_
+#define _WORKER_THREAD_H_
 
 #include "config.h"
 #include <pthread.h>
 
 #include <QtCore/QMutex>
 #include <QtCore/QObject>
-#include <QtCore/QStringList>
 #include <QtCore/QThread>
+#include <QtCore/QVariant>
 
 #include <kdemacros.h>
 
 namespace Kwave
 {
-    class Plugin;
+    class Runnable;
 
-    class KDE_EXPORT PluginWorkerThread : public QThread
+    class KDE_EXPORT WorkerThread : public QThread
     {
 	Q_OBJECT
     public:
 
 	/** Constructor */
-	PluginWorkerThread(Kwave::Plugin *plugin, QStringList params);
+	explicit WorkerThread(Kwave::Runnable *runnable, QVariant params);
 
 	/** Destructor, calls stop() if the thread is still running. */
-	virtual ~PluginWorkerThread();
+	virtual ~WorkerThread();
 
 	/** Starts the thread's execution. */
 	virtual void start();
@@ -56,8 +56,8 @@
 	virtual int stop(unsigned int timeout = 10000);
 
 	/**
-	 * A wrapper for the run() function, calls the run(...) function
-	 * of m_plugin with the parameters stored in m_params.
+	 * A wrapper for the run() function, calls the run_wrapper(...)
+	 * of m_runnable with the parameters passed in the constructor.
 	 */
 	virtual void run();
 
@@ -70,11 +70,11 @@
 
     private:
 
-	/** pointer to the Kwave plugin that has a run() function */
-	Kwave::Plugin *m_plugin;
+	/** pointer to the object that has a run() function */
+	Kwave::Runnable *m_runnable;
 
-	/** parameter list passed to the m_plugin's run() function */
-	QStringList m_params;
+	/** parameter pointer passed to the run() function */
+	QVariant m_params;
 
 	/** Mutex to control access to the thread itself */
 	QMutex m_lock;
@@ -99,7 +99,7 @@
 
 }
 
-#endif /* _PLUGIN_WORKER_THREAD_H_ */
+#endif /* _WORKER_THREAD_H_ */
 
 //***************************************************************************
 //***************************************************************************