MySQL  8.0.19
Source Code Documentation
builtin_plugins.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
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 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 
25 #ifndef MYSQL_HARNESS_BUILTIN_PLUGINS_INCLUDED
26 #define MYSQL_HARNESS_BUILTIN_PLUGINS_INCLUDED
27 
28 #include "mysql/harness/plugin.h"
29 
30 #include <map>
31 #include <string>
32 
33 namespace mysql_harness {
34 
35 /**
36  * @brief Singleton class implementing registry of the built-in MySQLRouter
37  * plugins.
38  *
39  * Built-in plugin is statically linked to the harness library (does not have
40  * dedicated .so or .dll file) but implements the same API as the external
41  * plugin (init(), start(), etc.) that is called by the Loader.
42  */
44  public:
45  /**
46  * @brief Gets the singleton instance.
47  */
48  static BuiltinPlugins &instance();
49 
50  /**
51  * It's a singleton so we disable copying.
52  */
53  BuiltinPlugins(const BuiltinPlugins &) = delete;
54  BuiltinPlugins &operator=(const BuiltinPlugins &) = delete;
55 
56  /**
57  * Stores the information about a single built-in plugin.
58  */
59  struct PluginInfo {
60  /**
61  * pointer to the plugin struct (used by the Loader to run init(),
62  * start(), etc on the plugin)
63  */
65 
66  /** if true the plugin should ALWAYS be loaded even if it does not have
67  * its section in the configuration
68  */
70  };
71 
72  using PluginsMap = std::map<std::string, PluginInfo>;
73 
74  /** @brief Checks if there is a built-in plugin with a specified name
75  *
76  * @param plugin_name plugin name to check
77  * @return true if there is a built-in plugin with a given name in the
78  * registry, false otherwise
79  */
80  bool has(const std::string &plugin_name) noexcept;
81 
82  /** @brief Returns the map containing information about all built-in plugins
83  * in the registry
84  *
85  * @return map containing information about all built-in plugins in the
86  * registry
87  */
88  const PluginsMap *get() noexcept { return &plugins_; }
89 
90  /** @brief Returns pointer to the Plugin struct for the plugin with
91  * selected name
92  *
93  * @throw std::out_of_range if there is no info about the plugin with a given
94  * name.
95  *
96  * @param plugin_name name of the plugin queried for the Plugin struct
97  * @return Plugin struct for the plugin with selected name
98  */
99  Plugin *get_plugin(const std::string &plugin_name) {
100  return plugins_.at(plugin_name).plugin;
101  }
102 
103  private:
104  BuiltinPlugins();
106 };
107 
108 } // namespace mysql_harness
109 
110 #endif
mysql_harness::BuiltinPlugins::has
bool has(const std::string &plugin_name) noexcept
Checks if there is a built-in plugin with a specified name.
Definition: builtin_plugins.cc:55
mysql_harness::BuiltinPlugins::PluginInfo::plugin
Plugin * plugin
pointer to the plugin struct (used by the Loader to run init(), start(), etc on the plugin)
Definition: builtin_plugins.h:64
plugin_name
LEX_CSTRING * plugin_name(st_plugin_int **ref)
Definition: sql_plugin_ref.h:94
mysql_harness::BuiltinPlugins::plugins_
const PluginsMap plugins_
Definition: builtin_plugins.h:105
mysql_harness::BuiltinPlugins::PluginInfo
Stores the information about a single built-in plugin.
Definition: builtin_plugins.h:59
mysql_harness::BuiltinPlugins::operator=
BuiltinPlugins & operator=(const BuiltinPlugins &)=delete
mysql_harness::BuiltinPlugins::get_plugin
Plugin * get_plugin(const std::string &plugin_name)
Returns pointer to the Plugin struct for the plugin with selected name.
Definition: builtin_plugins.h:99
mysql_harness::BuiltinPlugins::instance
static BuiltinPlugins & instance()
Gets the singleton instance.
Definition: builtin_plugins.cc:50
mysql_harness::BuiltinPlugins
Singleton class implementing registry of the built-in MySQLRouter plugins.
Definition: builtin_plugins.h:43
mysql_harness::BuiltinPlugins::get
const PluginsMap * get() noexcept
Returns the map containing information about all built-in plugins in the registry.
Definition: builtin_plugins.h:88
mysql_harness::BuiltinPlugins::BuiltinPlugins
BuiltinPlugins()
Definition: builtin_plugins.cc:37
Plugin
Sergei Dialog Client Authentication Plugin
Definition: dialog.cc:352
mysql_harness
Definition: common.h:39
mysql_harness::BuiltinPlugins::PluginsMap
std::map< std::string, PluginInfo > PluginsMap
Definition: builtin_plugins.h:72
mysql_harness::BuiltinPlugins::PluginInfo::always_load
bool always_load
if true the plugin should ALWAYS be loaded even if it does not have its section in the configuration
Definition: builtin_plugins.h:69