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 
00026 namespace drizzled {
00027 
00028 void XID::set(uint64_t xid)
00029 {
00030   formatID= 1;
00031   set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
00032   memcpy(data + DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
00033   my_xid tmp= xid;
00034   memcpy(data + DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
00035   gtrid_length= DRIZZLE_XID_GTRID_LEN;
00036 }
00037 
00038 void XID::set(long g, long b, const char *d)
00039 {
00040   formatID= 1;
00041   gtrid_length= g;
00042   bqual_length= b;
00043   memcpy(data, d, g+b);
00044 }
00045 
00046 bool XID::is_null() const
00047 {
00048   return formatID == -1;
00049 }
00050 
00051 void XID::set_null()
00052 {
00053   formatID= -1;
00054 }
00055 
00056 my_xid XID::quick_get_my_xid()
00057 {
00058   my_xid tmp;
00059   memcpy(&tmp, data + DRIZZLE_XID_OFFSET, sizeof(tmp));
00060   return tmp;
00061 }
00062 
00063 my_xid XID::get_my_xid()
00064 {
00065   return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
00066     !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
00067     !memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
00068     quick_get_my_xid() : 0;
00069 }
00070 
00071 uint32_t XID::length() const
00072 {
00073   return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
00074     gtrid_length+bqual_length;
00075 }
00076 
00077 } /* namespace drizzled */