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
00050 class KLibrary : public QObject
00051 {
00052 friend class KLibLoader;
00053 friend class QAsciiDict<KLibrary>;
00054
00055 Q_OBJECT
00056 public:
00061 KLibrary( const QString& libname, const QString& filename, void * handle );
00062
00067 QString name() const;
00068
00073 QString fileName() const;
00074
00079 KLibFactory* factory();
00080
00090 void* symbol( const char* name ) const;
00091
00101 bool hasSymbol( const char* name ) const;
00102
00108 void unload() const;
00109
00110 private slots:
00111 void slotObjectCreated( QObject *obj );
00112 void slotObjectDestroyed();
00113 void slotTimeout();
00114
00115 private:
00120 ~KLibrary();
00121
00122 QString m_libname;
00123 QString m_filename;
00124 KLibFactory* m_factory;
00125 void * m_handle;
00126 QPtrList<QObject> m_objs;
00127 QTimer *m_timer;
00128 KLibraryPrivate *d;
00129 };
00130
00131 class KLibWrapPrivate;
00132
00143 class KLibLoader : public QObject
00144 {
00145 friend class KLibrary;
00146
00147 Q_OBJECT
00148 public:
00154 ~KLibLoader();
00155
00176 KLibFactory* factory( const char* libname );
00177
00198 virtual KLibrary* library( const char* libname );
00199
00222 KLibrary* globalLibrary( const char *name );
00223
00224
00225
00226
00227
00228
00229
00230
00231 QString lastErrorMessage() const;
00232
00247 virtual void unloadLibrary( const char *libname );
00248
00255 static KLibLoader* self();
00256
00265 static void cleanUp();
00266
00277 static QString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() );
00278
00279 protected:
00280 KLibLoader( QObject* parent = 0, const char* name = 0 );
00281
00282 private slots:
00283 void slotLibraryDestroyed();
00284 private:
00285 void close_pending( KLibWrapPrivate * );
00286 QAsciiDict<KLibWrapPrivate> m_libs;
00287
00288 static KLibLoader* s_self;
00289
00290 protected:
00291 virtual void virtual_hook( int id, void* data );
00292 private:
00293 KLibLoaderPrivate *d;
00294 };
00295
00331 class KLibFactory : public QObject
00332 {
00333 Q_OBJECT
00334 public:
00340 KLibFactory( QObject* parent = 0, const char* name = 0 );
00341 virtual ~KLibFactory();
00342
00364 QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() );
00365
00366 signals:
00371 void objectCreated( QObject *obj );
00372
00373
00374 protected:
00375
00392 virtual QObject* createObject( QObject* parent = 0, const char* name = 0,
00393 const char* className = "QObject",
00394 const QStringList &args = QStringList() ) = 0;
00395
00396
00397 protected:
00398 virtual void virtual_hook( int id, void* data );
00399 private:
00400 KLibFactoryPrivate *d;
00401 };
00402
00403 #endif
This file is part of the documentation for kdecore Library Version 3.2.0.