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: 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 * Returns an error message that can be useful to debug the problem. 00226 * Returns QString::null if the last call to library() was successful. 00227 * You can call this function more than once. The error message is only 00228 * reset by a new call to library(). 00229 * @return the last error message, or QString::null if there was no error 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
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:21:42 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003