MySQL 8.3.0
Source Code Documentation
registry_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2023, 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 also distributed 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 included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MYSQL_SERVER_REGISTRY_H
24#define MYSQL_SERVER_REGISTRY_H
25
27#include "rwlock_scoped_lock.h"
28
31
32 public:
33 /**
34 Initializes registry for usage. Initializes RW lock, all other structures
35 should be empty. Shouldn't be called multiple times.
36 */
37 static void init();
38
39 /**
40 De-initializes registry. De-initializes RW lock, all other structures
41 are cleaned up.
42 */
43 static void deinit();
44
45 /** De-initializes RW lock */
46 static void rw_lock_deinit();
47
48 /**
49 Locks whole registry for write. For internal use only.
50
51 @return A lock acquired wrapped into RAII object.
52 */
54
55 /* Service Implementations */
56 /**
57 Finds and acquires a Service by name. A name of the Service or the Service
58 Implementation can be specified. In case of the Service name, the default
59 Service Implementation for Service specified will be returned.
60
61 @param service_name Name of Service or Service Implementation to acquire.
62 @param [out] out_service Pointer to Service handle to set acquired Service.
63 @return Status of performed operation
64 @retval false success
65 @retval true failure
66 */
67 static DEFINE_BOOL_METHOD(acquire, (const char *service_name,
68 my_h_service *out_service));
69
70 /**
71 Finds a Service by name. If there is a Service Implementation with the same
72 Component part of name as the input Service then the found Service is
73 returned.
74
75 @param service_name Name of Service or Service Implementation to acquire.
76 @param service Service handle already acquired Service Implementation.
77 @param [out] out_service Pointer to Service Implementation handle to set
78 acquired Service Implementation.
79 @return Status of performed operation
80 @retval false success
81 @retval true failure
82 */
84 (const char *service_name, my_h_service service,
85 my_h_service *out_service));
86
87 /**
88 Releases the Service Implementation previously acquired. After the call to
89 this method the usage of the Service Implementation handle will lead to
90 unpredicted results.
91
92 @param service Service Implementation handle of already acquired Service.
93 @return Status of performed operation
94 @retval false success
95 @retval true failure
96 */
97 static DEFINE_BOOL_METHOD(release, (my_h_service service));
98
99 /**
100 Registers a new Service Implementation. If it is the first Service
101 Implementation for the specified Service then it is made a default one.
102
103 @param service_implementation_name Name of the Service Implementation to
104 register.
105 @param ptr Pointer to the Service Implementation structure.
106 @return Status of performed operation
107 @retval false success
108 @retval true failure
109 */
111 (const char *service_implementation_name,
112 my_h_service ptr));
113
114 /**
115 Removes previously registered Service Implementation from registry. If it is
116 the default one for specified Service then any one still registered is made
117 default. If there is no other, the default entry is removed from the
118 Registry too.
119
120 @param service_implementation_name Name of the Service Implementation to
121 unregister.
122 @return Status of performed operation
123 @retval false success
124 @retval true Failure. May happen when Service is still being referenced.
125 */
127 (const char *service_implementation_name));
128
129 /**
130 Sets new default Service Implementation for corresponding Service name.
131
132 @param service_implementation_name Name of the Service Implementation to
133 set as default one.
134 @return Status of performed operation
135 @retval false success
136 @retval true failure
137 */
139 (const char *service_implementation_name));
140
141 /**
142 Creates iterator that iterates through all registered Service
143 Implementations. If successful it leaves read lock on the Registry until
144 iterator is released. The starting point of iteration may be specified
145 to be on one particular Service Implementation. The iterator will move
146 through all Service Implementations and additionally through all default
147 Service Implementation additionally, i.e. the default Service Implementation
148 will be returned twice. If no name is specified for search, iterator will be
149 positioned on the first Service Implementation.
150
151 @param service_name_pattern Name of Service or Service Implementation to
152 start iteration from. May be empty string or NULL pointer, in which case
153 iteration starts from the first Service Implementation.
154 @param [out] out_iterator Pointer to the Service Implementation iterator
155 handle.
156 @return Status of performed operation
157 @retval false success
158 @retval true failure
159 */
161 (const char *service_name_pattern,
162 my_h_service_iterator *out_iterator));
163
164 /**
165 Releases Service implementations iterator. Releases read lock on registry.
166
167 @param iterator Service Implementation iterator handle.
168 */
169 static DEFINE_METHOD(void, iterator_release,
170 (my_h_service_iterator iterator));
171
172 /**
173 Gets name of Service pointed to by iterator. The pointer returned will last
174 at least up to the moment of call to the release() method on the iterator.
175
176 @param iterator Service Implementation iterator handle.
177 @param [out] out_name Pointer to string with name to set result pointer to.
178 @return Status of performed operation
179 @retval false success
180 @retval true Failure, may be caused when called on iterator that went
181 through all values already.
182 */
184 const char **out_name));
185
186 /**
187 Advances specified iterator to next element. Will succeed but return true if
188 it reaches one-past-last element.
189
190 @param iterator Service Implementation iterator handle.
191 @return Status of performed operation and validity of iterator after
192 operation.
193 @retval false success
194 @retval true Failure or called on iterator that was on last element.
195 */
197
198 /**
199 Checks if specified iterator is valid, i.e. have not reached one-past-last
200 element.
201
202 @param iterator Service Implementation iterator handle.
203 @return Validity of iterator
204 @retval false Valid
205 @retval true Invalid or reached one-past-last element.
206 */
208 (my_h_service_iterator iterator));
209
210 /* This includes metadata-related method implementations that are shared
211 by registry and dynamic_loader, so we don't duplicate the code. Following
212 defines set up all required symbols. Unfortunately they are not only the
213 types, but also static members with different name, so usage of templates
214 is not enough to reuse that part of code. */
215#define OBJECT_ITERATOR my_h_service_iterator
216#define METADATA_ITERATOR my_h_service_metadata_iterator
217
219};
220#endif /* MYSQL_SERVER_REGISTRY_H */
Locks RW-lock and releases lock on scope exit.
Definition: rwlock_scoped_lock.h:32
Definition: registry_imp.h:29
static void init()
Initializes registry for usage.
Definition: registry.cc:73
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:178
static mysql_rwlock_t LOCK_registry
Definition: registry_imp.h:30
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:312
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:368
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:118
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:216
static minimal_chassis::rwlock_scoped_lock lock_registry_for_write()
Locks whole registry for write.
Definition: registry.cc:101
static void deinit()
De-initializes registry.
Definition: registry.cc:83
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:140
static mysql_service_status_t unregister(const char *service_implementation_name) noexcept
Removes previously registered Service Implementation from registry.
Definition: registry.cc:199
static mysql_service_status_t iterator_next(my_h_service_iterator iterator) noexcept
Advances specified iterator to next element.
Definition: registry.cc:342
static void iterator_release(my_h_service_iterator iterator) noexcept
Releases Service implementations iterator.
Definition: registry.cc:288
static mysql_service_status_t release(my_h_service service) noexcept
Releases the Service Implementation previously acquired.
Definition: registry.cc:158
static void rw_lock_deinit()
De-initializes RW lock.
Definition: registry.cc:91
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:244
Definition: registry_no_lock_imp.h:38
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:32
#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:87
#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:78
Definition: registry.cc:47
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:50