520.4.31
by Monty Taylor
Removed server_id from common_includes. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
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 |
*/
|
|
19 |
||
612.2.4
by Monty Taylor
Moved some defines to config.h. Stopped including config.h directly anywhere. |
20 |
#include <drizzled/global.h> |
520.4.31
by Monty Taylor
Removed server_id from common_includes. |
21 |
#include <stdint.h> |
22 |
#include <string.h> |
|
23 |
#include <drizzled/xid.h> |
|
24 |
||
25 |
XID::XID() |
|
26 |
{}
|
|
27 |
||
28 |
bool XID::eq(XID *xid) |
|
29 |
{
|
|
30 |
return eq(xid->gtrid_length, xid->bqual_length, xid->data); |
|
31 |
}
|
|
32 |
||
33 |
bool XID::eq(long g, long b, const char *d) |
|
34 |
{
|
|
35 |
return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); |
|
36 |
}
|
|
37 |
||
38 |
void XID::set(XID *xid) |
|
39 |
{
|
|
40 |
memcpy(this, xid, xid->length()); |
|
41 |
}
|
|
42 |
||
43 |
void XID::set(long f, const char *g, long gl, const char *b, long bl) |
|
44 |
{
|
|
45 |
formatID= f; |
|
46 |
memcpy(data, g, gtrid_length= gl); |
|
47 |
memcpy(data+gl, b, bqual_length= bl); |
|
48 |
}
|
|
49 |
||
50 |
void XID::set(uint64_t xid) |
|
51 |
{
|
|
52 |
my_xid tmp; |
|
53 |
formatID= 1; |
|
54 |
set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX); |
|
55 |
memcpy(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)); |
|
56 |
tmp= xid; |
|
57 |
memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp)); |
|
58 |
gtrid_length=DRIZZLE_XID_GTRID_LEN; |
|
59 |
}
|
|
60 |
||
61 |
void XID::set(long g, long b, const char *d) |
|
62 |
{
|
|
63 |
formatID= 1; |
|
64 |
gtrid_length= g; |
|
65 |
bqual_length= b; |
|
66 |
memcpy(data, d, g+b); |
|
67 |
}
|
|
68 |
||
69 |
bool XID::is_null() |
|
70 |
{
|
|
71 |
return formatID == -1; |
|
72 |
}
|
|
73 |
||
74 |
void XID::null() |
|
75 |
{
|
|
76 |
formatID= -1; |
|
77 |
}
|
|
78 |
||
79 |
my_xid XID::quick_get_my_xid() |
|
80 |
{
|
|
81 |
my_xid tmp; |
|
82 |
memcpy(&tmp, data+DRIZZLE_XID_OFFSET, sizeof(tmp)); |
|
83 |
return tmp; |
|
84 |
}
|
|
85 |
||
86 |
my_xid XID::get_my_xid() |
|
87 |
{
|
|
88 |
return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 && |
|
89 |
!memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) && |
|
90 |
!memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ? |
|
91 |
quick_get_my_xid() : 0; |
|
92 |
}
|
|
93 |
||
94 |
uint32_t XID::length() |
|
95 |
{
|
|
96 |
return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+ |
|
97 |
gtrid_length+bqual_length; |
|
98 |
}
|
|
99 |
||
100 |
unsigned char *XID::key() |
|
101 |
{
|
|
102 |
return (unsigned char *)>rid_length; |
|
103 |
}
|
|
104 |
||
105 |
uint32_t XID::key_length() |
|
106 |
{
|
|
107 |
return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length; |
|
108 |
}
|