You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

  1. /*
  2. Copyright (c) 2007, Antony T Curtis
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Neither the name of FederatedX nor the names of its
  10. contributors may be used to endorse or promote products derived from
  11. this software without specific prior written permission.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  16. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. /*#define MYSQL_SERVER 1*/
  25. #include "sql_priv.h"
  26. #include <mysql/plugin.h>
  27. #include "ha_federatedx.h"
  28. #include "m_string.h"
  29. #ifdef USE_PRAGMA_IMPLEMENTATION
  30. #pragma implementation // gcc: Class implementation
  31. #endif
  32. typedef federatedx_io *(*instantiate_io_type)(MEM_ROOT *server_root,
  33. FEDERATEDX_SERVER *server);
  34. struct io_schemes_st
  35. {
  36. const char *scheme;
  37. instantiate_io_type instantiate;
  38. };
  39. static const io_schemes_st federated_io_schemes[] =
  40. {
  41. { "mysql", &instantiate_io_mysql },
  42. { "null", instantiate_io_null } /* must be last element */
  43. };
  44. const uint federated_io_schemes_count= array_elements(federated_io_schemes);
  45. federatedx_io::federatedx_io(FEDERATEDX_SERVER *aserver)
  46. : server(aserver), owner_ptr(0), txn_next(0), idle_next(0),
  47. active(FALSE), busy(FALSE), readonly(TRUE)
  48. {
  49. DBUG_ENTER("federatedx_io::federatedx_io");
  50. DBUG_ASSERT(server);
  51. mysql_mutex_assert_owner(&server->mutex);
  52. server->io_count++;
  53. DBUG_VOID_RETURN;
  54. }
  55. federatedx_io::~federatedx_io()
  56. {
  57. DBUG_ENTER("federatedx_io::~federatedx_io");
  58. server->io_count--;
  59. DBUG_VOID_RETURN;
  60. }
  61. bool federatedx_io::handles_scheme(const char *scheme)
  62. {
  63. const io_schemes_st *ptr = federated_io_schemes;
  64. const io_schemes_st *end = ptr + array_elements(federated_io_schemes);
  65. while (ptr != end && strcasecmp(scheme, ptr->scheme))
  66. ++ptr;
  67. return ptr != end;
  68. }
  69. federatedx_io *federatedx_io::construct(MEM_ROOT *server_root,
  70. FEDERATEDX_SERVER *server)
  71. {
  72. const io_schemes_st *ptr = federated_io_schemes;
  73. const io_schemes_st *end = ptr + (array_elements(federated_io_schemes) - 1);
  74. while (ptr != end && strcasecmp(server->scheme, ptr->scheme))
  75. ++ptr;
  76. return ptr->instantiate(server_root, server);
  77. }