MySQL 8.3.0
Source Code Documentation
pfs_example_machine.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, 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 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 */
31extern SERVICE_TYPE(pfs_plugin_column_integer_v1) * col_int_svc;
32extern SERVICE_TYPE(pfs_plugin_column_enum_v1) * col_enum_svc;
33extern SERVICE_TYPE(pfs_plugin_column_string_v2) * col_string_svc;
34
35/* Global share pointer for pfs_example_employee_salary table */
37
38/* A mutex instance to protect:
39 * - machine_rows_in_table
40 * - next_available_index
41 * - machine_records_array
42 */
44
45enum machine_type_enum { LAPTOP = 1, DESKTOP = 2, MOBILE = 3, TYPE_END = 4 };
46
47/* Number of characters * max multibyte length */
48#define MACHINE_MADE_LEN 20 * 4
49
50/* A structure to denote a single row of the table. */
52 public:
56 unsigned int machine_made_length;
58
59 /* If there is a value in this row */
60 bool m_exist;
61};
62
63/**
64 * An array to keep rows of the tables.
65 * When a row is inserted in plugin table, it will be stored here.
66 * When a row is queried from plugin table, it will be fetched from here.
67 */
68extern std::vector<Machine_Record> machine_records_vector;
69
70/* A class to define position of cursor in table. */
72 private:
73 unsigned int m_index;
74
75 public:
76 ~Machine_POS() = default;
78
79 bool has_more() {
80 if (m_index < machine_records_vector.size()) return true;
81 return false;
82 }
83 void next() { m_index++; }
84
85 void reset() { m_index = 0; }
86
87 unsigned int get_index() { return m_index; }
88
89 void set_at(unsigned int index) { m_index = index; }
90
91 void set_at(Machine_POS *pos) { m_index = pos->m_index; }
92
93 void set_after(Machine_POS *pos) { m_index = pos->m_index + 1; }
94};
95
96/* A structure to define a handle for table in plugin/component code. */
98 /* Current position instance */
100 /* Next position instance */
102
103 /* Current row for the table */
105};
106
110int machine_rnd_init(PSI_table_handle *h, bool scan);
112int machine_index_init(PSI_table_handle *handle, uint idx, bool sorted,
113 PSI_index_handle **index);
115 unsigned int idx, int find_flag);
119 uint index);
122 unsigned int index);
125 unsigned int index);
128unsigned long long machine_get_row_count(void);
130
131#endif /* PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_MACHINE_H_ */
Definition: pfs_example_machine.h:71
void set_at(unsigned int index)
Definition: pfs_example_machine.h:89
~Machine_POS()=default
void reset()
Definition: pfs_example_machine.h:85
unsigned int get_index()
Definition: pfs_example_machine.h:87
unsigned int m_index
Definition: pfs_example_machine.h:73
bool has_more()
Definition: pfs_example_machine.h:79
void set_at(Machine_POS *pos)
Definition: pfs_example_machine.h:91
Machine_POS()
Definition: pfs_example_machine.h:77
void next()
Definition: pfs_example_machine.h:83
void set_after(Machine_POS *pos)
Definition: pfs_example_machine.h:93
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:63
void machine_reset_position(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:127
std::vector< Machine_Record > machine_records_vector
An array to keep rows of the tables.
Definition: pfs_example_machine.cc:33
void init_machine_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_machine.cc:288
const mysql_service_pfs_plugin_column_enum_v1_t * col_enum_svc
Definition: pfs_example_plugin_employee.cc:99
int machine_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_machine.cc:233
int machine_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:162
PFS_engine_table_share_proxy machine_st_share
Definition: pfs_example_machine.cc:27
int machine_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:70
const mysql_service_pfs_plugin_column_integer_v1_t * col_int_svc
Definition: pfs_example_plugin_employee.cc:89
int machine_rnd_pos(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:91
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
const mysql_service_pfs_plugin_column_string_v2_t * col_string_svc
Definition: pfs_example_plugin_employee.cc:91
int machine_index_init(PSI_table_handle *handle, uint idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_machine.cc:104
machine_type_enum
Definition: pfs_example_machine.h:45
@ LAPTOP
Definition: pfs_example_machine.h:45
@ DESKTOP
Definition: pfs_example_machine.h:45
@ TYPE_END
Definition: pfs_example_machine.h:45
@ MOBILE
Definition: pfs_example_machine.h:45
int machine_read_column_value(PSI_table_handle *handle, PSI_field *field, uint index)
Definition: pfs_example_machine.cc:135
int machine_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_machine.cc:86
mysql_mutex_t LOCK_machine_records_array
Definition: pfs_example_machine.cc:28
unsigned long long machine_get_row_count(void)
Definition: pfs_example_machine.cc:286
int machine_delete_all_rows(void)
Definition: pfs_example_machine.cc:278
int machine_index_next(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:121
int machine_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:219
int machine_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_machine.cc:263
#define MACHINE_MADE_LEN
Definition: pfs_example_machine.h:48
int machine_index_read(PSI_index_handle *index, PSI_key_reader *reader, unsigned int idx, int find_flag)
Definition: pfs_example_machine.cc:112
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
int machine_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_machine.cc:189
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
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
#define PSI_int
Definition: pfs_plugin_table_service.h:147
#define PSI_enum
Definition: pfs_plugin_table_service.h:152
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
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
struct PSI_field PSI_field
This is an opaque structure to denote filed in plugin/component code.
Definition: pfs_plugin_table_service.h:92
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:75
Specifies macros to define Service Implementations.
Definition: pfs_example_machine.h:51
PSI_int employee_number
Definition: pfs_example_machine.h:57
PSI_enum machine_type
Definition: pfs_example_machine.h:54
bool m_exist
Definition: pfs_example_machine.h:60
PSI_int machine_number
Definition: pfs_example_machine.h:53
char machine_made[MACHINE_MADE_LEN]
Definition: pfs_example_machine.h:55
unsigned int machine_made_length
Definition: pfs_example_machine.h:56
Definition: pfs_example_machine.h:97
Machine_Record current_row
Definition: pfs_example_machine.h:104
Machine_POS m_pos
Definition: pfs_example_machine.h:99
Machine_POS m_next_pos
Definition: pfs_example_machine.h:101
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:461
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49