~ubuntu-branches/ubuntu/trusty/drizzle/trusty

1 by Monty Taylor
Import upstream version 2010.03.1347
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1.2.4 by Monty Taylor
Import upstream version 2010.12.06
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
1 by Monty Taylor
Import upstream version 2010.03.1347
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
1.2.9 by Monty Taylor
Import upstream version 2011.03.11
20
#include <config.h>
1.1.2 by Monty Taylor
Import upstream version 2011.03.13
21
#include <cstring>
1 by Monty Taylor
Import upstream version 2010.03.1347
22
23
#include <drizzled/xid.h>
1.2.9 by Monty Taylor
Import upstream version 2011.03.11
24
#include <drizzled/charset.h>
1.1.2 by Monty Taylor
Import upstream version 2011.03.13
25
26
namespace drizzled {
1 by Monty Taylor
Import upstream version 2010.03.1347
27
28
void XID::set(uint64_t xid)
29
{
30
  formatID= 1;
31
  set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
1.1.2 by Monty Taylor
Import upstream version 2011.03.13
32
  memcpy(data + DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
33
  my_xid tmp= xid;
34
  memcpy(data + DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
35
  gtrid_length= DRIZZLE_XID_GTRID_LEN;
1 by Monty Taylor
Import upstream version 2010.03.1347
36
}
37
38
void XID::set(long g, long b, const char *d)
39
{
40
  formatID= 1;
41
  gtrid_length= g;
42
  bqual_length= b;
43
  memcpy(data, d, g+b);
44
}
45
1.1.3 by Tobias Frost
Import upstream version 2012.01.30
46
bool XID::is_null() const
1 by Monty Taylor
Import upstream version 2010.03.1347
47
{
48
  return formatID == -1;
49
}
50
1.1.3 by Tobias Frost
Import upstream version 2012.01.30
51
void XID::set_null()
1 by Monty Taylor
Import upstream version 2010.03.1347
52
{
53
  formatID= -1;
54
}
55
56
my_xid XID::quick_get_my_xid()
57
{
58
  my_xid tmp;
1.1.2 by Monty Taylor
Import upstream version 2011.03.13
59
  memcpy(&tmp, data + DRIZZLE_XID_OFFSET, sizeof(tmp));
1 by Monty Taylor
Import upstream version 2010.03.1347
60
  return tmp;
61
}
62
63
my_xid XID::get_my_xid()
64
{
65
  return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
66
    !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
67
    !memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
68
    quick_get_my_xid() : 0;
69
}
70
1.1.2 by Monty Taylor
Import upstream version 2011.03.13
71
uint32_t XID::length() const
1 by Monty Taylor
Import upstream version 2010.03.1347
72
{
73
  return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
74
    gtrid_length+bqual_length;
75
}
76
77
} /* namespace drizzled */