kdecore Library API Documentation

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     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      * Returns an error message that can be useful to debug the problem.
00221      * Returns QString::null if the last call to @ref #library() was successful.
00222      * You can call this function more than once. The error message is only
00223      * reset by a new call to library().
00224      * @return the last error message, or QString::null if there was no error
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
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:20:41 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001