24#ifndef WEAK_REQUIRES_SERVICE_GUARD
25#define WEAK_REQUIRES_SERVICE_GUARD
164template <
typename Service,
const std::string &
container,
165 const std::string &service_name>
204 const std::function<bool(Service *)>
function;
223 std::string(
"dynamic_loader_services_loaded_notification.") +
224 container + std::string(
"_") + service_name;
236 if (!
hton->service_reference.is_valid())
237 hton->service_reference.acquire(service_name.c_str(),
registry);
239 if (
hton->service_reference.is_valid()) {
240 if (
hton->function(
hton->service_reference))
return true;
241 hton->function_called =
true;
246 if (
hton->function(svc))
return true;
247 hton->function_called =
true;
263 for (
unsigned idx = 0; idx <
count; idx++) {
265 if (svc.length() > service_name.length() &&
266 svc[service_name.length()] ==
'.' && 0 == svc.find(service_name))
306 std::function<
bool(Service *)> func_arg,
307 bool keep_active_reference_arg =
true) {
310 assert(
hton ==
nullptr);
317 x, dynamic_loader_services_loaded_notification)
notify
319 if (reg_reg_arg->register_service(
320 hton->listener_name.c_str(),
323 x, dynamic_loader_services_loaded_notification))))
354 registry_registration_arg,
355 std::function<
bool(Service *)> deinit_func_arg) {
357 if (
hton ==
nullptr)
return false;
360 if (
hton->function_called) {
361 assert(
hton->service_reference.is_valid());
362 if (deinit_func_arg(
hton->service_reference))
return true;
369 if (
hton->service_reference.is_valid()) {
372 hton->service_reference.untie();
375 if (
hton->function_called) {
377 if (svc.
is_valid() && deinit_func_arg(svc))
return true;
381 registry_registration_arg->unregister(
hton->listener_name.c_str()))
Wraps my_h_service struct conforming ABI into RAII C++ object with ability to cast to desired service...
Definition: my_service.h:35
bool is_valid() const
Definition: my_service.h:127
void release()
Releases the reference, if any, and cleans the instance up.
Definition: my_service.h:104
A utility class to implement a delayed service reference.
Definition: weak_service_reference.h:166
static weak_service_reference< Service, container, service_name > * hton
A single instance of the class to hold (and initialize) some data at init time.
Definition: weak_service_reference.h:171
static bool keep_active_reference
true when the weak reference class is to keep the reference acquired for reuse until deinit is called...
Definition: weak_service_reference.h:189
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.
Definition: weak_service_reference.h:304
std::string listener_name
A service_loaded listener implementation name of the following format: dynamic_loader_services_loaded...
Definition: weak_service_reference.h:210
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.
Definition: weak_service_reference.h:261
std::atomic< bool > function_called
A flag if the init callback function has been called.
Definition: weak_service_reference.h:200
my_service< Service > service_reference
Definition: weak_service_reference.h:212
static bool call_function()
Helper function to take a reference to the service needed and call the init callback function.
Definition: weak_service_reference.h:234
static bool callback_registered
A flag stating if the callback service implementation listening for new implementations of the servic...
Definition: weak_service_reference.h:183
static const mysql_service_registry_t * registry
We need to store a reference to the registry since the init callback needs it.
Definition: weak_service_reference.h:178
weak_service_reference(std::function< bool(Service *)> &func_arg)
A private constructor for the hton.
Definition: weak_service_reference.h:220
const std::function< bool(Service *)> function
The init callback reference.
Definition: weak_service_reference.h:204
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.
Definition: weak_service_reference.h:352
Connection event tracking.
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:33
static int count
Definition: myisam_ftdump.cc:45
const mysql_service_registry_registration_t * registry_registration
Definition: atomics_array.h:39
Definition: services.cc:40
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
Specifies macros to define Service Implementations.
#define BEGIN_SERVICE_IMPLEMENTATION(component, service)
Declares a Service Implementation.
Definition: service_implementation.h:62
#define END_SERVICE_IMPLEMENTATION()
A macro to end the last declaration of a Service Implementation.
Definition: service_implementation.h:67
#define DEFINE_BOOL_METHOD(name, args)
A short macro to define method that returns bool, which is the most common case.
Definition: service_implementation.h:88
#define SERVICE_IMPLEMENTATION(component, service)
Reference to the name of the service implementation variable.
Definition: service_implementation.h:51