KDECore
klibloader.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KLIBLOADER_H
00019 #define KLIBLOADER_H
00020
00021 #include <qobject.h>
00022 #include <qstring.h>
00023 #include <qstringlist.h>
00024 #include <qasciidict.h>
00025 #include <qptrlist.h>
00026 #include <kglobal.h>
00027
00028 #include <stdlib.h>
00029
00030 class KInstance;
00031 class QTimer;
00032 class KLibrary;
00033 class KLibFactory;
00034 class KLibFactoryPrivate;
00035 class KLibLoaderPrivate;
00036 class KLibraryPrivate;
00037
00038 # define K_EXPORT_COMPONENT_FACTORY( libname, factory ) \
00039 extern "C" { KDE_EXPORT void *init_##libname() { return new factory; } }
00040
00050 class KDECORE_EXPORT KLibrary : public QObject
00051 {
00052 friend class KLibLoader;
00053 friend class QAsciiDict<KLibrary>;
00054
00055 Q_OBJECT
00056 public:
00060 KLibrary( const QString& libname, const QString& filename, void * handle );
00061
00066 QString name() const;
00067
00072 QString fileName() const;
00073
00078 KLibFactory* factory();
00079
00089 void* symbol( const char* name ) const;
00090
00100 bool hasSymbol( const char* name ) const;
00101
00107 void unload() const;
00108
00109 private slots:
00110 void slotObjectCreated( QObject *obj );
00111 void slotObjectDestroyed();
00112 void slotTimeout();
00113
00114 private:
00119 ~KLibrary();
00120
00121 QString m_libname;
00122 QString m_filename;
00123 KLibFactory* m_factory;
00124 void * m_handle;
00125 QPtrList<QObject> m_objs;
00126 QTimer *m_timer;
00127 KLibraryPrivate *d;
00128 };
00129
00130 class KLibWrapPrivate;
00131
00142 class KDECORE_EXPORT KLibLoader : public QObject
00143 {
00144 friend class KLibrary;
00145
00146 Q_OBJECT
00147 public:
00153 ~KLibLoader();
00154
00175 KLibFactory* factory( const char* libname );
00176
00197 virtual KLibrary* library( const char* libname );
00198
00221 KLibrary* globalLibrary( const char *name );
00222
00230 QString lastErrorMessage() const;
00231
00246 virtual void unloadLibrary( const char *libname );
00247
00254 static KLibLoader* self();
00255
00264 static void cleanUp();
00265
00276 static QString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() );
00277
00278 protected:
00279 KLibLoader( QObject* parent = 0, const char* name = 0 );
00280
00281 private slots:
00282 void slotLibraryDestroyed();
00283 private:
00284 void close_pending( KLibWrapPrivate * );
00285 QAsciiDict<KLibWrapPrivate> m_libs;
00286
00287 static KLibLoader* s_self;
00288
00289 protected:
00290 virtual void virtual_hook( int id, void* data );
00291 private:
00292 KLibLoaderPrivate *d;
00293 };
00294
00333 class KDECORE_EXPORT KLibFactory : public QObject
00334 {
00335 Q_OBJECT
00336 public:
00342 KLibFactory( QObject* parent = 0, const char* name = 0 );
00343 virtual ~KLibFactory();
00344
00366 QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() );
00367
00368 signals:
00373 void objectCreated( QObject *obj );
00374
00375
00376 protected:
00377
00394 virtual QObject* createObject( QObject* parent = 0, const char* name = 0,
00395 const char* className = "QObject",
00396 const QStringList &args = QStringList() ) = 0;
00397
00398
00399 protected:
00400 virtual void virtual_hook( int id, void* data );
00401 private:
00402 KLibFactoryPrivate *d;
00403 };
00404
00405 #endif