MySQL 9.1.0
Source Code Documentation
service_srv_session.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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#ifndef MYSQL_SRV_SESSION_SERVICE_INCLUDED
24#define MYSQL_SRV_SESSION_SERVICE_INCLUDED
25
26/**
27 @file include/mysql/service_srv_session.h
28 Header file for the Server session service. This service is to provide
29 of creating sessions with the server. These sessions can be furtherly used
30 together with the Command service to execute commands in the server.
31
32 @note Session should not be used after being closed, unless MYSQL_SESSION
33 handle is set to NULL.
34*/
35
36#include "mysql/service_srv_session_bits.h" /* MYSQL_SESSION, srv_session_error_cb */
37
38#ifndef MYSQL_ABI_CHECK
39#include "mysql/plugin.h" /* MYSQL_THD */
40#endif
41
42extern "C" struct srv_session_service_st {
43 int (*init_session_thread)(const void *plugin);
44
46
47 MYSQL_SESSION(*open_session)
49
51
53
55
56 int (*attach_session)(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd);
58
59#ifdef MYSQL_DYNAMIC_PLUGIN
60
61#define srv_session_init_thread(plugin) \
62 srv_session_service->init_session_thread((plugin))
63
64#define srv_session_deinit_thread() srv_session_service->deinit_session_thread()
65
66#define srv_session_open(cb, ctx) srv_session_service->open_session((cb), (ctx))
67
68#define srv_session_detach(session) \
69 srv_session_service->detach_session((session))
70
71#define srv_session_close(session) srv_session_service->close_session((session))
72
73#define srv_session_server_is_available() \
74 srv_session_service->server_is_available()
75
76#define srv_session_attach(session, thd) \
77 srv_session_service->attach_session((session), (thd))
78
79#else
80
81/**
82 Initializes the current physical thread to use with session service.
83
84 Call this function ONLY in physical threads which are not initialized in
85 any way by the server.
86
87 @param plugin Pointer to the plugin structure, passed to the plugin over
88 the plugin init function.
89
90 @return
91 0 success
92 1 failure
93*/
94int srv_session_init_thread(const void *plugin);
95
96/**
97 Deinitializes the current physical thread to use with session service.
98
99
100 Call this function ONLY in physical threads which were initialized using
101 srv_session_init_thread().
102*/
104
105/**
106 Opens a server session.
107
108 In a thread not initialized by the server itself, this function should be
109 called only after srv_session_init_thread() has already been called.
110
111 @param error_cb session error callback
112 @param plugin_ctx Plugin's context, opaque pointer that would
113 be provided to callbacks. Might be NULL.
114 @return
115 session on success
116 NULL on failure
117*/
118MYSQL_SESSION srv_session_open(srv_session_error_cb error_cb, void *plugin_ctx);
119
120/**
121 Detaches a session from current physical thread.
122
123 Detaches a previously session. Which can only occur when the MYSQL_SESSION
124 was manually attached by "srv_session_attach".
125 Other srv_session calls automatically attached/detached the THD when the
126 MYSQL_SESSION is used (for example command_service_run_command()).
127
128 @param session Session to detach
129
130 @returns
131 0 success
132 1 failure
133*/
135
136/**
137 Closes a previously opened session.
138
139 @param session Session to close
140
141 @note This method close the session but session handle is not set to NULL.
142 Session handle should be set to NULL explicitly after calling this
143 method. Session should not be used otherwise.
144
145 @return
146 0 success
147 1 failure
148*/
150
151/**
152 Returns if the server is available (not booting or shutting down)
153
154 @return
155 0 not available
156 1 available
157*/
159
160/**
161 Attaches a session to current physical thread.
162
163 Previously attached THD is detached and returned through ret_previous_thd.
164 THD associated with session is attached.
165
166 @param session Session to attach
167 @param ret_previous_thd Previously attached THD
168
169 @returns
170 0 success
171 1 failure
172*/
173int srv_session_attach(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd);
174
175#endif
176
177#endif /* MYSQL_SRV_SESSION_SERVICE_INCLUDED */
#define MYSQL_THD
Definition: backup_page_tracker.h:38
int srv_session_init_thread(const void *plugin)
Initializes the current physical thread to use with session service.
Definition: srv_session_service.cc:60
struct srv_session_service_st * srv_session_service
int srv_session_attach(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd)
Attaches a session to current physical thread.
Definition: srv_session_service.cc:233
void srv_session_deinit_thread()
Deinitializes the current physical thread to use with session service.
Definition: srv_session_service.cc:67
int srv_session_server_is_available()
Returns if the server is available (not booting or shutting down)
Definition: srv_session_service.cc:222
int srv_session_close(MYSQL_SESSION session)
Closes a previously opened session.
MYSQL_SESSION srv_session_open(srv_session_error_cb error_cb, void *plugin_ctx)
Opens a server session.
Definition: srv_session_service.cc:146
int srv_session_detach(MYSQL_SESSION session)
Detaches a session from current physical thread.
These are the common definitions between the plugin service for sessions and the component service ex...
class Srv_session * MYSQL_SESSION
Definition: service_srv_session_bits.h:37
void(* srv_session_error_cb)(void *ctx, unsigned int sql_errno, const char *err_msg)
Definition: service_srv_session_bits.h:43
Definition: service_srv_session.h:42
srv_session_error_cb void * plugix_ctx
Definition: service_srv_session.h:48
srv_session_error_cb error_cb
Definition: service_srv_session.h:48
int(* attach_session)(MYSQL_SESSION session, MYSQL_THD *ret_previous_thd)
Definition: service_srv_session.h:56
int(* server_is_available)()
Definition: service_srv_session.h:54
void(* deinit_session_thread)()
Definition: service_srv_session.h:45
int(* init_session_thread)(const void *plugin)
Definition: service_srv_session.h:43
int(* close_session)(MYSQL_SESSION session)
Definition: service_srv_session.h:52
int(* detach_session)(MYSQL_SESSION session)
Definition: service_srv_session.h:50