MySQL 9.1.0
Source Code Documentation
registry_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2024, 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 @param service_implementation_name Name of the Service Implementation to
105 register.
106 @param ptr Pointer to the Service Implementation structure.
107 @return Status of performed operation
108 @retval false success
109 @retval true failure
110 */
112 (const char *service_implementation_name,
113 my_h_service ptr));
114
115 /**
116 Removes previously registered Service Implementation from registry. If it is
117 the default one for specified Service then any one still registered is made
118 default. If there is no other, the default entry is removed from the
119 Registry too.
120
121 @param service_implementation_name Name of the Service Implementation to
122 unregister.
123 @return Status of performed operation
124 @retval false success
125 @retval true Failure. May happen when Service is still being referenced.
126 */
128 (const char *service_implementation_name));
129
130 /**
131 Sets new default Service Implementation for corresponding Service name.
132
133 @param service_implementation_name Name of the Service Implementation to
134 set as default one.
135 @return Status of performed operation
136 @retval false success
137 @retval true failure
138 */
140 (const char *service_implementation_name));
141
142 /**
143 Creates iterator that iterates through all registered Service
144 Implementations. If successful it leaves read lock on the Registry until
145 iterator is released. The starting point of iteration may be specified
146 to be on one particular Service Implementation. The iterator will move
147 through all Service Implementations and additionally through all default
148 Service Implementation additionally, i.e. the default Service Implementation
149 will be returned twice. If no name is specified for search, iterator will be
150 positioned on the first Service Implementation.
151
152 @param service_name_pattern Name of Service or Service Implementation to
153 start iteration from. May be empty string or NULL pointer, in which case
154 iteration starts from the first Service Implementation.
155 @param [out] out_iterator Pointer to the Service Implementation iterator
156 handle.
157 @return Status of performed operation
158 @retval false success
159 @retval true failure
160 */
162 (const char *service_name_pattern,
163 my_h_service_iterator *out_iterator));
164
165 /**
166 Releases Service implementations iterator. Releases read lock on registry.
167
168 @param iterator Service Implementation iterator handle.
169 */
170 static DEFINE_METHOD(void, iterator_release,
171 (my_h_service_iterator iterator));
172
173 /**
174 Gets name of Service pointed to by iterator. The pointer returned will last
175 at least up to the moment of call to the release() method on the iterator.
176
177 @param iterator Service Implementation iterator handle.
178 @param [out] out_name Pointer to string with name to set result pointer to.
179 @return Status of performed operation
180 @retval false success
181 @retval true Failure, may be caused when called on iterator that went
182 through all values already.
183 */
185 const char **out_name));
186
187 /**
188 Advances specified iterator to next element. Will succeed but return true if
189 it reaches one-past-last element.
190
191 @param iterator Service Implementation iterator handle.
192 @return Status of performed operation and validity of iterator after
193 operation.
194 @retval false success
195 @retval true Failure or called on iterator that was on last element.
196 */
198
199 /**
200 Checks if specified iterator is valid, i.e. have not reached one-past-last
201 element.
202
203 @param iterator Service Implementation iterator handle.
204 @return Validity of iterator
205 @retval false Valid
206 @retval true Invalid or reached one-past-last element.
207 */
209 (my_h_service_iterator iterator));
210
211 /* This includes metadata-related method implementations that are shared
212 by registry and dynamic_loader, so we don't duplicate the code. Following
213 defines set up all required symbols. Unfortunately they are not only the
214 types, but also static members with different name, so usage of templates
215 is not enough to reuse that part of code. */
216#define OBJECT_ITERATOR my_h_service_iterator
217#define METADATA_ITERATOR my_h_service_metadata_iterator
218
220};
221#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:74
static mysql_service_status_t register_service(const char *service_implementation_name, my_h_service ptr) noexcept
Registers a new Service Implementation.
Definition: registry.cc:179
static mysql_rwlock_t LOCK_registry
Definition: registry_imp.h:31
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:313
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:369
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:119
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:217
static minimal_chassis::rwlock_scoped_lock lock_registry_for_write()
Locks whole registry for write.
Definition: registry.cc:102
static void deinit()
De-initializes registry.
Definition: registry.cc:84
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:141
static mysql_service_status_t unregister(const char *service_implementation_name) noexcept
Removes previously registered Service Implementation from registry.
Definition: registry.cc:200
static mysql_service_status_t iterator_next(my_h_service_iterator iterator) noexcept
Advances specified iterator to next element.
Definition: registry.cc:343
static void iterator_release(my_h_service_iterator iterator) noexcept
Releases Service implementations iterator.
Definition: registry.cc:289
static mysql_service_status_t release(my_h_service service) noexcept
Releases the Service Implementation previously acquired.
Definition: registry.cc:159
static void rw_lock_deinit()
De-initializes RW lock.
Definition: registry.cc:92
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:245
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:48
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:51