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 Author : $Author: fgerlits $ 00025 Version : $Revision: 2329 $ 00026 Location : $URL: svn://code.campware.org/campcaster/trunk/campcaster/src/modules/core/src/UniqueId.cxx $ 00027 00028 ------------------------------------------------------------------------------*/ 00029 00030 /* ============================================================ include files */ 00031 00032 #ifdef HAVE_CONFIG_H 00033 #include "configure.h" 00034 #endif 00035 00036 #include <cstdlib> 00037 00038 #include "LiveSupport/Core/Uuid.h" 00039 #include "LiveSupport/Core/Md5.h" 00040 #include "LiveSupport/Core/UniqueId.h" 00041 00042 00043 using namespace LiveSupport::Core; 00044 00045 /* =================================================== local data structures */ 00046 00047 00048 /* ================================================ local constants & macros */ 00049 00050 00051 /* =============================================== local function prototypes */ 00052 00053 00054 /* ============================================================= module code */ 00055 00056 /*------------------------------------------------------------------------------ 00057 * Generate a globally unique id. 00058 *----------------------------------------------------------------------------*/ 00059 Ptr<UniqueId>::Ref 00060 UniqueId :: generateId(void) throw () 00061 { 00062 Ptr<Uuid>::Ref uuid = Uuid::generateId(); 00063 // as uuid is 128 bits, but we have only 63 bits, create an md5 hash 00064 // (which is still 128 bits), and use its values to create a 63 value 00065 // hopefully this is unique enough 00066 Md5 md5((std::string)*uuid); 00067 uint64_t idValue; 00068 00069 idValue = md5.high64bits(); 00070 idValue += md5.low64bits(); 00071 // make sure it's 63 bits only, so that signed 64 bit containers can 00072 // also accept it 00073 idValue &= 0x7fffffffffffffffLL; 00074 00075 Ptr<UniqueId>::Ref id(new UniqueId(idValue)); 00076 00077 return id; 00078 } 00079