24#ifndef WEAK_REQUIRES_SERVICE_GUARD
25#define WEAK_REQUIRES_SERVICE_GUARD
150template <
typename Service,
const std::string &
container,
151 const std::string &service_name>
190 const std::function<bool(Service *)>
function;
209 std::string(
"dynamic_loader_services_loaded_notification.") +
210 container + std::string(
"_") + service_name;
222 if (!
hton->service_reference.is_valid())
223 hton->service_reference.acquire(service_name.c_str(),
registry);
225 if (
hton->service_reference.is_valid()) {
226 if (
hton->function(
hton->service_reference))
return true;
227 hton->function_called =
true;
232 if (
hton->function(svc))
return true;
233 hton->function_called =
true;
249 for (
unsigned idx = 0; idx <
count; idx++) {
251 if (svc.length() > service_name.length() &&
252 svc[service_name.length()] ==
'.' && 0 == svc.find(service_name))
292 std::function<
bool(Service *)> func_arg,
293 bool keep_active_reference_arg =
true) {
296 assert(
hton ==
nullptr);
303 x, dynamic_loader_services_loaded_notification)
notify
305 if (reg_reg_arg->register_service(
306 hton->listener_name.c_str(),
309 x, dynamic_loader_services_loaded_notification))))
340 registry_registration_arg,
341 std::function<
bool(Service *)> deinit_func_arg) {
343 if (
hton ==
nullptr)
return false;
346 if (
hton->function_called) {
347 assert(
hton->service_reference.is_valid());
348 if (deinit_func_arg(
hton->service_reference))
return true;
355 if (
hton->service_reference.is_valid()) {
358 hton->service_reference.untie();
361 if (
hton->function_called) {
363 if (svc.
is_valid() && deinit_func_arg(svc))
return true;
367 registry_registration_arg->unregister(
hton->listener_name.c_str()))
389 return hton ? ((Service *)
hton->service_reference) :
nullptr;
406 return hton ?
hton->service_reference :
nullptr;
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:152
static my_h_service get_my_hservice()
Gets the my_h_service reference, if available.
Definition: weak_service_reference.h:405
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:157
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:175
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:290
std::string listener_name
A service_loaded listener implementation name of the following format: dynamic_loader_services_loaded...
Definition: weak_service_reference.h:196
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:247
std::atomic< bool > function_called
A flag if the init callback function has been called.
Definition: weak_service_reference.h:186
my_service< Service > service_reference
Definition: weak_service_reference.h:198
static Service * get_service()
Get the service reference, if available.
Definition: weak_service_reference.h:388
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:220
static bool callback_registered
A flag stating if the callback service implementation listening for new implementations of the servic...
Definition: weak_service_reference.h:169
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:164
weak_service_reference(std::function< bool(Service *)> &func_arg)
A private constructor for the hton.
Definition: weak_service_reference.h:206
const std::function< bool(Service *)> function
The init callback reference.
Definition: weak_service_reference.h:190
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:338
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
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