Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QComponentFactory Class Reference

The QComponentFactory class provides static functions to create and register components. More...

#include </home/clem/local/src/opie/qmake/include/private/qcomponentfactory_p.h>

List of all members.

Static Public Member Functions

static QRESULT createInstance (const QString &cid, const QUuid &iid, QUnknownInterface **instance, QUnknownInterface *outer=0)
static QRESULT registerServer (const QString &filename)
static QRESULT unregisterServer (const QString &filename)
static bool registerComponent (const QUuid &cid, const QString &filename, const QString &name=QString::null, int version=0, const QString &description=QString::null)
static bool unregisterComponent (const QUuid &cid)


Detailed Description

The QComponentFactory class provides static functions to create and register components.

For internal use only.

The static convenience functions can be used both by applications to instantiate components, and by component servers to register components.

The createInstance() function provides a pointer to an interface implemented in a specific component if the component requested has been installed properly and implements the interface.

Use registerServer() to load a component server and register its components, and unregisterServer() to unregister the components. The component exported by the component server has to implement the QComponentRegistrationInterface.

The static functions registerComponent() and unregisterComponent() register and unregister a single component in the system component registry, and should be used when implementing the registerCompontents() and unregisterCompontents() functions in the QComponentRegistrationInterface.

A component is registered using a UUID, but can additionally be registered with a name, version and description. A component registered with a name and a version can be instantiated by client applications using the name and specific version number, or the highest available version number for that component by just using the name. A component that is registered calling

  QComponentFactory::registerComponent( QUuid(...), filename, "MyProgram.Component", 1 );

can be instantiated calling either:

  QComponentFactory::createInstance( QUuid(...), IID_XYZ, (QUnknownInterface**)&iface );
or
  QComponentFactory::createInstance( "MyProgram.Component", IID_XYZ, (QUnknownInterface**)&iface );
or
  QComponentFactory::createInstance( "MyProgram.Component.1", IID_XYZ, (QUnknownInterface**)&iface );

The first and the last way will always instantiate exactly the component registered above, while the second call might also return a later version of the same component. This allows smoother upgrading of components, and is easier to use in application source code, but should only be used when new versions of the component are guaranteed to work with the application.

The component name can be anything, but should be unique on the system the component is being installed on. A common naming convention for components is application.component.

See also:
QComponentRegistrationInterface QComponentFactoryInterface

Definition at line 59 of file qcomponentfactory_p.h.


Member Function Documentation

QRESULT QComponentFactory::createInstance const QString cid,
const QUuid iid,
QUnknownInterface **  iface,
QUnknownInterface outer = 0
[static]
 

Searches for the component identifier cid in the system component registry, loads the corresponding component server and queries for the interface iid. iface is set to the resulting interface pointer. cid can either be the UUID or the name of the component.

The parameter outer is a pointer to the outer interface used for containment and aggregation and is propagated to the createInstance() implementation of the QComponentFactoryInterface in the component server if provided.

The function returns QS_OK if the interface was successfully instantiated, QE_NOINTERFACE if the component does not provide an interface iid, or QE_NOCOMPONENT if there was an error loading the component.

Example:

  QInterfacePtr<MyInterface> iface;
  if ( QComponentFactory::createInstance( IID_MyInterface, CID_MyComponent, (QUnknownInterface**)&iface ) == QS_OK )
      iface->doSomething();
      ...
  }

Definition at line 146 of file qcomponentfactory.cpp.

References FALSE, IID_QComponentFactory, IID_QLibrary, QSettings::insertSearchPath(), QString::isEmpty(), QUuid::isNull(), liblist(), QString::null, qApp, QE_NOCOMPONENT, QRESULT, QS_OK, QComLibrary::queryInterface(), QSettings::readEntry(), QUnknownInterface::release(), QUuid::toString(), TRUE, and QSettings::Windows.

bool QComponentFactory::registerComponent const QUuid cid,
const QString filepath,
const QString name = QString::null,
int  version = 0,
const QString description = QString::null
[static]
 

Registers the component with id cid in the system component registry and returns TRUE if the component was registerd successfully, otherwise returns FALSE. The component is provided by the component server at filepath and registered with an optional name, version and description.

This function does nothing and returns FALSE if a component with an identical cid does already exist on the system.

A component that has been registered with a name can be created using both the cid and the name value using createInstance().

Call this function for each component in an implementation of registerComponents() .

See also:
unregisterComponent(), registerServer(), createInstance()

Definition at line 252 of file qcomponentfactory.cpp.

References FALSE, QSettings::insertSearchPath(), QString::null, QString::number(), QSettings::readEntry(), QSettings::Windows, and QSettings::writeEntry().

QRESULT QComponentFactory::registerServer const QString filename  )  [static]
 

Loads the shared library filename and queries for a QComponentRegistrationInterface. If the library implements this interface, the registerComponents() function is called.

Returns TRUE if the interface is found and successfully called, otherwise returns FALSE.

Definition at line 199 of file qcomponentfactory.cpp.

References QDir::absPath(), IID_QComponentRegistration, QRESULT, QS_FALSE, QS_OK, QComLibrary::queryInterface(), and QUnknownInterface::release().

bool QComponentFactory::unregisterComponent const QUuid cid  )  [static]
 

Unregisters the component with id cid from the system component registry and returns TRUE if the component was unregistered successfully, otherwise returns FALSE.

Call this function for each component in an implementation of unregisterComponents() .

See also:
registerComponent(), unregisterServer()

Definition at line 299 of file qcomponentfactory.cpp.

References FALSE, QString::find(), QSettings::insertSearchPath(), QString::isEmpty(), QString::length(), name, QString::null, QString::number(), QSettings::readEntry(), QSettings::removeEntry(), QString::right(), QString::toInt(), version, QSettings::Windows, and QSettings::writeEntry().

QRESULT QComponentFactory::unregisterServer const QString filename  )  [static]
 

Loads the shared library filename and queries for a QComponentRegistrationInterface. If the library implements this interface, the unregisterComponents() function is called.

Returns TRUE if the interface is found and successfully unregistered, otherwise returns FALSE.

Definition at line 222 of file qcomponentfactory.cpp.

References IID_QComponentRegistration, QRESULT, QS_FALSE, QS_OK, QComLibrary::queryInterface(), and QUnknownInterface::release().


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 17:46:18 2005 for OPIE by  doxygen 1.4.2