MySQL 8.0.39
Source Code Documentation
abstract_chain_element.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2024, 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, version 2.0, 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 ABSTRACT_CHAIN_ELEMENT_INCLUDED
27#define ABSTRACT_CHAIN_ELEMENT_INCLUDED
28
29#include <stddef.h>
30#include <atomic>
31#include <functional>
32
38#include "my_inttypes.h"
39
40namespace Mysql {
41namespace Tools {
42namespace Dump {
43
45 public virtual Abstract_progress_reporter {
46 public:
47 /**
48 Returns an application unique ID of this chain element object. This helps
49 progress watching with multiple parts of chain during all objects
50 processing.
51 */
52 uint64 get_id() const override;
53
54 /** Disable move assignment to avoid Wvirtual-move-assign warning */
56
57 // Fix "inherits ... via dominance" warnings
59 I_progress_watcher *new_progress_watcher) override {
61 }
62
63 protected:
65 std::function<bool(const Mysql::Tools::Base::Message_data &)>
66 *message_handler,
67 Simple_id_generator *object_id_generator);
68
69 /**
70 Process task object with specified function if that task object can be
71 casted to type TType. Returns true if object was processed.
72 */
73 template <typename TType, typename TClass>
75 Item_processing_data *item_to_process,
76 void (TClass::*processing_func)(TType *, Item_processing_data *)) {
77 TType *casted_object =
78 dynamic_cast<TType *>(item_to_process->get_process_task_object());
79 if (casted_object != nullptr)
80 (((TClass *)this)->*processing_func)(casted_object, item_to_process);
81 return casted_object != nullptr;
82 }
83
84 /**
85 Process task object with specified function if that task object can be
86 casted to type TType. Returns true if object was processed.
87 */
88 template <typename TType, typename TClass>
90 void (TClass::*processing_func)(TType *)) {
91 TType *casted_object =
92 dynamic_cast<TType *>(item_to_process->get_process_task_object());
93 if (casted_object != nullptr)
94 (((TClass *)this)->*processing_func)(casted_object);
95 return casted_object != nullptr;
96 }
97
99
101 Item_processing_data *current_item_data,
102 I_chain_element *child_chain_element);
103
105
107 Chain_data *new_chain_data, Item_processing_data *parent_processing_data,
108 I_chain_element *child_chain_element);
109
111 Item_processing_data *current_item_data, I_dump_task *dump_task_created);
112
113 void object_processing_ends(Item_processing_data *processed_item);
114
116
118
119 /**
120 Passes message to message callback.
121 */
122 void pass_message(const Mysql::Tools::Base::Message_data &message_data);
123
124 std::function<bool(const Mysql::Tools::Base::Message_data &)>
125 *get_message_handler() const;
126
127 protected:
128 virtual bool need_callbacks_in_child();
129
130 // Must be protected to allow subclasses to call explicitly.
132 Item_processing_data *item_processed) override;
133
134 private:
135 /**
136 Wrapper on item_completion_in_child_callback which allows creation of
137 pointer to function which will then fetch correct virtual method pointer.
138 */
140 Item_processing_data *item_processed);
141 /**
142 Wrapper on item_completion_in_child_callback_wrapper which also sets
143 precessed task to be fully completed.
144 */
146 Item_processing_data *item_processed);
147
149 Item_processing_data *current_item_data,
150 I_chain_element *child_chain_element, I_dump_task *task_to_be_processed,
151 std::function<void(Item_processing_data *)> *callback);
152
154 std::function<bool(const Mysql::Tools::Base::Message_data &)>
157 std::function<void(Item_processing_data *)>
160
161 /**
162 Stores next chain element ID to be used. Used as ID generator.
163 */
164 static std::atomic<uint64_t> next_id;
165};
166
167} // namespace Dump
168} // namespace Tools
169} // namespace Mysql
170
171#endif
Structure to represent message from server sent after executing query.
Definition: message_data.h:49
Definition: abstract_chain_element.h:45
Abstract_chain_element(std::function< bool(const Mysql::Tools::Base::Message_data &)> *message_handler, Simple_id_generator *object_id_generator)
Definition: abstract_chain_element.cc:38
virtual bool need_callbacks_in_child()
Definition: abstract_chain_element.cc:135
void object_processing_starts(Item_processing_data *item_to_process)
Definition: abstract_chain_element.cc:53
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: abstract_chain_element.h:58
uint64 generate_new_object_id()
Definition: abstract_chain_element.cc:115
void item_completion_in_child_completes_task_callback(Item_processing_data *item_processed)
Wrapper on item_completion_in_child_callback_wrapper which also sets precessed task to be fully compl...
Definition: abstract_chain_element.cc:144
Abstract_chain_element & operator=(Abstract_chain_element &&other)=delete
Disable move assignment to avoid Wvirtual-move-assign warning.
void pass_message(const Mysql::Tools::Base::Message_data &message_data)
Passes message to message callback.
Definition: abstract_chain_element.cc:123
Item_processing_data * task_to_be_processed_in_child(Item_processing_data *current_item_data, I_chain_element *child_chain_element, I_dump_task *task_to_be_processed, std::function< void(Item_processing_data *)> *callback)
Definition: abstract_chain_element.cc:155
std::function< bool(const Mysql::Tools::Base::Message_data &)> * m_message_handler
Definition: abstract_chain_element.h:155
std::function< bool(const Mysql::Tools::Base::Message_data &)> * get_message_handler() const
Definition: abstract_chain_element.cc:131
uint64 m_id
Definition: abstract_chain_element.h:153
bool try_process_task(Item_processing_data *item_to_process, void(TClass::*processing_func)(TType *, Item_processing_data *))
Process task object with specified function if that task object can be casted to type TType.
Definition: abstract_chain_element.h:74
uint64 get_id() const override
Returns an application unique ID of this chain element object.
Definition: abstract_chain_element.cc:36
Item_processing_data * new_task_created(I_dump_task *dump_task_created)
Definition: abstract_chain_element.cc:71
std::function< void(Item_processing_data *)> m_item_processed_complete_callback
Definition: abstract_chain_element.h:158
void item_completion_in_child_callback_wrapper(Item_processing_data *item_processed)
Wrapper on item_completion_in_child_callback which allows creation of pointer to function which will ...
Definition: abstract_chain_element.cc:139
Item_processing_data * object_to_be_processed_in_child(Item_processing_data *current_item_data, I_chain_element *child_chain_element)
Definition: abstract_chain_element.cc:59
void object_processing_ends(Item_processing_data *processed_item)
Definition: abstract_chain_element.cc:105
std::function< void(Item_processing_data *)> m_item_processed_callback
Definition: abstract_chain_element.h:156
void item_completion_in_child_callback(Item_processing_data *item_processed) override
This callback can be requested to be called by child for any object processing.
Definition: abstract_chain_element.cc:150
Simple_id_generator * get_object_id_generator() const
Definition: abstract_chain_element.cc:119
bool try_process_task(Item_processing_data *item_to_process, void(TClass::*processing_func)(TType *))
Process task object with specified function if that task object can be casted to type TType.
Definition: abstract_chain_element.h:89
Simple_id_generator * m_object_id_generator
Definition: abstract_chain_element.h:159
Item_processing_data * new_chain_created(Chain_data *new_chain_data, Item_processing_data *parent_processing_data, I_chain_element *child_chain_element)
Definition: abstract_chain_element.cc:80
static std::atomic< uint64_t > next_id
Stores next chain element ID to be used.
Definition: abstract_chain_element.h:164
Definition: abstract_progress_reporter.h:38
void register_progress_watcher(I_progress_watcher *new_progress_watcher) override
Add new Progress Watcher to report to.
Definition: abstract_progress_reporter.cc:32
Definition: chain_data.h:35
Interface for all objects that can process data in any part of dump process.
Definition: i_chain_element.h:41
Interface for all individual dump process tasks.
Definition: i_dump_task.h:38
Definition: i_progress_watcher.h:37
Data structure for objects that are processed in any chain.
Definition: item_processing_data.h:43
I_dump_task * get_process_task_object() const
Definition: item_processing_data.cc:66
Definition: simple_id_generator.h:37
Some integer typedefs for easier portability.
uint64_t uint64
Definition: my_inttypes.h:69
Definition: abstract_connection_program.h:38