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