Poco::OSP

class ExtensionPointService

Library: OSP
Package: ExtensionPointService
Header: Poco/OSP/ExtensionPointService.h

Description

The ExtensionPointService allows a bundle to define extension points (or "hooks") where other bundles can "hook in" functionality, thus extending the bundle.

The service listens for EV_BUNDLE_STARTED events. For every started bundle, the service tries to retrieve the bundle's "extensions.xml" file. If the file exists, the file is parsed using a DOM parser.

The ExtensionPointService then iterates over all "extension" elements in that document. Every "extension" element must specify an attribute named "point" that specifies the ExtensionPoint object to invoke for this element. The service then invokes the ExtensionPoint::handleExtension() member function with the bundle and the "extension" element as arguments.

The "extensions.xml" file basically looks as follows:

<extensions>
    <extension point="<id>">
        <!-- extension point specific content -->
    </extension>
    <!-- more extension elements -->
</extensions>

The service name of the ExtensionPointService is "osp.core.xp".

Inheritance

Direct Base Classes: Service

All Base Classes: Service, Poco::RefCountedObject

Member Summary

Member Functions: findExtensionPoint, handleExtension, handleExtensions, isA, onBundleStarted, onBundleStopped, registerExtensionPoint, removeExtension, type, unregisterExtensionPoint

Inherited Functions: duplicate, isA, referenceCount, release, type

Types

void protected

typedef void (ExtensionPointService::* GenericHandler)(Bundle::ConstPtr pBundle, const std::string & id, Poco::XML::Element * pExtensionElement);

Types Aliases

ConstPtr

using ConstPtr = const Ptr;

Ptr

using Ptr = Poco::AutoPtr < ExtensionPointService >;

Enumerations

Direction protected

The direction in which to traverse the extension points

DIR_FORWARD

DIR_REVERSE

Constructors

ExtensionPointService

ExtensionPointService(
    BundleEvents & events
);

Creates the ExtensionPointService.

Destructor

~ExtensionPointService protected virtual

~ExtensionPointService();

Destroys the ExtensionPointService.

Member Functions

isA virtual

bool isA(
    const std::type_info & otherType
) const;

registerExtensionPoint

void registerExtensionPoint(
    Bundle::ConstPtr pBundle,
    const std::string & id,
    ExtensionPoint::Ptr pExtensionPoint
);

Registers the given extension point under the given ID. If the bundle registering the extension point is stopped, the extension point will be automatically unregistered.

Throws a Poco::ExistsException if an extension point with the given ID has already been registered.

type virtual

const std::type_info & type() const;

unregisterExtensionPoint

void unregisterExtensionPoint(
    const std::string & id
);

Unregisters the extension point with the given ID.

Throws a Poco::NotFoundException if the extension point with the given ID does not exist.

findExtensionPoint protected

ExtensionPoint::Ptr findExtensionPoint(
    const std::string & id
);

Returns the extension point with the given ID.

handleExtension protected

void handleExtension(
    Bundle::ConstPtr pBundle,
    const std::string & id,
    Poco::XML::Element * pExtensionElement
);

Handles a single "extension" element.

handleExtensions protected

void handleExtensions(
    Bundle::ConstPtr pBundle,
    GenericHandler handler,
    Direction dir = DIR_FORWARD
);

Handles the "extensions.xml" file, if it exists.

handleExtensions protected

void handleExtensions(
    Bundle::ConstPtr pBundle,
    std::istream & istr,
    GenericHandler handler,
    Direction dir = DIR_FORWARD
);

Handles the "extensions.xml" file.

onBundleStarted protected

void onBundleStarted(
    const void * pSender,
    BundleEvent & event
);

Handles an EV_BUNDLE_STARTED event.

onBundleStopped protected

void onBundleStopped(
    const void * pSender,
    BundleEvent & event
);

Handles an EV_BUNDLE_STOPPED event.

removeExtension protected

void removeExtension(
    Bundle::ConstPtr pBundle,
    const std::string & id,
    Poco::XML::Element * pExtensionElement
);

Handles a single "extension" element for extension removal.

Variables

EXTENSIONS_ELEM static

static const std::string EXTENSIONS_ELEM;

EXTENSIONS_XML static

static const std::string EXTENSIONS_XML;

EXTENSION_ELEM static

static const std::string EXTENSION_ELEM;

POINT_ATTR static

static const std::string POINT_ATTR;

SERVICE_NAME static

static const std::string SERVICE_NAME;