MySQL 8.4.0
Source Code Documentation
udf_service_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef UDF_SERVICE_IMPL_H
25#define UDF_SERVICE_IMPL_H
26
29
30#include <string>
31#include <vector>
32
33/**
34 Contains all the necessary data to register an UDF in MySQL.
35*/
36typedef struct udf_data_t {
37 const std::string m_name;
42 udf_data_t(const std::string &name, const Item_result return_type,
43 const Udf_func_string func, const Udf_func_init init_func,
44 const Udf_func_deinit deinit_func)
45 : m_name(name),
46 m_return_type(return_type),
47 m_func(func),
48 m_init_func(init_func),
49 m_deinit_func(deinit_func) {}
50 udf_data_t(udf_data_t const &) = delete;
51 udf_data_t(udf_data_t &&other) = delete;
52 udf_data_t &operator=(udf_data_t const &) = delete;
53 udf_data_t &operator=(udf_data_t &&other) = delete;
55
56/*
57 Utility class for registering UDF service.
58
59 For usage please check sql/rpl_async_conn_failover_udf.cc
60*/
62 private:
63 /* UDF registry service. */
64 SERVICE_TYPE(registry) * m_registry{nullptr};
65
66 /* List of registered udfs name. */
67 std::vector<std::string> m_udfs_registered;
68
69 public:
70 Udf_service_impl() = default;
71 virtual ~Udf_service_impl() = default;
72
73 /**
74 Initialize variables, acquires the mysql_service_mysql_udf_metadata from the
75 registry service and register the Asynchronous Connection Failover's UDFs.
76 If there is an error registering any UDF, all installed UDFs are
77 unregistered.
78
79 @retval true if there was an error
80 @retval false if all UDFs were registered
81 */
82 virtual bool init() = 0;
83
84 /**
85 Release the mysql_service_mysql_udf_metadata service and unregisters the
86 Asynchronous Connection Failover's UDFs.
87
88 @retval true if there was an error
89 @retval false if all UDFs were unregistered
90 */
91 bool deinit();
92
93 /**
94 Save UDF registry service.
95
96 param[in] r UDF registry service.
97 */
98 void set_registry(SERVICE_TYPE(registry) * r) { m_registry = r; }
99
100 /**
101 Registers the Asynchronous Connection Failover's UDFs.
102 If there is an error registering any UDF, all installed UDFs are
103 unregistered.
104
105 @retval true if there was an error
106 @retval false if all UDFs were registered
107 */
108 bool register_udf(Udf_data &e);
109
110 /**
111 Unregisters the Asynchronous Connection Failover's UDFs.
112
113 @retval true if there was an error
114 @retval false if all UDFs were unregistered
115 */
116 bool unregister_udf(const std::string udf_name);
117};
118
119/*
120 Used to load registered UDFs
121*/
123 private:
124 /* List of registered udfs functions. */
125 std::vector<Udf_service_impl *> m_udfs_registered;
126
127 template <class T>
128 void add() {
129 T *obj = new T();
130 m_udfs_registered.emplace_back(obj);
131 }
132
133 void register_udf();
134
135 void unregister_udf();
136
137 public:
139
141
142 /**
143 Registers the Asynchronous Connection Failover's UDFs.
144 If there is an error registering any UDF, all installed UDFs are
145 unregistered.
146
147 @retval true if there was an error
148 @retval false if all UDFs were registered
149 */
150 bool init();
151
152 /**
153 Unregisters the Asynchronous Connection Failover's UDFs.
154
155 @retval true if there was an error
156 @retval false if all UDFs were unregistered
157 */
158 bool deinit();
159};
160
161#endif /* UDF_SERVICE_IMPL_H */
Definition: udf_service_impl.h:122
~Udf_load_service()
Definition: udf_service_impl.cc:106
Udf_load_service()
Definition: udf_service_impl.cc:104
bool init()
Registers the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:108
std::vector< Udf_service_impl * > m_udfs_registered
Definition: udf_service_impl.h:125
void register_udf()
Definition: udf_service_impl.cc:124
void unregister_udf()
Definition: udf_service_impl.cc:132
bool deinit()
Unregisters the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:116
void add()
Definition: udf_service_impl.h:128
Definition: udf_service_impl.h:61
const mysql_service_registry_t * m_registry
Definition: udf_service_impl.h:64
void set_registry(const mysql_service_registry_t *r)
Save UDF registry service.
Definition: udf_service_impl.h:98
virtual ~Udf_service_impl()=default
bool unregister_udf(const std::string udf_name)
Unregisters the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:70
bool deinit()
Release the mysql_service_mysql_udf_metadata service and unregisters the Asynchronous Connection Fail...
Definition: udf_service_impl.cc:94
virtual bool init()=0
Initialize variables, acquires the mysql_service_mysql_udf_metadata from the registry service and reg...
Udf_service_impl()=default
std::vector< std::string > m_udfs_registered
Definition: udf_service_impl.h:67
bool register_udf(Udf_data &e)
Registers the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:39
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
case opt name
Definition: sslopt-case.h:29
Contains all the necessary data to register an UDF in MySQL.
Definition: backup_page_tracker.h:51
const Item_result m_return_type
Definition: udf_service_impl.h:38
udf_data_t(udf_data_t &&other)=delete
Item_result m_return_type
Definition: backup_page_tracker.h:53
const Udf_func_deinit m_deinit_func
Definition: udf_service_impl.h:41
std::string m_name
Definition: backup_page_tracker.h:52
udf_data_t & operator=(udf_data_t &&other)=delete
udf_data_t & operator=(udf_data_t const &)=delete
const std::string m_name
Definition: udf_service_impl.h:37
udf_data_t(const std::string &name, const Item_result return_type, const Udf_func_string func, const Udf_func_init init_func, const Udf_func_deinit deinit_func)
Definition: udf_service_impl.h:42
const Udf_func_init m_init_func
Definition: udf_service_impl.h:40
const Udf_func_string m_func
Definition: udf_service_impl.h:39
udf_data_t(udf_data_t const &)=delete
char *(* Udf_func_string)(UDF_INIT *, UDF_ARGS *, char *, unsigned long *, unsigned char *, unsigned char *)
Definition: udf_registration_types.h:87
void(* Udf_func_deinit)(UDF_INIT *)
Definition: udf_registration_types.h:80
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39
bool(* Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *)
Definition: udf_registration_types.h:81
struct udf_data_t Udf_data
Contains all the necessary data to register an UDF in MySQL.