MySQL  8.0.18
Source Code Documentation
my_service.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6 
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef MY_SERVICE_H
24 #define MY_SERVICE_H
25 
28 
29 /**
30  Wraps my_h_service struct conforming ABI into RAII C++ object with ability to
31  cast to desired service type.
32 */
33 template <typename TService>
34 class my_service {
35  public:
36  /**
37  Acquires service by name.
38 
39  @param name Name of service, with or without component name, to acquire.
40  @param registry Handle to registry service to use. The registry service
41  must be valid (i.e. not released) up to the moment when this instance
42  dies.
43  */
44  my_service(const char *name, SERVICE_TYPE(registry) * registry)
45  : m_registry(registry) {
46  if (registry->acquire(name, &m_service)) {
47  /* NULLed service handle means no valid service managed. */
48  m_service = {};
49  }
50  }
51  /**
52  Acquires service by name.
53 
54  @param name Name of service, with or without component name, to acquire.
55  @param related_service Handle to service to acquire related to.
56  @param registry Handle to registry service to use.
57  */
58  my_service(const char *name, my_h_service related_service,
59  SERVICE_TYPE(registry) * registry)
60  : m_registry(registry) {
61  if (registry->acquire_related(name, related_service, &m_service)) {
62  /* NULLed service handle means no valid service managed. */
63  m_service = nullptr;
64  }
65  }
66  /**
67  Wraps service implementation already acquired.
68 
69  @param service Service handle to manage.
70  @param registry Handle to registry service to use.
71  */
72  my_service(my_h_service service, SERVICE_TYPE(registry) * registry)
73  : m_service(service), m_registry(registry) {}
74 
75  my_service(const my_service<TService> &other) = delete;
76 
78  : m_service(other.m_service), m_registry(other.m_registry) {
79  other.m_service = nullptr;
80  }
81 
83  if (this->is_valid()) {
85  }
86  }
87 
88  operator TService *() const {
89  return reinterpret_cast<TService *>(m_service);
90  }
91 
92  operator my_h_service() const { return m_service; }
93  /**
94  Returns managed service typed as desired service type to execute
95  operations specified after -> on it.
96  */
97  TService *operator->() const { return static_cast<TService *>(*this); }
98  /**
99  @retval false Object manages valid service.
100  @retval true Object does not manage any service.
101  */
102  operator bool() const { return !is_valid(); }
103  bool is_valid() const {
104  /* NULLed service handle means no valid service managed. */
105  return static_cast<const my_h_service_imp *>(this->m_service) != nullptr;
106  }
107 
108  private:
111 };
112 
113 #endif /* MY_SERVICE_H */
Wraps my_h_service struct conforming ABI into RAII C++ object with ability to cast to desired service...
Definition: my_service.h:34
const string name("\ame\)
#define bool
Definition: config_static.h:42
const mysql_service_registry_t * m_registry
Definition: my_service.h:110
my_service(my_service< TService > &&other)
Definition: my_service.h:77
my_h_service m_service
Definition: my_service.h:109
#define SERVICE_TYPE(name)
my_service(my_h_service service, const mysql_service_registry_t *registry)
Wraps service implementation already acquired.
Definition: my_service.h:72
~my_service()
Definition: my_service.h:82
TService * operator->() const
Returns managed service typed as desired service type to execute operations specified after -> on it...
Definition: my_service.h:97
my_service(const char *name, my_h_service related_service, const mysql_service_registry_t *registry)
Acquires service by name.
Definition: my_service.h:58
bool is_valid() const
Definition: my_service.h:103
my_service(const char *name, const mysql_service_registry_t *registry)
Acquires service by name.
Definition: my_service.h:44
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:32
mysql_service_status_t(* release)(my_h_service service)
Releases the Service Implementation previously acquired.
Definition: registry.h:88