00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef DIGESTCONTROLLERTHREADHOST_H
00026 #define DIGESTCONTROLLERTHREADHOST_H
00027
00028
00029 #include <QThread>
00030
00031 #include <QCoreApplication>
00032
00033 #include <jni.h>
00034
00035 #include "abstractmodel.h"
00036
00037
00038 template <class T>
00039 class DigestControllerThreadHost : public QThread {
00040
00041 public:
00042 DigestControllerThreadHost( JavaVM* jvm, QObject* parent = 0 )
00043 : QThread(parent),
00044 m_jvm(jvm),
00045 m_initialModel(0) {}
00046
00047 DigestControllerThreadHost( AbstractModel* model,
00048 JavaVM* jvm, QObject* parent = 0 )
00049 : QThread(parent),
00050 m_jvm(jvm),
00051 m_initialModel(model) {}
00052
00053 virtual ~DigestControllerThreadHost() {
00054 quit();
00055 wait();
00056
00057 }
00058
00059 T* controller() const { return m_controller; }
00060
00061
00062 protected:
00063 virtual void run()
00064 {
00065
00066
00067
00068
00069 m_controller = new T( m_jvm );
00070 if ( m_initialModel != 0 )
00071 QCoreApplication::postEvent( m_controller,
00072 new CChangeModelEvent(m_initialModel, this) );
00073 exec();
00074 delete m_controller;
00075 m_controller = 0;
00076 }
00077
00078
00079 private:
00080 T* m_controller;
00081 JavaVM* m_jvm;
00082 AbstractModel* m_initialModel;
00083 };
00084
00085
00086 #endif // ! DIGESTCONTROLLERTHREADHOST_H