MySQL  8.0.19
Source Code Documentation
pfs_example_machine.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_MACHINE_H_
24 #define PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_MACHINE_H_
25 
28 #include <mysql/plugin.h>
29 
30 /* Service handle */
31 extern SERVICE_TYPE(pfs_plugin_table) * table_svc;
32 
33 /* Global share pointer for pfs_example_employee_salary table */
35 
36 /* A mutex instance to protect:
37  * - machine_rows_in_table
38  * - next_available_index
39  * - machine_records_array
40  */
42 
43 enum machine_type_enum { LAPTOP = 1, DESKTOP = 2, MOBILE = 3, TYPE_END = 4 };
44 
45 /* A structure to denote a single row of the table. */
46 struct {
47  public:
50  char machine_made[20];
51  unsigned int machine_made_length;
53 
54  /* If there is a value in this row */
55  bool m_exist;
56 } typedef Machine_Record;
57 
58 /**
59  * An array to keep rows of the tables.
60  * When a row is inserted in plugin table, it will be stored here.
61  * When a row is queried from plugin table, it will be fetched from here.
62  */
63 extern std::vector<Machine_Record> machine_records_vector;
64 
65 /* A class to define position of cursor in table. */
66 class Machine_POS {
67  private:
68  unsigned int m_index;
69 
70  public:
72  Machine_POS() { m_index = 0; }
73 
74  bool has_more() {
75  if (m_index < machine_records_vector.size()) return true;
76  return false;
77  }
78  void next() { m_index++; }
79 
80  void reset() { m_index = 0; }
81 
82  unsigned int get_index() { return m_index; }
83 
84  void set_at(unsigned int index) { m_index = index; }
85 
86  void set_at(Machine_POS *pos) { m_index = pos->m_index; }
87 
88  void set_after(Machine_POS *pos) { m_index = pos->m_index + 1; }
89 };
90 
91 /* A structure to define a handle for table in plugin/component code. */
92 typedef struct {
93  /* Current position instance */
95  /* Next position instance */
97 
98  /* Current row for the table */
101 
105 int machine_rnd_init(PSI_table_handle *h, bool scan);
107 int machine_index_init(PSI_table_handle *handle, uint idx, bool sorted,
110  unsigned int idx, int find_flag);
114  uint index);
117  unsigned int index);
120  unsigned int index);
122 int machine_delete_all_rows(void);
123 unsigned long long machine_get_row_count(void);
125 
126 #endif /* PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_MACHINE_H_ */
Machine_Table_Handle::m_next_pos
Machine_POS m_next_pos
Definition: pfs_example_machine.h:96
Machine_Record::m_exist
bool m_exist
Definition: pfs_example_machine.h:55
Machine_POS::~Machine_POS
~Machine_POS()
Definition: pfs_example_machine.h:71
machine_rnd_next
int machine_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:70
Machine_POS::m_index
unsigned int m_index
Definition: pfs_example_machine.h:68
Machine_Record
Definition: pfs_example_machine.h:46
machine_update_column_value
int machine_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_machine.cc:233
Machine_Record::employee_number
PSI_int employee_number
Definition: pfs_example_machine.h:52
pos
char * pos
Definition: do_ctype.cc:76
machine_index_read
int machine_index_read(PSI_index_handle *index, PSI_key_reader *reader, unsigned int idx, int find_flag)
Definition: pfs_example_machine.cc:113
handle
void * handle
Definition: engine_loader.c:19
table_svc
const mysql_service_pfs_plugin_table_t * table_svc
Definition: pfs_example_plugin_employee.cc:87
mysql_mutex_t
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
MOBILE
@ MOBILE
Definition: pfs_example_machine.h:43
Machine_POS::get_index
unsigned int get_index()
Definition: pfs_example_machine.h:82
machine_get_row_count
unsigned long long machine_get_row_count(void)
Definition: pfs_example_machine.cc:285
machine_records_vector
std::vector< Machine_Record > machine_records_vector
An array to keep rows of the tables.
Definition: pfs_example_machine.cc:33
PSI_enum
#define PSI_enum
Definition: pfs_plugin_table_service.h:152
machine_rnd_pos
int machine_rnd_pos(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:91
machine_rnd_init
int machine_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_machine.cc:86
DESKTOP
@ DESKTOP
Definition: pfs_example_machine.h:43
Machine_POS::Machine_POS
Machine_POS()
Definition: pfs_example_machine.h:72
pfs_plugin_table_service.h
machine_delete_all_rows
int machine_delete_all_rows(void)
Definition: pfs_example_machine.cc:277
machine_update_row_values
int machine_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:219
Machine_POS::set_after
void set_after(Machine_POS *pos)
Definition: pfs_example_machine.h:88
Machine_Record::machine_type
PSI_enum machine_type
Definition: pfs_example_machine.h:49
PSI_field
struct PSI_field PSI_field
This is an opaque structure to denote filed in plugin/component code.
Definition: pfs_plugin_table_service.h:92
plugin.h
PSI_index_handle
struct PSI_index_handle PSI_index_handle
This is an opaque structure to denote Index Handle in plugin/component code.
Definition: pfs_plugin_table_service.h:109
LAPTOP
@ LAPTOP
Definition: pfs_example_machine.h:43
machine_write_column_value
int machine_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_machine.cc:190
LOCK_machine_records_array
mysql_mutex_t LOCK_machine_records_array
Definition: pfs_example_machine.cc:28
uint
unsigned int uint
Definition: uca-dump.cc:29
machine_index_next
int machine_index_next(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:122
machine_index_init
int machine_index_init(PSI_table_handle *handle, uint idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_machine.cc:104
Machine_POS
Definition: pfs_example_machine.h:66
Machine_POS::next
void next()
Definition: pfs_example_machine.h:78
Machine_Table_Handle::m_pos
Machine_POS m_pos
Definition: pfs_example_machine.h:94
machine_write_row_values
int machine_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:163
SERVICE_TYPE
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:75
TYPE_END
@ TYPE_END
Definition: pfs_example_machine.h:43
PSI_int
#define PSI_int
Definition: pfs_plugin_table_service.h:147
machine_st_share
PFS_engine_table_share_proxy machine_st_share
Definition: pfs_example_machine.cc:27
PFS_engine_table_share_proxy
A share to be initialized by plugin/component code and to be provided to add_table() service method o...
Definition: pfs_plugin_table_service.h:443
machine_read_column_value
int machine_read_column_value(PSI_table_handle *handle, PSI_field *field, uint index)
Definition: pfs_example_machine.cc:136
PSI_table_handle
struct PSI_table_handle PSI_table_handle
This is an opaque structure to denote table handle in plugin/component code.
Definition: pfs_plugin_table_service.h:96
Machine_POS::reset
void reset()
Definition: pfs_example_machine.h:80
machine_reset_position
void machine_reset_position(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:128
Machine_Record::machine_number
PSI_int machine_number
Definition: pfs_example_machine.h:48
Machine_Table_Handle
Definition: pfs_example_machine.h:92
Machine_Record::machine_made_length
unsigned int machine_made_length
Definition: pfs_example_machine.h:51
Machine_POS::set_at
void set_at(unsigned int index)
Definition: pfs_example_machine.h:84
Machine_Table_Handle::current_row
Machine_Record current_row
Definition: pfs_example_machine.h:99
machine_close_table
void machine_close_table(PSI_table_handle *handle)
Destroy the Machine_Table_Handle at plugin code when corresponding table in performance schema is clo...
Definition: pfs_example_machine.cc:54
machine_open_table
PSI_table_handle * machine_open_table(PSI_pos **pos)
Instantiate Machine_Table_Handle at plugin code when corresponding table in performance schema is ope...
Definition: pfs_example_machine.cc:39
PSI_pos
struct PSI_pos PSI_pos
This is an opaque structure to denote cursor position in plugin/component code.
Definition: pfs_plugin_table_service.h:101
machine_delete_row_values
int machine_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:262
PSI_key_reader
struct PSI_key_reader PSI_key_reader
This is an opaque structure to denote Key Reader in plugin/component code.
Definition: pfs_plugin_table_service.h:105
Machine_POS::has_more
bool has_more()
Definition: pfs_example_machine.h:74
machine_type_enum
machine_type_enum
Definition: pfs_example_machine.h:43
index
char * index(const char *, int c)
Definition: mysql.cc:2875
service_implementation.h
init_machine_share
void init_machine_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_machine.cc:287
Machine_POS::set_at
void set_at(Machine_POS *pos)
Definition: pfs_example_machine.h:86