| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# klibloader.h

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 1999 Torben Weis <weis@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    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> // For backwards compatibility
    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      * Returns an error message that can be useful to debug the problem.
    00223      * Returns QString::null if the last call to @ref #library() was successful.
    00224      * You can call this function more than once. The error message is only
    00225      * reset by a new call to library().
    00226      * @return the last error message, or QString::null if there was no error
    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.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:36 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001