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