service_srv_session.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef MYSQL_SRV_SESSION_SERVICE_INCLUDED
  19. #define MYSQL_SRV_SESSION_SERVICE_INCLUDED
  20. /**
  21. @file
  22. Header file for the Server session service. This service is to provide
  23. of creating sessions with the server. These sessions can be furtherly used
  24. together with the Command service to execute commands in the server.
  25. */
  26. #ifdef __cplusplus
  27. class Srv_session;
  28. typedef class Srv_session* MYSQL_SESSION;
  29. #else
  30. struct Srv_session;
  31. typedef struct Srv_session* MYSQL_SESSION;
  32. #endif
  33. #ifndef MYSQL_ABI_CHECK
  34. #include "mysql/plugin.h" /* MYSQL_THD */
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. typedef void (*srv_session_error_cb)(void *ctx,
  40. unsigned int sql_errno,
  41. const char *err_msg);
  42. extern struct srv_session_service_st
  43. {
  44. int (*init_session_thread)(const void *plugin);
  45. void (*deinit_session_thread)();
  46. MYSQL_SESSION (*open_session)(srv_session_error_cb error_cb,
  47. void *plugix_ctx);
  48. int (*detach_session)(MYSQL_SESSION session);
  49. int (*close_session)(MYSQL_SESSION session);
  50. int (*server_is_available)();
  51. } *srv_session_service;
  52. #ifdef MYSQL_DYNAMIC_PLUGIN
  53. #define srv_session_init_thread(plugin) \
  54. srv_session_service->init_session_thread((plugin))
  55. #define srv_session_deinit_thread() \
  56. srv_session_service->deinit_session_thread()
  57. #define srv_session_open(cb, ctx) \
  58. srv_session_service->open_session((cb), (ctx))
  59. #define srv_session_detach(session) \
  60. srv_session_service->detach_session((session))
  61. #define srv_session_close(session) \
  62. srv_session_service->close_session((session))
  63. #define srv_session_server_is_available() \
  64. srv_session_service->server_is_available()
  65. #else
  66. /**
  67. Initializes the current physical thread to use with session service.
  68. Call this function ONLY in physical threads which are not initialized in
  69. any way by the server.
  70. @param plugin Pointer to the plugin structure, passed to the plugin over
  71. the plugin init function.
  72. @return
  73. 0 success
  74. 1 failure
  75. */
  76. int srv_session_init_thread(const void *plugin);
  77. /**
  78. Deinitializes the current physical thread to use with session service.
  79. Call this function ONLY in physical threads which were initialized using
  80. srv_session_init_thread().
  81. */
  82. void srv_session_deinit_thread();
  83. /**
  84. Opens a server session.
  85. In a thread not initialized by the server itself, this function should be
  86. called only after srv_session_init_thread() has already been called.
  87. @param error_cb Default completion callback
  88. @param plugin_ctx Plugin's context, opaque pointer that would
  89. be provided to callbacks. Might be NULL.
  90. @return
  91. session on success
  92. NULL on failure
  93. */
  94. MYSQL_SESSION srv_session_open(srv_session_error_cb cb, void *plugix_ctx);
  95. /**
  96. Detaches a session from current physical thread.
  97. Detaches a previously attached session. Sessions are automatically attached
  98. when they are used with the Command service (command_service_run_command()).
  99. If the session is opened in a spawned thread, then it will stay attached
  100. after command_service_run_command() until another session is used in the
  101. same physical thread. The command services will detach the previously used
  102. session and attach the one to be used for execution.
  103. This function should be called in case the session has to be used in
  104. different physical thread. It will unbound the session from the current
  105. physical thread. After that the session can be used in a different thread.
  106. @param session Session to detach
  107. @returns
  108. 0 success
  109. 1 failure
  110. */
  111. int srv_session_detach(MYSQL_SESSION session);
  112. /**
  113. Closes a previously opened session.
  114. @param session Session to close
  115. @return
  116. 0 success
  117. 1 failure
  118. */
  119. int srv_session_close(MYSQL_SESSION session);
  120. /**
  121. Returns if the server is available (not booting or shutting down)
  122. @return
  123. 0 not available
  124. 1 available
  125. */
  126. int srv_session_server_is_available();
  127. #endif
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif /* MYSQL_SRV_SESSION_SERVICE_INCLUDED */