MySQL 8.0.30
Source Code Documentation
udf_service_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2022, 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 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 UDF_SERVICE_IMPL_H
24#define UDF_SERVICE_IMPL_H
25
28
29#include <string>
30#include <vector>
31
32/**
33 Contains all the necessary data to register an UDF in MySQL.
34*/
35typedef struct udf_data_t {
36 const std::string m_name;
41 udf_data_t(const std::string &name, const Item_result return_type,
42 const Udf_func_string func, const Udf_func_init init_func,
43 const Udf_func_deinit deinit_func)
44 : m_name(name),
45 m_return_type(return_type),
46 m_func(func),
47 m_init_func(init_func),
48 m_deinit_func(deinit_func) {}
49 udf_data_t(udf_data_t const &) = delete;
50 udf_data_t(udf_data_t &&other) = delete;
51 udf_data_t &operator=(udf_data_t const &) = delete;
52 udf_data_t &operator=(udf_data_t &&other) = delete;
54
55/*
56 Utility class for registering UDF service.
57
58 For usage please check sql/rpl_async_conn_failover_udf.cc
59*/
61 private:
62 /* UDF registry service. */
63 SERVICE_TYPE(registry) * m_registry{nullptr};
64
65 /* List of registered udfs name. */
66 std::vector<std::string> m_udfs_registered;
67
68 public:
69 Udf_service_impl() = default;
70 virtual ~Udf_service_impl() = default;
71
72 /**
73 Initialize variables, acquires the mysql_service_mysql_udf_metadata from the
74 registry service and register the Asynchronous Connection Failover's UDFs.
75 If there is an error registering any UDF, all installed UDFs are
76 unregistered.
77
78 @retval true if there was an error
79 @retval false if all UDFs were registered
80 */
81 virtual bool init() = 0;
82
83 /**
84 Release the mysql_service_mysql_udf_metadata service and unregisters the
85 Asynchronous Connection Failover's UDFs.
86
87 @retval true if there was an error
88 @retval false if all UDFs were unregistered
89 */
90 bool deinit();
91
92 /**
93 Save UDF registry service.
94
95 param[in] r UDF registry service.
96 */
97 void set_registry(SERVICE_TYPE(registry) * r) { m_registry = r; }
98
99 /**
100 Registers the Asynchronous Connection Failover's UDFs.
101 If there is an error registering any UDF, all installed UDFs are
102 unregistered.
103
104 @retval true if there was an error
105 @retval false if all UDFs were registered
106 */
107 bool register_udf(Udf_data &e);
108
109 /**
110 Unregisters the Asynchronous Connection Failover's UDFs.
111
112 @retval true if there was an error
113 @retval false if all UDFs were unregistered
114 */
115 bool unregister_udf(const std::string udf_name);
116};
117
118/*
119 Used to load registered UDFs
120*/
122 private:
123 /* List of registered udfs functions. */
124 std::vector<Udf_service_impl *> m_udfs_registered;
125
126 template <class T>
127 void add() {
128 T *obj = new T();
129 m_udfs_registered.emplace_back(obj);
130 }
131
132 void register_udf();
133
134 void unregister_udf();
135
136 public:
138
140
141 /**
142 Registers the Asynchronous Connection Failover's UDFs.
143 If there is an error registering any UDF, all installed UDFs are
144 unregistered.
145
146 @retval true if there was an error
147 @retval false if all UDFs were registered
148 */
149 bool init();
150
151 /**
152 Unregisters the Asynchronous Connection Failover's UDFs.
153
154 @retval true if there was an error
155 @retval false if all UDFs were unregistered
156 */
157 bool deinit();
158};
159
160#endif /* UDF_SERVICE_IMPL_H */
Definition: udf_service_impl.h:121
~Udf_load_service()
Definition: udf_service_impl.cc:105
Udf_load_service()
Definition: udf_service_impl.cc:103
bool init()
Registers the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:107
std::vector< Udf_service_impl * > m_udfs_registered
Definition: udf_service_impl.h:124
void register_udf()
Definition: udf_service_impl.cc:123
void unregister_udf()
Definition: udf_service_impl.cc:131
bool deinit()
Unregisters the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:115
void add()
Definition: udf_service_impl.h:127
Definition: udf_service_impl.h:60
const mysql_service_registry_t * m_registry
Definition: udf_service_impl.h:63
void set_registry(const mysql_service_registry_t *r)
Save UDF registry service.
Definition: udf_service_impl.h:97
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:69
bool deinit()
Release the mysql_service_mysql_udf_metadata service and unregisters the Asynchronous Connection Fail...
Definition: udf_service_impl.cc:93
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:66
bool register_udf(Udf_data &e)
Registers the Asynchronous Connection Failover's UDFs.
Definition: udf_service_impl.cc:38
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:75
case opt name
Definition: sslopt-case.h:32
Contains all the necessary data to register an UDF in MySQL.
Definition: backup_page_tracker.h:50
const Item_result m_return_type
Definition: udf_service_impl.h:37
udf_data_t(udf_data_t &&other)=delete
Item_result m_return_type
Definition: backup_page_tracker.h:52
const Udf_func_deinit m_deinit_func
Definition: udf_service_impl.h:40
std::string m_name
Definition: backup_page_tracker.h:51
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:36
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:41
const Udf_func_init m_init_func
Definition: udf_service_impl.h:39
const Udf_func_string m_func
Definition: udf_service_impl.h:38
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:86
void(* Udf_func_deinit)(UDF_INIT *)
Definition: udf_registration_types.h:79
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
bool(* Udf_func_init)(UDF_INIT *, UDF_ARGS *, char *)
Definition: udf_registration_types.h:80
struct udf_data_t Udf_data
Contains all the necessary data to register an UDF in MySQL.