sql_plugin_ref.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright (c) 2015, 2017, 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 SQL_PLUGIN_REF_INCLUDED
  19. #define SQL_PLUGIN_REF_INCLUDED
  20. #include "lex_string.h"
  21. #include "my_alloc.h"
  22. #include "mysql/mysql_lex_string.h"
  23. #include "prealloced_array.h"
  24. class sys_var;
  25. struct st_mysql_plugin;
  26. struct st_plugin_dl;
  27. enum enum_plugin_load_option {
  28. PLUGIN_OFF,
  29. PLUGIN_ON,
  30. PLUGIN_FORCE,
  31. PLUGIN_FORCE_PLUS_PERMANENT
  32. };
  33. /* A handle of a plugin */
  34. struct st_plugin_int {
  35. LEX_STRING name{nullptr, 0};
  36. st_mysql_plugin *plugin{nullptr};
  37. st_plugin_dl *plugin_dl{nullptr};
  38. uint state{0};
  39. uint ref_count{0}; /* number of threads using the plugin */
  40. void *data{nullptr}; /* plugin type specific, e.g. handlerton */
  41. MEM_ROOT mem_root; /* memory for dynamic plugin structures */
  42. sys_var *system_vars{nullptr}; /* server variables for this plugin */
  43. enum_plugin_load_option load_option{
  44. PLUGIN_OFF}; /* OFF, ON, FORCE, F+PERMANENT */
  45. };
  46. /*
  47. See intern_plugin_lock() for the explanation for the
  48. conditionally defined plugin_ref type
  49. */
  50. #ifdef DBUG_OFF
  51. typedef struct st_plugin_int *plugin_ref;
  52. inline st_mysql_plugin *plugin_decl(st_plugin_int *ref) { return ref->plugin; }
  53. inline st_plugin_dl *plugin_dlib(st_plugin_int *ref) { return ref->plugin_dl; }
  54. template <typename T>
  55. inline T plugin_data(st_plugin_int *ref) {
  56. return static_cast<T>(ref->data);
  57. }
  58. inline LEX_STRING *plugin_name(st_plugin_int *ref) { return &(ref->name); }
  59. inline uint plugin_state(st_plugin_int *ref) { return ref->state; }
  60. inline enum_plugin_load_option plugin_load_option(st_plugin_int *ref) {
  61. return ref->load_option;
  62. }
  63. inline bool plugin_equals(st_plugin_int *ref1, st_plugin_int *ref2) {
  64. return ref1 == ref2;
  65. }
  66. #else
  67. typedef struct st_plugin_int **plugin_ref;
  68. inline st_mysql_plugin *plugin_decl(st_plugin_int **ref) {
  69. return ref[0]->plugin;
  70. }
  71. inline st_plugin_dl *plugin_dlib(st_plugin_int **ref) {
  72. return ref[0]->plugin_dl;
  73. }
  74. template <typename T>
  75. inline T plugin_data(st_plugin_int **ref) {
  76. return static_cast<T>(ref[0]->data);
  77. }
  78. inline LEX_STRING *plugin_name(st_plugin_int **ref) { return &(ref[0]->name); }
  79. inline uint plugin_state(st_plugin_int **ref) { return ref[0]->state; }
  80. inline enum_plugin_load_option plugin_load_option(st_plugin_int **ref) {
  81. return ref[0]->load_option;
  82. }
  83. inline bool plugin_equals(st_plugin_int **ref1, st_plugin_int **ref2) {
  84. return ref1 && ref2 && (ref1[0] == ref2[0]);
  85. }
  86. #endif
  87. /**
  88. @class Plugin_array
  89. @brief Plugin array helper class.
  90. */
  91. class Plugin_array : public Prealloced_array<plugin_ref, 2> {
  92. public:
  93. /**
  94. Class construction.
  95. @param psi_key PSI key.
  96. */
  97. explicit Plugin_array(PSI_memory_key psi_key)
  98. : Prealloced_array<plugin_ref, 2>(psi_key) {}
  99. /**
  100. Check, whether the plugin specified by the plugin argument has been
  101. already added into the array.
  102. @param plugin Plugin to check.
  103. @retval true Plugin has been already added.
  104. @retval false There is no plugin in the array.
  105. */
  106. bool exists(plugin_ref plugin) {
  107. Plugin_array::iterator i;
  108. for (i = begin(); i != end(); ++i)
  109. if (plugin_equals(*i, plugin)) return true;
  110. return false;
  111. }
  112. };
  113. #endif // SQL_PLUGIN_REF_INCLUDED