klibloader.h
/* This file is part of the KDE libraries
Copyright (C) 1999 Torben Weis <weis@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KLIBLOADER_H
#define KLIBLOADER_H
#include <qobject.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qasciidict.h>
#include <qptrlist.h>
#include <kglobal.h>
#include <stdlib.h> // For backwards compatibility
class KInstance;
class QTimer;
class KLibrary;
class KLibFactory;
class KLibFactoryPrivate;
class KLibLoaderPrivate;
class KLibraryPrivate;
# define K_EXPORT_COMPONENT_FACTORY( libname, factory ) \
extern "C" { KDE_EXPORT void *init_##libname() { return new factory; } }
class KDECORE_EXPORT KLibrary : public QObject
{
friend class KLibLoader;
friend class QAsciiDict<KLibrary>;
Q_OBJECT
public:
KLibrary( const QString& libname, const QString& filename, void * handle );
QString name() const;
QString fileName() const;
KLibFactory* factory();
void* symbol( const char* name ) const;
bool hasSymbol( const char* name ) const;
void unload() const;
private slots:
void slotObjectCreated( QObject *obj );
void slotObjectDestroyed();
void slotTimeout();
private:
~KLibrary();
QString m_libname;
QString m_filename;
KLibFactory* m_factory;
void * m_handle;
QPtrList<QObject> m_objs;
QTimer *m_timer;
KLibraryPrivate *d;
};
class KLibWrapPrivate;
class KDECORE_EXPORT KLibLoader : public QObject
{
friend class KLibrary;
Q_OBJECT
public:
~KLibLoader();
KLibFactory* factory( const char* libname );
virtual KLibrary* library( const char* libname );
KLibrary* globalLibrary( const char *name );
QString lastErrorMessage() const;
virtual void unloadLibrary( const char *libname );
static KLibLoader* self();
static void cleanUp();
static QString findLibrary( const char * name, const KInstance * instance = KGlobal::instance() );
protected:
KLibLoader( QObject* parent = 0, const char* name = 0 );
private slots:
void slotLibraryDestroyed();
private:
void close_pending( KLibWrapPrivate * );
QAsciiDict<KLibWrapPrivate> m_libs;
static KLibLoader* s_self;
protected:
virtual void virtual_hook( int id, void* data );
private:
KLibLoaderPrivate *d;
};
class KDECORE_EXPORT KLibFactory : public QObject
{
Q_OBJECT
public:
KLibFactory( QObject* parent = 0, const char* name = 0 );
virtual ~KLibFactory();
QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() );
signals:
void objectCreated( QObject *obj );
protected:
virtual QObject* createObject( QObject* parent = 0, const char* name = 0,
const char* className = "QObject",
const QStringList &args = QStringList() ) = 0;
protected:
virtual void virtual_hook( int id, void* data );
private:
KLibFactoryPrivate *d;
};
#endif
KLibFactory
If you develop a library that is to be loaded dynamically at runtime, then you should return a pointe...
Definition: klibloader.h:333
KLibrary::name
QString name() const
Returns the name of the library.
Definition: klibloader.cpp:136
KLibrary
Represents a dynamically loaded library.
Definition: klibloader.h:50
KInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:43
KLibrary::factory
KLibFactory * factory()
Returns the factory of the library.
Definition: klibloader.cpp:146
KGlobal::instance
static KInstance * instance()
Returns the global instance.
Definition: kglobal.cpp:82
KLibLoader
The KLibLoader allows you to load libraries dynamically at runtime.
Definition: klibloader.h:142

KDE Home | KDE Accessibility Home | Description of Access Keys