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 00050 class KLibrary : public QObject 00051 { 00052 friend class KLibLoader; 00053 friend class QAsciiDict<KLibrary>; 00054 00055 Q_OBJECT 00056 public: 00060 KLibrary( const QString& libname, const QString& filename, void * handle ); 00061 00066 QString name() const; 00067 00072 QString fileName() const; 00073 00078 KLibFactory* factory(); 00079 00089 void* symbol( const char* name ) const; 00090 00100 bool hasSymbol( const char* name ) const; 00101 00107 void unload() const; 00108 00109 private slots: 00110 void slotObjectCreated( QObject *obj ); 00111 void slotObjectDestroyed(); 00112 void slotTimeout(); 00113 00114 private: 00119 ~KLibrary(); 00120 00121 QString m_libname; 00122 QString m_filename; 00123 KLibFactory* m_factory; 00124 void * m_handle; 00125 QPtrList<QObject> m_objs; 00126 QTimer *m_timer; 00127 KLibraryPrivate *d; 00128 }; 00129 00130 class KLibWrapPrivate; 00131 00142 class KLibLoader : public QObject 00143 { 00144 friend class KLibrary; 00145 00146 Q_OBJECT 00147 public: 00153 ~KLibLoader(); 00154 00175 KLibFactory* factory( const char* libname ); 00176 00197 virtual KLibrary* library( const char* libname ); 00198 00221 KLibrary* globalLibrary( const char *name ); 00222 00223 /* 00224 * Returns an error message that can be useful to debug the problem. 00225 * Returns QString::null if the last call to library() was successful. 00226 * You can call this function more than once. The error message is only 00227 * reset by a new call to library(). 00228 * @return the last error message, or QString::null if there was no error 00229 */ 00230 QString lastErrorMessage() const; 00231 00246 virtual void unloadLibrary( const char *libname ); 00247 00254 static KLibLoader* self(); 00255 00264 static void cleanUp(); 00265 00276 static QString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() ); 00277 00278 protected: 00279 KLibLoader( QObject* parent = 0, const char* name = 0 ); 00280 00281 private slots: 00282 void slotLibraryDestroyed(); 00283 private: 00284 void close_pending( KLibWrapPrivate * ); 00285 QAsciiDict<KLibWrapPrivate> m_libs; 00286 00287 static KLibLoader* s_self; 00288 00289 protected: 00290 virtual void virtual_hook( int id, void* data ); 00291 private: 00292 KLibLoaderPrivate *d; 00293 }; 00294 00330 class KLibFactory : public QObject 00331 { 00332 Q_OBJECT 00333 public: 00339 KLibFactory( QObject* parent = 0, const char* name = 0 ); 00340 virtual ~KLibFactory(); 00341 00363 QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() ); 00364 00365 signals: 00370 void objectCreated( QObject *obj ); 00371 00372 00373 protected: 00374 00391 virtual QObject* createObject( QObject* parent = 0, const char* name = 0, 00392 const char* className = "QObject", 00393 const QStringList &args = QStringList() ) = 0; 00394 00395 00396 protected: 00397 virtual void virtual_hook( int id, void* data ); 00398 private: 00399 KLibFactoryPrivate *d; 00400 }; 00401 00402 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:40:08 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003