Drizzled Public API Documentation

xid.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 #include <cstring>
00022 
00023 #include <drizzled/xid.h>
00024 #include <drizzled/charset.h>
00025 #include <drizzled/global_charset_info.h>
00026 #include <drizzled/charset_info.h>
00027 
00028 namespace drizzled {
00029 
00030 bool XID::eq(XID *xid)
00031 {
00032   return eq(xid->gtrid_length, xid->bqual_length, xid->data);
00033 }
00034 
00035 bool XID::eq(long g, long b, const char *d)
00036 {
00037   return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b);
00038 }
00039 
00040 void XID::set(XID *xid)
00041 {
00042   memcpy(this, xid, xid->length());
00043 }
00044 
00045 void XID::set(long f, const char *g, long gl, const char *b, long bl)
00046 {
00047   formatID= f;
00048   memcpy(data, g, gtrid_length= gl);
00049   memcpy(data+gl, b, bqual_length= bl);
00050 }
00051 
00052 void XID::set(uint64_t xid)
00053 {
00054   formatID= 1;
00055   set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
00056   memcpy(data + DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
00057   my_xid tmp= xid;
00058   memcpy(data + DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
00059   gtrid_length= DRIZZLE_XID_GTRID_LEN;
00060 }
00061 
00062 void XID::set(long g, long b, const char *d)
00063 {
00064   formatID= 1;
00065   gtrid_length= g;
00066   bqual_length= b;
00067   memcpy(data, d, g+b);
00068 }
00069 
00070 bool XID::is_null()
00071 {
00072   return formatID == -1;
00073 }
00074 
00075 void XID::null()
00076 {
00077   formatID= -1;
00078 }
00079 
00080 my_xid XID::quick_get_my_xid()
00081 {
00082   my_xid tmp;
00083   memcpy(&tmp, data + DRIZZLE_XID_OFFSET, sizeof(tmp));
00084   return tmp;
00085 }
00086 
00087 my_xid XID::get_my_xid()
00088 {
00089   return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
00090     !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
00091     !memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
00092     quick_get_my_xid() : 0;
00093 }
00094 
00095 uint32_t XID::length() const
00096 {
00097   return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
00098     gtrid_length+bqual_length;
00099 }
00100 
00101 const unsigned char *XID::key() const
00102 {
00103   return (unsigned char *)&gtrid_length;
00104 }
00105 
00106 uint32_t XID::key_length() const
00107 {
00108   return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
00109 }
00110 
00111 } /* namespace drizzled */