MySQL 9.1.0
Source Code Documentation
|
A utility class to implement a delayed service reference. More...
#include <weak_service_reference.h>
Static Public Member Functions | |
static bool | init (const mysql_service_registry_t *reg_arg, const mysql_service_registry_registration_t *reg_reg_arg, std::function< bool(Service *)> func_arg, bool keep_active_reference_arg=true) |
Initialize the weak reference class. More... | |
static bool | deinit (const mysql_service_registry_t *registry_arg, const mysql_service_registry_registration_t *registry_registration_arg, std::function< bool(Service *)> deinit_func_arg) |
Deinitializes a weak reference caller class. More... | |
Private Member Functions | |
weak_service_reference (std::function< bool(Service *)> &func_arg) | |
A private constructor for the hton. More... | |
Static Private Member Functions | |
static bool | call_function () |
Helper function to take a reference to the service needed and call the init callback function. More... | |
static mysql_service_status_t | notify (const char **services, unsigned int count) noexcept |
An implementation for the dynamic_loader_services_loaded_notification::notify service method. More... | |
Private Attributes | |
std::atomic< bool > | function_called {false} |
A flag if the init callback function has been called. More... | |
const std::function< bool(Service *)> | function |
The init callback reference. More... | |
std::string | listener_name |
A service_loaded listener implementation name of the following format: dynamic_loader_services_loaded_notification. More... | |
my_service< Service > | service_reference |
Static Private Attributes | |
static weak_service_reference< Service, container, service_name > * | hton |
A single instance of the class to hold (and initialize) some data at init time. More... | |
static const mysql_service_registry_t * | registry {nullptr} |
We need to store a reference to the registry since the init callback needs it. More... | |
static bool | callback_registered {false} |
A flag stating if the callback service implementation listening for new implementations of the service has been registered. More... | |
static bool | keep_active_reference {true} |
true when the weak reference class is to keep the reference acquired for reuse until deinit is called. More... | |
A utility class to implement a delayed service reference.
This class allows a component to have a "weak" reference to a component service.
Normal usage pattern is that the weak_service_reference::init() is called during component initialization.
And weak_service_reference::deinit() is called during the component deinitialization.
One can expect that the function argument is called either at init() time or asyncronously, possibly from anoher thread, when an implementation of a service is registered.
Typical usage:
Service | This is the type of the service to be called. E.g. SERVICE_TYPE(foo) |
container | The name of the "container". Usually a component name. It has to be a rvalue ref since you would need a distinct set of the static members of the template class for every service/component combo. |
service_name | The name of the service to try to call. It has to be a rvalue ref since you would need a distinct set of the static members of the template class for every service/component combo. |
|
inlineprivate |
A private constructor for the hton.
func_arg | The function to call when there's an implementation. active reference until deinit. |
|
inlinestaticprivate |
Helper function to take a reference to the service needed and call the init callback function.
true | failure |
false | success |
|
inlinestatic |
Deinitializes a weak reference caller class.
If the init callback was called it will try to acquire a reference to the service and call the deinit callback if the reference is acquired.
Then it will deregister the dynamic_loader_services_loaded_notification implementation, if it's been registered by init().
And it will then proceed to delete the state in hton and reset the class.
registry_arg | A reference to the registry service implementation |
registry_registration_arg | A reference to the registry_registration service implementation |
deinit_func_arg | A (deinit) function to call if an implementation of the service required is definied. One typically reverses the action taken by the registration callback here, e.g. diposes of state, deregisters features etc. |
true | failure |
false | success |
|
inlinestatic |
Initialize the weak reference class.
reg_arg | A reference to the registry service implementation |
reg_reg_arg | A reference to the registry_registration service implementation |
func_arg | A function to be called when an implementation of the service is available. Typically used to initialize some state, e.g. allocate instance handles or register some features in registries. |
keep_active_reference_arg | True if weak_reference is to keep an active reference until deinit. |
This is typically called by the component initialization. If there's already an implementation of the service required a reference to it is obtained and is passed to the function callback from the argument.
If no implementations are available a listener for new implementation registration (an implementation of the dynamic_loader_services_loaded_notifications service) is registered into the registry and the function returns.
true | Failure |
false | Success |
|
inlinestaticprivatenoexcept |
An implementation for the dynamic_loader_services_loaded_notification::notify service method.
This is called by the dynamic loader when a new service implementation is registered.
|
inlinestaticprivate |
A flag stating if the callback service implementation listening for new implementations of the service has been registered.
|
private |
The init callback reference.
|
private |
A flag if the init callback function has been called.
This is to prevent multiple calls to the init callback. Ideally we'd unregister the callback altogether, but the callback is called while a reference to it is held, so it can't unregister itself due to an active reference. Hence we raise the flag to prevent further action and deregister at deinit()
|
inlinestaticprivate |
A single instance of the class to hold (and initialize) some data at init time.
|
inlinestaticprivate |
true when the weak reference class is to keep the reference acquired for reuse until deinit is called.
|
private |
A service_loaded listener implementation name of the following format: dynamic_loader_services_loaded_notification.
<conainer_name>_<service_name>
|
inlinestaticprivate |
We need to store a reference to the registry since the init callback needs it.
|
private |