service_srv_session_info.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef MYSQL_SERVICE_SRV_SESSION_INFO_INCLUDED
  2. #define MYSQL_SERVICE_SRV_SESSION_INFO_INCLUDED
  3. /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License, version 2.0,
  6. as published by the Free Software Foundation.
  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. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License, version 2.0, for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  20. /**
  21. @file
  22. Service providing setters and getters for some properties of a session
  23. */
  24. #include "mysql/service_srv_session.h"
  25. #ifndef MYSQL_ABI_CHECK
  26. #include "my_thread.h" /* my_thread_id */
  27. #include "m_string.h" /* LEX_CSTRING */
  28. #include "plugin.h" /* MYSQL_THD */
  29. #include "mysql_com.h" /* Vio for violite.h */
  30. #include "violite.h" /* enum_vio_type */
  31. #include <stdint.h> /* uint16_t */
  32. #endif
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. extern struct srv_session_info_service_st {
  37. MYSQL_THD (*get_thd)(MYSQL_SESSION session);
  38. my_thread_id (*get_session_id)(MYSQL_SESSION session);
  39. LEX_CSTRING (*get_current_db)(MYSQL_SESSION session);
  40. uint16_t (*get_client_port)(MYSQL_SESSION session);
  41. int (*set_client_port)(MYSQL_SESSION session, uint16_t port);
  42. int (*set_connection_type)(MYSQL_SESSION session, enum enum_vio_type type);
  43. int (*killed)(MYSQL_SESSION session);
  44. unsigned int (*session_count)();
  45. unsigned int (*thread_count)(const void *plugin);
  46. } *srv_session_info_service;
  47. #ifdef MYSQL_DYNAMIC_PLUGIN
  48. #define srv_session_info_get_thd(session) srv_session_info_service->get_thd((session))
  49. #define srv_session_info_get_session_id(sess) srv_session_info_service->get_session_id((sess))
  50. #define srv_session_info_get_current_db(sess) srv_session_info_service->get_current_db((sess))
  51. #define srv_session_info_get_client_port(sess) srv_session_info_service->get_client_port((sess))
  52. #define srv_session_info_set_client_port(sess, port) srv_session_info_service->set_client_port((sess), (port))
  53. #define srv_session_info_set_connection_type(sess, type) srv_session_info_service->set_connection_type((sess), (type))
  54. #define srv_session_info_killed(sess) srv_session_info_service->killed((sess))
  55. #define srv_session_info_session_count(sess) srv_session_info_service->session_count(sess)
  56. #define srv_session_info_thread_count(plugin) srv_session_info_service->thread_count(plugin)
  57. #else
  58. /**
  59. Returns the THD of a session.
  60. @param session Session
  61. @returns
  62. address of the THD
  63. */
  64. MYSQL_THD srv_session_info_get_thd(MYSQL_SESSION session);
  65. /**
  66. Returns the ID of a session.
  67. @param session Session
  68. */
  69. my_thread_id srv_session_info_get_session_id(MYSQL_SESSION session);
  70. /**
  71. Returns the current database of a session.
  72. @note {NULL, 0} is returned case of no current database or session is NULL
  73. @param session Session
  74. */
  75. LEX_CSTRING srv_session_info_get_current_db(MYSQL_SESSION session);
  76. /**
  77. Returns the client port of a session.
  78. @note The client port in SHOW PROCESSLIST, INFORMATION_SCHEMA.PROCESSLIST.
  79. This port is NOT shown in PERFORMANCE_SCHEMA.THREADS.
  80. @param session Session
  81. */
  82. uint16_t srv_session_info_get_client_port(MYSQL_SESSION session);
  83. /**
  84. Sets the client port of a session.
  85. @note The client port in SHOW PROCESSLIST, INFORMATION_SCHEMA.PROCESSLIST.
  86. This port is NOT shown in PERFORMANCE_SCHEMA.THREADS.
  87. @param session Session
  88. @param port Port number
  89. @return
  90. 0 success
  91. 1 failure
  92. */
  93. int srv_session_info_set_client_port(MYSQL_SESSION session, uint16_t port);
  94. /**
  95. Sets the connection type of a session.
  96. @see enum_vio_type
  97. @note The type is shown in PERFORMANCE_SCHEMA.THREADS. The value is translated
  98. from the enum to a string according to @see vio_type_names array
  99. in vio/vio.c
  100. @note If NO_VIO_TYPE passed as type the call will fail.
  101. @return
  102. 0 success
  103. 1 failure
  104. */
  105. int srv_session_info_set_connection_type(MYSQL_SESSION session,
  106. enum enum_vio_type type);
  107. /**
  108. Returns whether the session was killed
  109. @param session Session
  110. @return
  111. 0 not killed
  112. 1 killed
  113. */
  114. int srv_session_info_killed(MYSQL_SESSION session);
  115. /**
  116. Returns the number opened sessions in thread initialized by srv_session
  117. service.
  118. */
  119. unsigned int srv_session_info_session_count();
  120. /**
  121. Returns the number opened sessions in thread initialized by srv_session
  122. service.
  123. @param plugin Pointer to the plugin structure, passed to the plugin over
  124. the plugin init function.
  125. */
  126. unsigned int srv_session_info_thread_count(const void *plugin);
  127. #endif /* MYSQL_DYNAMIC_PLUGIN */
  128. #ifdef __cplusplus
  129. } /* extern "C" */
  130. #endif
  131. #endif /* MYSQL_SERVICE_SRV_SESSION_INFO_INCLUDED */