00001 /*------------------------------------------------------------------------------ 00002 00003 Copyright (c) 2004 Media Development Loan Fund 00004 00005 This file is part of the Campcaster project. 00006 https://www.campware.org/ 00007 To report bugs, send an e-mail to [email protected] 00008 00009 Campcaster is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 Campcaster is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with Campcaster; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 00024 This code is based upon the Leach working draft for UUIDs, 00025 http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt 00026 and the sample code therein. 00027 The original copyright message of the sample code is the following: 00028 00029 ** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc. 00030 ** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. & 00031 ** Digital Equipment Corporation, Maynard, Mass. 00032 ** Copyright (c) 1998 Microsoft. 00033 ** To anyone who acknowledges that this file is provided "AS IS" 00034 ** without any express or implied warranty: permission to use, copy, 00035 ** modify, and distribute this file for any purpose is hereby 00036 ** granted without fee, provided that the above copyright notices and 00037 ** this notice appears in all source code copies, and that none of 00038 ** the names of Open Software Foundation, Inc., Hewlett-Packard 00039 ** Company, or Digital Equipment Corporation be used in advertising 00040 ** or publicity pertaining to distribution of the software without 00041 ** specific, written prior permission. Neither Open Software 00042 ** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital Equipment 00043 ** Corporation makes any representations about the suitability of 00044 ** this software for any purpose. 00045 00046 00047 Author : $Author: fgerlits $ 00048 Version : $Revision: 2329 $ 00049 Location : $URL: svn://code.campware.org/campcaster/trunk/campcaster/src/modules/core/include/LiveSupport/Core/Uuid.h $ 00050 00051 ------------------------------------------------------------------------------*/ 00052 #ifndef LiveSupport_Core_Uuid_h 00053 #define LiveSupport_Core_Uuid_h 00054 00055 #ifndef __cplusplus 00056 #error This is a C++ include file 00057 #endif 00058 00059 00060 /* ============================================================ include files */ 00061 00062 #ifdef HAVE_CONFIG_H 00063 #include "configure.h" 00064 #endif 00065 00066 #ifdef HAVE_STDINT_H 00067 #include <stdint.h> 00068 #else 00069 #error need stdint.h 00070 #endif 00071 00072 00073 #include <string> 00074 #include "LiveSupport/Core/Ptr.h" 00075 00076 namespace LiveSupport { 00077 namespace Core { 00078 00079 /* ================================================================ constants */ 00080 00081 00082 /* =================================================================== macros */ 00083 00084 00085 /* =============================================================== data types */ 00086 00096 class Uuid 00097 { 00098 private: 00102 typedef uint64_t UuidTime; 00103 00107 typedef struct { 00108 char nodeId[6]; 00109 } UuidNode; 00110 00114 long long int id; 00115 00119 std::string idAsString; 00120 00124 uint32_t timeLow; 00125 00129 uint16_t timeMid; 00130 00134 uint16_t timeHiAndVersion; 00135 00139 uint8_t clockSeqHiAndReserved; 00140 00144 uint8_t clockSeqLow; 00145 00149 uint8_t node[6]; 00150 00154 Uuid(void) throw () 00155 { 00156 } 00157 00165 static bool 00166 compare(const Uuid & id1, 00167 const Uuid & id2) throw (); 00168 00175 static void 00176 getCurrentTime(UuidTime * timestamp) throw (); 00177 00184 static uint16_t 00185 trueRandom(void) throw (); 00186 00195 int 00196 readState(uint16_t * clockSeq, 00197 UuidTime * timestamp, 00198 UuidNode * node) throw (); 00199 00208 void 00209 writeState(uint16_t clockSeq, 00210 UuidTime timestamp, 00211 UuidNode node) throw (); 00212 00225 void 00226 format(uint16_t clockSeq, 00227 UuidTime timestamp, 00228 UuidNode node) throw (); 00229 00236 static void 00237 getSystemTime(UuidTime * uuidTime) throw (); 00238 00244 static void 00245 getIeeeNodeIdentifier(UuidNode * node) throw (); 00246 00251 void 00252 representAsString(void) throw (); 00253 00254 00255 public: 00260 static Ptr<Uuid>::Ref 00261 generateId(void) throw (); 00262 00270 bool 00271 operator==(const Uuid & otherId) const throw () 00272 { 00273 return compare(*this, otherId); 00274 } 00275 00283 bool 00284 operator!=(const Uuid & otherId) const throw () 00285 { 00286 return !compare(*this, otherId); 00287 } 00288 00294 operator std::string() const throw () 00295 { 00296 return idAsString; 00297 } 00298 }; 00299 00300 00301 /* ================================================= external data structures */ 00302 00303 00304 /* ====================================================== function prototypes */ 00305 00306 inline std::ostream & 00307 operator<< (std::ostream & os, 00308 const Uuid & id) 00309 { 00310 os << (std::string) id; 00311 00312 return os; 00313 } 00314 00315 00316 } // namespace Core 00317 } // namespace LiveSupport 00318 00319 #endif // LiveSupport_Core_Uuid_h 00320