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., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef KLIBLOADER_H 00019 #define KLIBLOADER_H 00020 00021 #include <tqobject.h> 00022 #include <tqstring.h> 00023 #include <tqstringlist.h> 00024 #include <tqasciidict.h> 00025 #include <tqptrlist.h> 00026 #include <kglobal.h> 00027 00028 #include <stdlib.h> // For backwards compatibility 00029 00030 class KInstance; 00031 class TQTimer; 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" { KDE_EXPORT void *init_##libname() { return new factory; } } 00040 00050 class KDECORE_EXPORT KLibrary : public TQObject 00051 { 00052 friend class KLibLoader; 00053 friend class TQAsciiDict<KLibrary>; 00054 00055 Q_OBJECT 00056 public: 00060 KLibrary( const TQString& libname, const TQString& filename, void * handle ); 00061 00066 TQString name() const; 00067 00072 TQString 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( TQObject *obj ); 00111 void slotObjectDestroyed(); 00112 void slotTimeout(); 00113 00114 private: 00119 ~KLibrary(); 00120 00121 TQString m_libname; 00122 TQString m_filename; 00123 KLibFactory* m_factory; 00124 void * m_handle; 00125 TQPtrList<TQObject> m_objs; 00126 TQTimer *m_timer; 00127 KLibraryPrivate *d; 00128 }; 00129 00130 class KLibWrapPrivate; 00131 00142 class KDECORE_EXPORT KLibLoader : public TQObject 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 00230 TQString lastErrorMessage() const; 00231 00246 virtual void unloadLibrary( const char *libname ); 00247 00254 static KLibLoader* self(); 00255 00264 static void cleanUp(); 00265 00276 static TQString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() ); 00277 00278 protected: 00279 KLibLoader( TQObject* parent = 0, const char* name = 0 ); 00280 00281 private slots: 00282 void slotLibraryDestroyed(); 00283 private: 00284 void close_pending( KLibWrapPrivate * ); 00285 TQAsciiDict<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 00333 class KDECORE_EXPORT KLibFactory : public TQObject 00334 { 00335 Q_OBJECT 00336 public: 00342 KLibFactory( TQObject* parent = 0, const char* name = 0 ); 00343 virtual ~KLibFactory(); 00344 00366 TQObject* create( TQObject* parent = 0, const char* name = 0, const char* classname = TQOBJECT_OBJECT_NAME_STRING, const TQStringList &args = TQStringList() ); 00367 00368 signals: 00373 void objectCreated( TQObject *obj ); 00374 00375 00376 protected: 00377 00394 virtual TQObject* createObject( TQObject* parent = 0, const char* name = 0, 00395 const char* className = TQOBJECT_OBJECT_NAME_STRING, 00396 const TQStringList &args = TQStringList() ) = 0; 00397 00398 00399 protected: 00400 virtual void virtual_hook( int id, void* data ); 00401 private: 00402 KLibFactoryPrivate *d; 00403 }; 00404 00405 #endif