BundleActivator¶
-
struct BundleActivator¶
Customizes the starting and stopping of a CppMicroServices bundle.
BundleActivatoris an interface that can be implemented by CppMicroServices bundles. The CppMicroServices library can create instances of a bundle’sBundleActivatoras required. If an instance’sBundleActivator::Startmethod executes successfully, it is guaranteed that the same instance’sBundleActivator::Stopmethod will be called when the bundle is to be stopped. The CppMicroServices library does not concurrently call aBundleActivatorobject.BundleActivatoris an abstract class interface whose implementations must be exported via a special macro. Implementations are usually declared and defined directly in .cpp files.class MyActivator : public BundleActivator { public: void Start(BundleContext /*context*/) { /* register stuff */ } void Stop(BundleContext /*context*/) { /* cleanup */ } }; CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(MyActivator)
The class implementing the
BundleActivatorinterface must have a public default constructor so that aBundleActivatorobject can be created by the CppMicroServices library.Note
A bundle activator needs to be exported by using the
CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATORmacro. The bundle manifest.json resource also needs to contain a"bundle.activator" : true
element.
Public Functions
-
virtual ~BundleActivator() = default¶
-
virtual void Start(BundleContext context) = 0¶
Called when this bundle is started.
This method can be used to register services or to allocate any resources that this bundle may need globally (during the whole bundle lifetime).
This method must complete and return to its caller in a timely manner.
- Parameters:
context – The execution context of the bundle being started.
- Throws:
std::exception – If this method throws an exception, this bundle is marked as stopped and the framework will remove this bundle’s listeners, unregister all services registered by this bundle, and release all services used by this bundle.
-
virtual void Stop(BundleContext context) = 0¶
Called when this bundle is stopped.
In general, this method should undo the work that the
BundleActivator::Startmethod started. There should be no active threads that were started by this bundle when this method returns.This method must complete and return to its caller in a timely manner.
- Parameters:
context – The execution context of the bundle being stopped.
- Throws:
std::exception – If this method throws an exception, the bundle is still marked as stopped, and the framework will remove the bundle’s listeners, unregister all services registered by the bundle, and release all services used by the bundle.
-
virtual ~BundleActivator() = default¶