MySQL 9.0.0
Source Code Documentation
event_tracking_lifecycle_consumer_helper.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 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 EVENT_TRACKING_LIFECYCLE_CONSUMER_HELPER_H
25#define EVENT_TRACKING_LIFECYCLE_CONSUMER_HELPER_H
26
30
31/**
32 @file event_tracking_lifecycle_consumer_helper.h
33 Helper file to create lifecycle event consumer
34*/
35
36// clang-format off
37/**
38 @anchor EVENT_TRACKING_LIFECYCLE_CONSUMER_EXAMPLE
39
40 @code
41
42 #include "mysql/components/util/event_tracking_lifecycle_consumer_helper.h"
43
44 namespace Event_tracking_implementation {
45
46 // Replace following with union of startup subevents to be filtered
47 Event_tracking_lifecycle_subclass_t
48 Event_tracking_lifecycle_implementation::startup_filtered_sub_events = 0;
49
50 // Replace following with union of shutdown subevents to be filtered
51 Event_tracking_lifecycle_subclass_t
52 Event_tracking_lifecycle_implementation::shutdown_filtered_sub_events = 0;
53
54 bool Event_tracking_lifecycle_implementation::callback(
55 const mysql_event_tracking_startup_data *data [[maybe_unused]]) {
56 // Your code goes here
57 }
58
59 bool Event_tracking_lifecycle_implementation::callback(
60 const mysql_event_tracking_shutdown_data *data [[maybe_unused]]) {
61 // Your code goes here
62 }
63 } // namespace Event_tracking_implementation
64
65 // Define init/deinit methods for component
66
67 // Component declaration related stuff
68
69 IMPLEMENTS_SERVICE_EVENT_TRACKING_LIFECYCLE(<implementation_name>);
70
71 BEGIN_COMPONENT_PROVIDES(<component_name>)
72 PROVIDES_SERVICE_EVENT_TRACKING_LIFECYCLE(<implementation_name>)
73 END_COMPONENT_PROVIDES()
74
75 // Rest of the component declaration code
76
77 @endcode
78*/
79// clang-format on
80
81#define PROVIDES_SERVICE_EVENT_TRACKING_LIFECYCLE(component) \
82 PROVIDES_SERVICE(component, event_tracking_lifecycle)
83
84#define IMPLEMENTS_SERVICE_EVENT_TRACKING_LIFECYCLE(component) \
85 BEGIN_SERVICE_IMPLEMENTATION(component, event_tracking_lifecycle) \
86 Event_tracking_implementation::Event_tracking_lifecycle_implementation:: \
87 notify_startup, \
88 Event_tracking_implementation::Event_tracking_lifecycle_implementation:: \
89 notify_shutdown \
90 END_SERVICE_IMPLEMENTATION()
91
93/** Implementation helper class for lifecycle events. */
95 public:
96 /** Sub-events to be filtered/ignored - To be defined by the component */
98
99 /** Sub-events to be filtered/ignored - To be defined by the component */
101
102 /** Callback function - To be implemented by component to handle an event */
104
105 /** Callback function - To be implemented by component to handle an event */
107
108 /**
109 event_tracking_lifecycle service implementation
110
111 @param [in] data Data related to startup event
112
113 @returns Status of operation
114 @retval false Success
115 @retval true Failure
116 */
119 try {
120 if (!data) return true;
121 if (data->event_subclass & startup_filtered_sub_events) return false;
122 return callback(data);
123 } catch (...) {
124 return true;
125 }
126 }
127
128 /**
129 event_tracking_lifecycle service implementation
130
131 @param [in] data Data related to shutdown event
132
133 @returns Status of operation
134 @retval false Success
135 @retval true Failure
136 */
139 try {
140 if (!data) return true;
141 if (data->event_subclass & shutdown_filtered_sub_events) return false;
142 return callback(data);
143 } catch (...) {
144 return true;
145 }
146 }
147};
148} // namespace Event_tracking_implementation
149
150#endif // !EVENT_TRACKING_LIFECYCLE_CONSUMER_HELPER_H
Implementation helper class for lifecycle events.
Definition: event_tracking_lifecycle_consumer_helper.h:94
static bool callback(const mysql_event_tracking_shutdown_data *data)
Callback function - To be implemented by component to handle an event.
static bool callback(const mysql_event_tracking_startup_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_service_status_t notify_shutdown(const mysql_event_tracking_shutdown_data *data) noexcept
event_tracking_lifecycle service implementation
Definition: event_tracking_lifecycle_consumer_helper.h:138
static mysql_service_status_t notify_startup(const mysql_event_tracking_startup_data *data) noexcept
event_tracking_lifecycle service implementation
Definition: event_tracking_lifecycle_consumer_helper.h:118
static mysql_event_tracking_shutdown_subclass_t shutdown_filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_lifecycle_consumer_helper.h:100
static mysql_event_tracking_startup_subclass_t startup_filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_lifecycle_consumer_helper.h:97
Specifies macros to define Components.
unsigned long mysql_event_tracking_shutdown_subclass_t
Events for Shutdown event tracking.
Definition: event_tracking_lifecycle_defs.h:68
unsigned long mysql_event_tracking_startup_subclass_t
Events for Startup event tracking.
Definition: event_tracking_lifecycle_defs.h:42
Program lifecycle event tracking.
Definition: event_tracking_authentication_consumer_helper.h:81
Specifies macros to define Service Implementations.
#define DEFINE_BOOL_METHOD(name, args)
A short macro to define method that returns bool, which is the most common case.
Definition: service_implementation.h:88
Structure for Shutdown event tracking.
Definition: event_tracking_lifecycle_defs.h:87
mysql_event_tracking_shutdown_subclass_t event_subclass
Shutdown event.
Definition: event_tracking_lifecycle_defs.h:89
Structure for Startup event tracking.
Definition: event_tracking_lifecycle_defs.h:49
mysql_event_tracking_startup_subclass_t event_subclass
Event subclass.
Definition: event_tracking_lifecycle_defs.h:51