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_BRASS_VERSION_H 00022 #define OM_HGUARD_BRASS_VERSION_H 00023 00024 #include <cstring> 00025 #include <string> 00026 00027 #include "common/safeuuid.h" 00028 00034 class BrassVersion { 00036 std::string filename; 00037 00042 mutable uuid_t uuid; 00043 00044 public: 00045 BrassVersion(const std::string & dbdir) : filename(dbdir) { 00046 filename += "/iambrass"; 00047 } 00048 00050 void create(); 00051 00056 void read_and_check(); 00057 00059 const char * get_uuid() const { 00060 // uuid is unsigned char[]. 00061 return reinterpret_cast<const char *>(uuid); 00062 } 00063 00065 std::string get_uuid_string() const { 00066 char buf[37]; 00067 uuid_unparse_lower(uuid, buf); 00068 return std::string(buf, 36); 00069 } 00070 00072 void set_uuid(void * data) { 00073 std::memcpy(uuid, data, 16); 00074 } 00075 00080 bool set_uuid_string(const std::string & s) { 00081 return uuid_parse(s.c_str(), uuid); 00082 } 00083 }; 00084 00085 #endif