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 Q_OBJECT
00143 public:
00149 ~KLibLoader();
00150
00171 KLibFactory* factory( const char* libname );
00172
00193 virtual KLibrary* library( const char* libname );
00194
00217 KLibrary* globalLibrary( const char *name );
00218
00219
00220
00221
00222
00223
00224
00225
00226 QString lastErrorMessage() const;
00227
00242 virtual void unloadLibrary( const char *libname );
00243
00250 static KLibLoader* self();
00251
00260 static void cleanUp();
00261
00272 static QString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() );
00273
00274 protected:
00275 KLibLoader( QObject* parent = 0, const char* name = 0 );
00276
00277 private slots:
00278 void slotLibraryDestroyed();
00279 private:
00280 void close_pending( KLibWrapPrivate * );
00281 QAsciiDict<KLibWrapPrivate> m_libs;
00282
00283 static KLibLoader* s_self;
00284
00285 protected:
00286 virtual void virtual_hook( int id, void* data );
00287 private:
00288 KLibLoaderPrivate *d;
00289 };
00290
00326 class KLibFactory : public QObject
00327 {
00328 Q_OBJECT
00329 public:
00335 KLibFactory( QObject* parent = 0, const char* name = 0 );
00336 virtual ~KLibFactory();
00337
00359 QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() );
00360
00361 signals:
00366 void objectCreated( QObject *obj );
00367
00368
00369 protected:
00370
00387 virtual QObject* createObject( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() ) = 0;
00388
00389
00390 protected:
00391 virtual void virtual_hook( int id, void* data );
00392 private:
00393 KLibFactoryPrivate *d;
00394 };
00395
00396 #endif
This file is part of the documentation for kdelibs Version 3.1.0.