00001 00004 /* Copyright (C) 2006,2007,2008,2009 Olly Betts 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; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef OM_HGUARD_FLINT_VERSION_H 00022 #define OM_HGUARD_FLINT_VERSION_H 00023 00024 #include <cstring> 00025 #include <string> 00026 00027 #include "common/safeuuid.h" 00028 00034 class FlintVersion { 00036 std::string filename; 00037 00039 mutable uuid_t uuid; 00040 00042 void ensure_uuid() const; 00043 00044 public: 00045 FlintVersion(const std::string & dbdir) 00046 : filename(dbdir + "/iamflint") { } 00047 00049 void create(); 00050 00057 void read_and_check(bool readonly); 00058 00060 const char * get_uuid() const { 00061 ensure_uuid(); 00062 return reinterpret_cast<const char *>(uuid); 00063 } 00064 00066 std::string get_uuid_string() const { 00067 char buf[37]; 00068 ensure_uuid(); 00069 uuid_unparse_lower(uuid, buf); 00070 return std::string(buf, 36); 00071 } 00072 00074 void set_uuid(void * data) { 00075 std::memcpy(uuid, data, 16); 00076 } 00077 00082 bool set_uuid_string(const std::string & s) { 00083 return uuid_parse(s.c_str(), uuid); 00084 } 00085 }; 00086 00087 #endif