MySQL 9.1.0
Source Code Documentation
my_service.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 MY_SERVICE_H
25#define MY_SERVICE_H
26
29
30/**
31 Wraps my_h_service struct conforming ABI into RAII C++ object with ability to
32 cast to desired service type.
33*/
34template <typename TService>
36 public:
37 /**
38 Default contructor: constructs an empty my_service
39 */
41
42 /**
43 An acquire convenience constructor
44 */
45 my_service(const char *name, SERVICE_TYPE(registry) * registry) {
46 acquire(name, registry);
47 }
48 /**
49 Acquires service by name.
50
51 @param name Name of service, with or without component name, to acquire.
52 @param registry Handle to registry service to use. The registry service
53 must be valid (i.e. not released) up to the moment when this instance
54 dies.
55 */
56 void acquire(const char *name, SERVICE_TYPE(registry) * registry) {
57 m_registry = registry;
58 if (registry->acquire(name, &m_service)) {
59 /* NULLed service handle means no valid service managed. */
60 m_service = {};
61 }
62 }
63 /**
64 Acquires service by name.
65
66 @param name Name of service, with or without component name, to acquire.
67 @param related_service Handle to service to acquire related to.
68 @param registry Handle to registry service to use.
69 */
70 my_service(const char *name, my_h_service related_service,
71 SERVICE_TYPE(registry) * registry)
72 : m_registry(registry) {
73 if (registry->acquire_related(name, related_service, &m_service)) {
74 /* NULLed service handle means no valid service managed. */
75 m_service = nullptr;
76 }
77 }
78 /**
79 Wraps service implementation already acquired.
80
81 @param service Service handle to manage.
82 @param registry Handle to registry service to use.
83 */
84 my_service(my_h_service service, SERVICE_TYPE(registry) * registry)
85 : m_service(service), m_registry(registry) {}
86
87 my_service(const my_service<TService> &other) = delete;
88
90 : m_service(other.m_service), m_registry(other.m_registry) {
91 other.m_service = nullptr;
92 }
94
96 m_service = other.m_service;
97 m_registry = other.m_registry;
98 other.m_service = nullptr;
99 }
100
101 /**
102 Releases the reference, if any, and cleans the instance up.
103 */
104 void release() {
105 if (this->is_valid()) m_registry->release(m_service);
106 m_service = nullptr;
107 m_registry = nullptr;
108 }
109
111
112 operator TService *() const {
113 return reinterpret_cast<TService *>(m_service);
114 }
115
116 operator my_h_service() const { return m_service; }
117 /**
118 Returns managed service typed as desired service type to execute
119 operations specified after -> on it.
120 */
121 TService *operator->() const { return static_cast<TService *>(*this); }
122 /**
123 @retval false Object manages valid service.
124 @retval true Object does not manage any service.
125 */
126 operator bool() const { return !is_valid(); }
127 bool is_valid() const {
128 /* NULLed service handle means no valid service managed. */
129 return static_cast<const my_h_service_imp *>(this->m_service) != nullptr;
130 }
131
132 /**
133 Unties and returns the underlying service handle.
134
135 It will not be released by the destructor.
136
137 @retval the handle
138 */
139 TService *untie() {
140 TService *save = reinterpret_cast<TService *>(m_service);
141 m_service = nullptr;
142 return save;
143 }
144
145 private:
148};
149
150#endif /* MY_SERVICE_H */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Wraps my_h_service struct conforming ABI into RAII C++ object with ability to cast to desired service...
Definition: my_service.h:35
my_service(const char *name, const mysql_service_registry_t *registry)
An acquire convenience constructor.
Definition: my_service.h:45
my_service(my_h_service service, const mysql_service_registry_t *registry)
Wraps service implementation already acquired.
Definition: my_service.h:84
my_h_service m_service
Definition: my_service.h:146
bool is_valid() const
Definition: my_service.h:127
void acquire(const char *name, const mysql_service_registry_t *registry)
Acquires service by name.
Definition: my_service.h:56
TService * untie()
Unties and returns the underlying service handle.
Definition: my_service.h:139
~my_service()
Definition: my_service.h:110
TService * operator->() const
Returns managed service typed as desired service type to execute operations specified after -> on it.
Definition: my_service.h:121
my_service(my_service< TService > &&other)
Definition: my_service.h:89
my_service(const char *name, my_h_service related_service, const mysql_service_registry_t *registry)
Acquires service by name.
Definition: my_service.h:70
void release()
Releases the reference, if any, and cleans the instance up.
Definition: my_service.h:104
my_service< TService > & operator=(const my_service< TService > &other)=delete
my_service< TService > & operator=(my_service< TService > &other)
Definition: my_service.h:95
my_service()
Default contructor: constructs an empty my_service.
Definition: my_service.h:40
my_service(const my_service< TService > &other)=delete
const mysql_service_registry_t * m_registry
Definition: my_service.h:147
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:33
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
case opt name
Definition: sslopt-case.h:29
mysql_service_status_t(* release)(my_h_service service)
Releases the Service Implementation previously acquired.
Definition: registry.h:88