File: abstract_chain_element.h

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (171 lines) | stat: -rw-r--r-- 6,154 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
  Copyright (c) 2015, 2025, Oracle and/or its affiliates.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2.0,
  as published by the Free Software Foundation.

  This program is designed to work with certain software (including
  but not limited to OpenSSL) that is licensed under separate terms,
  as designated in a particular file or component or in included license
  documentation.  The authors of MySQL hereby grant you an additional
  permission to link the program and your derivative works with the
  separately licensed software that they have either included with
  the program or referenced in the documentation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License, version 2.0, for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
*/

#ifndef ABSTRACT_CHAIN_ELEMENT_INCLUDED
#define ABSTRACT_CHAIN_ELEMENT_INCLUDED

#include <stddef.h>
#include <atomic>
#include <functional>

#include "client/base/message_data.h"
#include "client/dump/abstract_progress_reporter.h"
#include "client/dump/i_chain_element.h"
#include "client/dump/item_processing_data.h"
#include "client/dump/simple_id_generator.h"
#include "my_inttypes.h"

namespace Mysql {
namespace Tools {
namespace Dump {

class Abstract_chain_element : public virtual I_chain_element,
                               public virtual Abstract_progress_reporter {
 public:
  /**
    Returns an application unique ID of this chain element object. This helps
    progress watching with multiple parts of chain during all objects
    processing.
   */
  uint64 get_id() const override;

  /** Disable move assignment to avoid Wvirtual-move-assign warning */
  Abstract_chain_element &operator=(Abstract_chain_element &&other) = delete;

  // Fix "inherits ... via dominance" warnings
  void register_progress_watcher(
      I_progress_watcher *new_progress_watcher) override {
    Abstract_progress_reporter::register_progress_watcher(new_progress_watcher);
  }

 protected:
  Abstract_chain_element(
      std::function<bool(const Mysql::Tools::Base::Message_data &)>
          *message_handler,
      Simple_id_generator *object_id_generator);

  /**
    Process task object with specified function if that task object can be
    casted to type TType. Returns true if object was processed.
   */
  template <typename TType, typename TClass>
  bool try_process_task(
      Item_processing_data *item_to_process,
      void (TClass::*processing_func)(TType *, Item_processing_data *)) {
    TType *casted_object =
        dynamic_cast<TType *>(item_to_process->get_process_task_object());
    if (casted_object != nullptr)
      (((TClass *)this)->*processing_func)(casted_object, item_to_process);
    return casted_object != nullptr;
  }

  /**
    Process task object with specified function if that task object can be
    casted to type TType. Returns true if object was processed.
   */
  template <typename TType, typename TClass>
  bool try_process_task(Item_processing_data *item_to_process,
                        void (TClass::*processing_func)(TType *)) {
    TType *casted_object =
        dynamic_cast<TType *>(item_to_process->get_process_task_object());
    if (casted_object != nullptr)
      (((TClass *)this)->*processing_func)(casted_object);
    return casted_object != nullptr;
  }

  void object_processing_starts(Item_processing_data *item_to_process);

  Item_processing_data *object_to_be_processed_in_child(
      Item_processing_data *current_item_data,
      I_chain_element *child_chain_element);

  Item_processing_data *new_task_created(I_dump_task *dump_task_created);

  Item_processing_data *new_chain_created(
      Chain_data *new_chain_data, Item_processing_data *parent_processing_data,
      I_chain_element *child_chain_element);

  Item_processing_data *new_chain_created(
      Item_processing_data *current_item_data, I_dump_task *dump_task_created);

  void object_processing_ends(Item_processing_data *processed_item);

  uint64 generate_new_object_id();

  Simple_id_generator *get_object_id_generator() const;

  /**
    Passes message to message callback.
   */
  void pass_message(const Mysql::Tools::Base::Message_data &message_data);

  std::function<bool(const Mysql::Tools::Base::Message_data &)>
      *get_message_handler() const;

 protected:
  virtual bool need_callbacks_in_child();

  // Must be protected to allow subclasses to call explicitly.
  void item_completion_in_child_callback(
      Item_processing_data *item_processed) override;

 private:
  /**
    Wrapper on item_completion_in_child_callback which allows creation of
    pointer to function which will then fetch correct virtual method pointer.
   */
  void item_completion_in_child_callback_wrapper(
      Item_processing_data *item_processed);
  /**
    Wrapper on item_completion_in_child_callback_wrapper which also sets
    precessed task to be fully completed.
   */
  void item_completion_in_child_completes_task_callback(
      Item_processing_data *item_processed);

  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);

  uint64 m_id;
  std::function<bool(const Mysql::Tools::Base::Message_data &)>
      *m_message_handler;
  std::function<void(Item_processing_data *)> m_item_processed_callback;
  std::function<void(Item_processing_data *)>
      m_item_processed_complete_callback;
  Simple_id_generator *m_object_id_generator;

  /**
    Stores next chain element ID to be used. Used as ID generator.
   */
  static std::atomic<uint64_t> next_id;
};

}  // namespace Dump
}  // namespace Tools
}  // namespace Mysql

#endif