Library: OSP
Package: ExtensionPointService
Header: Poco/OSP/ExtensionPointService.h
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".
Direct Base Classes: Service
All Base Classes: Service, Poco::RefCountedObject
Member Functions: findExtensionPoint, handleExtension, handleExtensions, isA, onBundleStarted, onBundleStopped, registerExtensionPoint, removeExtension, type, unregisterExtensionPoint
Inherited Functions: duplicate, isA, referenceCount, release, type
typedef void (ExtensionPointService::* GenericHandler)(Bundle::ConstPtr pBundle, const std::string & id, Poco::XML::Element * pExtensionElement);
The direction in which to traverse the extension points
ExtensionPointService(
BundleEvents & events
);
Creates the ExtensionPointService.
Destroys the ExtensionPointService.
bool isA(
const std::type_info & otherType
) const;
See also: Poco::OSP::Service::isA()
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.
const std::type_info & type() const;
See also: Poco::OSP::Service::type()
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.
ExtensionPoint::Ptr findExtensionPoint(
const std::string & id
);
Returns the extension point with the given ID.
void handleExtension(
Bundle::ConstPtr pBundle,
const std::string & id,
Poco::XML::Element * pExtensionElement
);
Handles a single "extension" element.
void handleExtensions(
Bundle::ConstPtr pBundle,
GenericHandler handler,
Direction dir = DIR_FORWARD
);
Handles the "extensions.xml" file, if it exists.
void handleExtensions(
Bundle::ConstPtr pBundle,
std::istream & istr,
GenericHandler handler,
Direction dir = DIR_FORWARD
);
Handles the "extensions.xml" file.
void onBundleStarted(
const void * pSender,
BundleEvent & event
);
Handles an EV_BUNDLE_STARTED event.
void onBundleStopped(
const void * pSender,
BundleEvent & event
);
Handles an EV_BUNDLE_STOPPED event.
void removeExtension(
Bundle::ConstPtr pBundle,
const std::string & id,
Poco::XML::Element * pExtensionElement
);
Handles a single "extension" element for extension removal.
static const std::string EXTENSIONS_ELEM;
static const std::string EXTENSIONS_XML;
static const std::string EXTENSION_ELEM;
static const std::string POINT_ATTR;
static const std::string SERVICE_NAME;