klibloader.h
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" { void *init_##libname() { return new factory; } }
00040
00048 class KLibrary : public QObject
00049 {
00050 friend class KLibLoader;
00051 friend class QAsciiDict<KLibrary>;
00052
00053 Q_OBJECT
00054 public:
00059 KLibrary( const QString& libname, const QString& filename, void * handle );
00060
00065 QString name() const;
00066
00071 QString fileName() const;
00072
00077 KLibFactory* factory();
00078
00088 void* symbol( const char* name ) const;
00089
00099 bool hasSymbol( const char* name ) const;
00100
00106 void unload() const;
00107
00108 private slots:
00109 void slotObjectCreated( QObject *obj );
00110 void slotObjectDestroyed();
00111 void slotTimeout();
00112
00113 private:
00118 ~KLibrary();
00119
00120 QString m_libname;
00121 QString m_filename;
00122 KLibFactory* m_factory;
00123 void * m_handle;
00124 QPtrList<QObject> m_objs;
00125 QTimer *m_timer;
00126 KLibraryPrivate *d;
00127 };
00128
00129 class KLibWrapPrivate;
00130
00140 class KLibLoader : public QObject
00141 {
00142 friend class KLibrary;
00143
00144 Q_OBJECT
00145 public:
00151 ~KLibLoader();
00152
00173 KLibFactory* factory( const char* libname );
00174
00195 virtual KLibrary* library( const char* libname );
00196
00219 KLibrary* globalLibrary( const char *name );
00220
00221
00222
00223
00224
00225
00226
00227
00228 QString lastErrorMessage() const;
00229
00244 virtual void unloadLibrary( const char *libname );
00245
00252 static KLibLoader* self();
00253
00262 static void cleanUp();
00263
00274 static QString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() );
00275
00276 protected:
00277 KLibLoader( QObject* parent = 0, const char* name = 0 );
00278
00279 private slots:
00280 void slotLibraryDestroyed();
00281 private:
00282 void close_pending( KLibWrapPrivate * );
00283 QAsciiDict<KLibWrapPrivate> m_libs;
00284
00285 static KLibLoader* s_self;
00286
00287 protected:
00288 virtual void virtual_hook( int id, void* data );
00289 private:
00290 KLibLoaderPrivate *d;
00291 };
00292
00328 class KLibFactory : public QObject
00329 {
00330 Q_OBJECT
00331 public:
00337 KLibFactory( QObject* parent = 0, const char* name = 0 );
00338 virtual ~KLibFactory();
00339
00361 QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() );
00362
00363 signals:
00368 void objectCreated( QObject *obj );
00369
00370
00371 protected:
00372
00389 virtual QObject* createObject( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() ) = 0;
00390
00391
00392 protected:
00393 virtual void virtual_hook( int id, void* data );
00394 private:
00395 KLibFactoryPrivate *d;
00396 };
00397
00398 #endif
This file is part of the documentation for kdelibs Version 3.1.5.