MySQL 9.4.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
registry_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2025, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_SERVER_REGISTRY_H
25#define MYSQL_SERVER_REGISTRY_H
26
28#include "rwlock_scoped_lock.h"
29
32
33 public:
34 /**
35 Initializes registry for usage. Initializes RW lock, all other structures
36 should be empty. Shouldn't be called multiple times.
37 */
38 static void init();
39
40 /**
41 De-initializes registry. De-initializes RW lock, all other structures
42 are cleaned up.
43 */
44 static void deinit();
45
46 /** De-initializes RW lock */
47 static void rw_lock_deinit();
48
49 /**
50 Locks whole registry for write. For internal use only.
51
52 @return A lock acquired wrapped into RAII object.
53 */
55
56 /* Service Implementations */
57 /**
58 Finds and acquires a Service by name. A name of the Service or the Service
59 Implementation can be specified. In case of the Service name, the default
60 Service Implementation for Service specified will be returned.
61
62 @param service_name Name of Service or Service Implementation to acquire.
63 @param [out] out_service Pointer to Service handle to set acquired Service.
64 @return Status of performed operation
65 @retval false success
66 @retval true failure
67 */
68 static DEFINE_BOOL_METHOD(acquire, (const char *service_name,
69 my_h_service *out_service));
70
71 /**
72 Finds a Service by name. If there is a Service Implementation with the same
73 Component part of name as the input Service then the found Service is
74 returned.
75
76 @param service_name Name of Service or Service Implementation to acquire.
77 @param service Service handle already acquired Service Implementation.
78 @param [out] out_service Pointer to Service Implementation handle to set
79 acquired Service Implementation.
80 @return Status of performed operation
81 @retval false success
82 @retval true failure
83 */
85 (const char *service_name, my_h_service service,
86 my_h_service *out_service));
87
88 /**
89 Releases the Service Implementation previously acquired. After the call to
90 this method the usage of the Service Implementation handle will lead to
91 unpredicted results.
92
93 @param service Service Implementation handle of already acquired Service.
94 @return Status of performed operation
95 @retval false success
96 @retval true failure
97 */
98 static DEFINE_BOOL_METHOD(release, (my_h_service service));
99
100 /**
101 Registers a new Service Implementation. If it is the first Service
102 Implementation for the specified Service then it is made a default one.
103
104 @note Called by register_service API and the dyloader
105
106 @param service_implementation_name Name of the Service Implementation to
107 register.
108 @param ptr Pointer to the Service Implementation structure.
109 @return Status of performed operation
110 @retval false success
111 @retval true failure
112 */
114 const char *service_implementation_name, my_h_service ptr);
115
116 /**
117 Implementation of the top level register service call.
118 In addition to @ref register_service_sans_notify also calls the loaded
119 notification.
120
121 @param service_implementation_name Name of the Service Implementation to
122 register.
123 @param ptr Pointer to the Service Implementation structure.
124 @return Status of performed operation
125 @retval false success
126 @retval true failure
127 */
129 (const char *service_implementation_name,
130 my_h_service ptr));
131
132 /**
133 Removes previously registered Service Implementation from registry. If it is
134 the default one for specified Service then any one still registered is made
135 default. If there is no other, the default entry is removed from the
136 Registry too.
137
138 @note Called by the unregister_service API and the dyloader
139
140 @param service_implementation_name Name of the Service Implementation to
141 unregister.
142 @return Status of performed operation
143 @retval false success
144 @retval true Failure. May happen when Service is still being referenced.
145 */
146 static bool unregister_sans_notify(const char *service_implementation_name);
147
148 /**
149 Implementation of the top level unregister service call.
150 In addition to @ref unregister_sans_notify also calls the unloaded
151 notification.
152
153 @param service_implementation_name Name of the Service Implementation to
154 unregister.
155 @return Status of performed operation
156 @retval false success
157 @retval true Failure. May happen when Service is still being referenced.
158 */
160 (const char *service_implementation_name));
161
162 /**
163 Sets new default Service Implementation for corresponding Service name.
164
165 @param service_implementation_name Name of the Service Implementation to
166 set as default one.
167 @return Status of performed operation
168 @retval false success
169 @retval true failure
170 */
172 (const char *service_implementation_name));
173
174 /**
175 Creates iterator that iterates through all registered Service
176 Implementations. If successful it leaves read lock on the Registry until
177 iterator is released. The starting point of iteration may be specified
178 to be on one particular Service Implementation. The iterator will move
179 through all Service Implementations and additionally through all default
180 Service Implementation additionally, i.e. the default Service Implementation
181 will be returned twice. If no name is specified for search, iterator will be
182 positioned on the first Service Implementation.
183
184 @param service_name_pattern Name of Service or Service Implementation to
185 start iteration from. May be empty string or NULL pointer, in which case
186 iteration starts from the first Service Implementation.
187 @param [out] out_iterator Pointer to the Service Implementation iterator
188 handle.
189 @return Status of performed operation
190 @retval false success
191 @retval true failure
192 */
194 (const char *service_name_pattern,
195 my_h_service_iterator *out_iterator));
196
197 /**
198 Releases Service implementations iterator. Releases read lock on registry.
199
200 @param iterator Service Implementation iterator handle.
201 */
202 static DEFINE_METHOD(void, iterator_release,
203 (my_h_service_iterator iterator));
204
205 /**
206 Gets name of Service pointed to by iterator. The pointer returned will last
207 at least up to the moment of call to the release() method on the iterator.
208
209 @param iterator Service Implementation iterator handle.
210 @param [out] out_name Pointer to string with name to set result pointer to.
211 @return Status of performed operation
212 @retval false success
213 @retval true Failure, may be caused when called on iterator that went
214 through all values already.
215 */
217 const char **out_name));
218
219 /**
220 Advances specified iterator to next element. Will succeed but return true if
221 it reaches one-past-last element.
222
223 @param iterator Service Implementation iterator handle.
224 @return Status of performed operation and validity of iterator after
225 operation.
226 @retval false success
227 @retval true Failure or called on iterator that was on last element.
228 */
230
231 /**
232 Checks if specified iterator is valid, i.e. have not reached one-past-last
233 element.
234
235 @param iterator Service Implementation iterator handle.
236 @return Validity of iterator
237 @retval false Valid
238 @retval true Invalid or reached one-past-last element.
239 */
241 (my_h_service_iterator iterator));
242
243 /* This includes metadata-related method implementations that are shared
244 by registry and dynamic_loader, so we don't duplicate the code. Following
245 defines set up all required symbols. Unfortunately they are not only the
246 types, but also static members with different name, so usage of templates
247 is not enough to reuse that part of code. */
248#define OBJECT_ITERATOR my_h_service_iterator
249#define METADATA_ITERATOR my_h_service_metadata_iterator
250
252};
253#endif /* MYSQL_SERVER_REGISTRY_H */
Locks RW-lock and releases lock on scope exit.
Definition: rwlock_scoped_lock.h:33
Definition: registry_imp.h:30
static void init()
Initializes registry for usage.
Definition: registry.cc:99
static bool register_service_sans_notify(const char *service_implementation_name, my_h_service ptr)
Registers a new Service Implementation.
Definition: registry.cc:190
static mysql_service_status_t register_service(const char *service_implementation_name, my_h_service ptr) noexcept
Implementation of the top level register service call.
Definition: registry.cc:201
static mysql_rwlock_t LOCK_registry
Definition: registry_imp.h:31
static bool unregister_sans_notify(const char *service_implementation_name)
Removes previously registered Service Implementation from registry.
Definition: registry.cc:220
static mysql_service_status_t iterator_get(my_h_service_iterator iterator, const char **out_name) noexcept
Gets name of Service pointed to by iterator.
Definition: registry.cc:352
static mysql_service_status_t iterator_is_valid(my_h_service_iterator iterator) noexcept
Checks if specified iterator is valid, i.e.
Definition: registry.cc:408
static mysql_service_status_t acquire(const char *service_name, my_h_service *out_service) noexcept
Finds and acquires a Service by name.
Definition: registry.cc:143
static mysql_service_status_t set_default(const char *service_implementation_name) noexcept
Sets new default Service Implementation for corresponding Service name.
Definition: registry.cc:257
static minimal_chassis::rwlock_scoped_lock lock_registry_for_write()
Locks whole registry for write.
Definition: registry.cc:127
static void deinit()
De-initializes registry.
Definition: registry.cc:109
static mysql_service_status_t acquire_related(const char *service_name, my_h_service service, my_h_service *out_service) noexcept
Finds a Service by name.
Definition: registry.cc:165
static mysql_service_status_t unregister(const char *service_implementation_name) noexcept
Implementation of the top level unregister service call.
Definition: registry.cc:229
static mysql_service_status_t iterator_next(my_h_service_iterator iterator) noexcept
Advances specified iterator to next element.
Definition: registry.cc:382
static void iterator_release(my_h_service_iterator iterator) noexcept
Releases Service implementations iterator.
Definition: registry.cc:329
static mysql_service_status_t release(my_h_service service) noexcept
Releases the Service Implementation previously acquired.
Definition: registry.cc:183
static void rw_lock_deinit()
De-initializes RW lock.
Definition: registry.cc:117
static mysql_service_status_t iterator_create(const char *service_name_pattern, my_h_service_iterator *out_iterator) noexcept
Creates iterator that iterates through all registered Service Implementations.
Definition: registry.cc:285
Definition: registry_no_lock_imp.h:39
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:33
#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 DEFINE_METHOD(retval, name, args)
A macro to ensure method implementation has required properties, that is it does not throw exceptions...
Definition: service_implementation.h:79
Definition: registry.cc:73
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:51