MySQL 26.10.0
Source Code Documentation
mrs_component_udfs.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MRS_COMPONENT_UDF_MANAGER_H
27#define MRS_COMPONENT_UDF_MANAGER_H
28
29#include <cstring>
30#include <set>
31#include <string>
32
34
35namespace mrs_component {
36
37// UDF layout:
38struct UDF {
39 UDF() = default;
40
41 const char *name = nullptr;
43 Udf_func_any function = nullptr;
46
47 // operator< to allow comparisons for std::set
48 bool operator<(const UDF &other) const {
49 return std::strcmp(name, other.name) < 0;
50 }
51};
52
53/**
54 Owns and manages the UDFs provided by the MRS component.
55*/
56class UDFs {
57 public:
58 UDFs() = default;
59 ~UDFs() = default;
60 UDFs(const UDFs &) = delete;
61 UDFs &operator=(const UDFs &) = delete;
62 UDFs(UDFs &&) = delete;
63 UDFs &operator=(UDFs &&) = delete;
64
65 int initialize_all();
66 int register_all();
67 int unregister_all();
68
69 static void throw_udf_error(const char *udf_name, const char *error_message);
70
71 // UDF callbacks
72 static bool mysql_rest_service_restart_init(UDF_INIT *initid, UDF_ARGS *args,
73 char *message);
75 [[maybe_unused]]);
76 static long long mysql_rest_service_restart(UDF_INIT *, UDF_ARGS *args,
77 unsigned char *,
78 unsigned char *error);
79
80 static bool mysql_rest_service_stop_init(UDF_INIT *initid, UDF_ARGS *args,
81 char *message);
82 static void mysql_rest_service_stop_deinit(UDF_INIT *initid [[maybe_unused]]);
83 static long long mysql_rest_service_stop(UDF_INIT *, UDF_ARGS *args,
84 unsigned char *,
85 unsigned char *error);
86
87 static bool mysql_rest_service_start_init(UDF_INIT *initid, UDF_ARGS *args,
88 char *message);
90 [[maybe_unused]]);
91 static long long mysql_rest_service_start(UDF_INIT *, UDF_ARGS *args,
92 unsigned char *,
93 unsigned char *error);
94
95 private:
96 std::set<UDF> m_udf_list;
97 std::set<std::string> m_registered_udfs;
98};
99
100} // namespace mrs_component
101
102#endif // MRS_COMPONENT_UDF_MANAGER_H
Owns and manages the UDFs provided by the MRS component.
Definition: mrs_component_udfs.h:56
static void mysql_rest_service_start_deinit(UDF_INIT *initid)
Callback function for de-initialization of UDF "mysql_rest_service_start".
Definition: mrs_component_udfs.cc:300
int initialize_all()
Initialize the MySQL Rest Service Component UDFs.
Definition: mrs_component_udfs.cc:100
int register_all()
Register the MySQL Rest Service Component UDFs in the server.
Definition: mrs_component_udfs.cc:151
static void mysql_rest_service_stop_deinit(UDF_INIT *initid)
Callback function for de-initialization of UDF "mysql_rest_service_stop".
Definition: mrs_component_udfs.cc:256
std::set< UDF > m_udf_list
Definition: mrs_component_udfs.h:96
static long long mysql_rest_service_restart(UDF_INIT *, UDF_ARGS *args, unsigned char *, unsigned char *error)
UDF for "mysql_rest_service_restart".
Definition: mrs_component_udfs.cc:215
static void mysql_rest_service_restart_deinit(UDF_INIT *initid)
Callback function for de-initialization of UDF "mysql_rest_service_restart".
Definition: mrs_component_udfs.cc:209
std::set< std::string > m_registered_udfs
Definition: mrs_component_udfs.h:97
static bool mysql_rest_service_restart_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
Callback function for initialization of UDF "mysql_rest_service_restart".
Definition: mrs_component_udfs.cc:192
UDFs & operator=(const UDFs &)=delete
static long long mysql_rest_service_stop(UDF_INIT *, UDF_ARGS *args, unsigned char *, unsigned char *error)
UDF for "mysql_rest_service_stop".
Definition: mrs_component_udfs.cc:261
UDFs(const UDFs &)=delete
static bool mysql_rest_service_start_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
Callback function for initialization of UDF "mysql_rest_service_start".
Definition: mrs_component_udfs.cc:284
int unregister_all()
Unregister the MySQL Rest Service Component UDFs from the server.
Definition: mrs_component_udfs.cc:169
UDFs(UDFs &&)=delete
static long long mysql_rest_service_start(UDF_INIT *, UDF_ARGS *args, unsigned char *, unsigned char *error)
UDF for "mysql_rest_service_start".
Definition: mrs_component_udfs.cc:305
static void throw_udf_error(const char *udf_name, const char *error_message)
Definition: mrs_component_udfs.cc:91
UDFs & operator=(UDFs &&)=delete
static bool mysql_rest_service_stop_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
Callback function for initialization of UDF "mysql_rest_service_stop".
Definition: mrs_component_udfs.cc:240
Definition: mrs_component.cc:137
Definition: udf_registration_types.h:48
Information about the result of a user defined function.
Definition: udf_registration_types.h:66
Definition: mrs_component_udfs.h:38
const char * name
Definition: mrs_component_udfs.h:41
enum Item_result return_type
Definition: mrs_component_udfs.h:42
Udf_func_deinit deinit_function
Definition: mrs_component_udfs.h:45
bool operator<(const UDF &other) const
Definition: mrs_component_udfs.h:48
Udf_func_init init_function
Definition: mrs_component_udfs.h:44
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
void(* Udf_func_any)(void)
Definition: udf_registration_types.h:82