MySQL 9.3.0
Source Code Documentation
plugin_state.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 2025, 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 ROUTER_SRC_HARNESS_INCLUDE_MYSQL_HARNESS_PLUGIN_STATE_H_
27#define ROUTER_SRC_HARNESS_INCLUDE_MYSQL_HARNESS_PLUGIN_STATE_H_
28
29#include <atomic>
30#include <map>
31#include <memory>
32#include <mutex>
33#include <vector>
34
36
37#include "harness_export.h"
38
39namespace mysql_harness {
40
41class HARNESS_EXPORT PluginState {
42 public:
43 using PluginName = std::string;
44 using Plugins = std::vector<PluginName>;
45 using ObserverId = uint32_t;
46 using ObserverPtr = std::weak_ptr<PluginStateObserver>;
47 using MapOfListeners = std::map<ObserverId, ObserverPtr>;
48
49 constexpr static ObserverId k_invalid_id_ = 0;
50
51 public:
52 virtual ~PluginState() = default;
53
54 static PluginState *get_instance();
55
56 virtual ObserverId push_back_observer(ObserverPtr psl);
57 virtual std::vector<ObserverId> push_back_observers(
58 const std::vector<ObserverPtr> &array);
59 virtual void remove_observer(ObserverId k);
60 virtual void remove_observers(const std::vector<ObserverId> &k);
61
62 virtual void dispatch_register_waitable(const PluginName &name);
63 virtual void dispatch_startup(const PluginName &name);
64 virtual void dispatch_shutdown(const PluginName &name);
65
66 virtual Plugins get_running_plugins() const;
67 virtual Plugins get_loaded_plugins() const;
68
69 protected:
70 class PluginStateOp;
72
73 std::atomic<ObserverId> last_used_id_{k_invalid_id_};
74 mutable std::mutex mutex_guard_listeners_;
79 std::shared_ptr<PluginStateObserver> default_observer_;
80};
81
82} // namespace mysql_harness
83
84#endif // ROUTER_SRC_HARNESS_INCLUDE_MYSQL_HARNESS_PLUGIN_STATE_H_
Definition: plugin_state.cc:62
Definition: plugin_state.h:41
Plugins stopped_plugins_
Definition: plugin_state.h:77
std::map< ObserverId, ObserverPtr > MapOfListeners
Definition: plugin_state.h:47
uint32_t ObserverId
Definition: plugin_state.h:45
std::vector< PluginName > Plugins
Definition: plugin_state.h:44
virtual ~PluginState()=default
std::string PluginName
Definition: plugin_state.h:43
std::weak_ptr< PluginStateObserver > ObserverPtr
Definition: plugin_state.h:46
Plugins loaded_plugins_
Definition: plugin_state.h:78
MapOfListeners listeners_
Definition: plugin_state.h:75
std::mutex mutex_guard_listeners_
Definition: plugin_state.h:74
std::shared_ptr< PluginStateObserver > default_observer_
Definition: plugin_state.h:79
Plugins running_plugins_
Definition: plugin_state.h:76
Definition: common.h:44