[complement-svn] SF.net SVN: complement: [1889] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-06-06 17:27:26
|
Revision: 1889 http://complement.svn.sourceforge.net/complement/?rev=1889&view=rev Author: complement Date: 2008-06-06 10:27:03 -0700 (Fri, 06 Jun 2008) Log Message: ----------- functions for generating UIDs; libxmt revision to 2.0.3 Modified Paths: -------------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc trunk/complement/explore/lib/mt/uid.cc Modified: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/include/mt/uid.h 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 13:38:05 ptr> +// -*- C++ -*- Time-stamp: <08/06/06 21:21:30 yeti> /* * Copyright (c) 2006 @@ -65,6 +65,9 @@ const char *hostid_str(); const xmt::uuid_type& hostid(); +std::string uid_str(); +xmt::uuid_type uid(); + } // namespace xmt #endif // __mt_uid_h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/lib/mt/ChangeLog 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,3 +1,9 @@ +2008-06-06 Petr Ovtchenkov <pt...@is...> + + * uid.h, uid.cc: functions for generating UIDs; + + * libxmt: bump revision to 2.0.3. + 2008-04-23 Petr Ovtchenkov <pt...@is...> * mutex: remove STLport-specific macro STATIC_CAST; Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/lib/mt/Makefile.inc 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <08/04/23 23:15:02 ptr> +# -*- Makefile -*- Time-stamp: <08/06/06 21:25:42 yeti> LIBNAME = xmt MAJOR = 2 MINOR = 0 -PATCH = 2 +PATCH = 3 SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc shm.cc callstack.cc system_error.cc thread.cc \ date_time.cc SRC_C = fl.c Modified: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc 2008-06-06 14:41:32 UTC (rev 1888) +++ trunk/complement/explore/lib/mt/uid.cc 2008-06-06 17:27:03 UTC (rev 1889) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/11/29 13:38:19 ptr> +// -*- C++ -*- Time-stamp: <08/06/06 21:23:34 yeti> /* * Copyright (c) 2006 @@ -34,6 +34,16 @@ uuid_type __uid_init::_host_id; char __uid_init::_host_id_str[48]; +class __uuid_init +{ + public: + __uuid_init(); + + static ifstream _uuid; +}; + +ifstream __uuid_init::_uuid; + __uid_init::__uid_init() { static mutex _lk; @@ -83,8 +93,21 @@ >> reinterpret_cast<unsigned&>(_host_id.u.b[15]); } +__uuid_init::__uuid_init() +{ + static mutex _lk; + + scoped_lock lock( _lk ); + + if ( !_uuid.is_open() ) { + _uuid.open( "/proc/sys/kernel/random/uuid" ); + } +} + } // namespace detail +using namespace std; + const char *hostid_str() { static detail::__uid_init _uid; @@ -97,4 +120,63 @@ return detail::__uid_init::_host_id; } +std::string uid_str() +{ + static detail::__uuid_init _uid; + + static mutex _lk; + + scoped_lock lock( _lk ); + + std::string tmp; + + getline( _uid._uuid, tmp ); + + return tmp; +} + +xmt::uuid_type uid() +{ + string tmp = uid_str(); + uuid_type id; + + stringstream s; + s << tmp[0] << tmp[1] << ' ' + << tmp[2] << tmp[3] << ' ' + << tmp[4] << tmp[5] << ' ' + << tmp[6] << tmp[7] << ' ' // - + << tmp[9] << tmp[10] << ' ' + << tmp[11] << tmp[12] << ' ' // - + << tmp[14] << tmp[15] << ' ' + << tmp[16] << tmp[17] << ' ' // - + << tmp[19] << tmp[20] << ' ' + << tmp[21] << tmp[22] << ' ' // - + << tmp[24] << tmp[25] << ' ' + << tmp[26] << tmp[27] << ' ' + << tmp[28] << tmp[29] << ' ' + << tmp[30] << tmp[31] << ' ' + << tmp[32] << tmp[33] << ' ' + << tmp[34] << tmp[35]; + + s >> hex + >> reinterpret_cast<unsigned&>(id.u.b[0]) + >> reinterpret_cast<unsigned&>(id.u.b[1]) + >> reinterpret_cast<unsigned&>(id.u.b[2]) + >> reinterpret_cast<unsigned&>(id.u.b[3]) + >> reinterpret_cast<unsigned&>(id.u.b[4]) + >> reinterpret_cast<unsigned&>(id.u.b[5]) + >> reinterpret_cast<unsigned&>(id.u.b[6]) + >> reinterpret_cast<unsigned&>(id.u.b[7]) + >> reinterpret_cast<unsigned&>(id.u.b[8]) + >> reinterpret_cast<unsigned&>(id.u.b[9]) + >> reinterpret_cast<unsigned&>(id.u.b[10]) + >> reinterpret_cast<unsigned&>(id.u.b[11]) + >> reinterpret_cast<unsigned&>(id.u.b[12]) + >> reinterpret_cast<unsigned&>(id.u.b[13]) + >> reinterpret_cast<unsigned&>(id.u.b[14]) + >> reinterpret_cast<unsigned&>(id.u.b[15]); + + return id; +} + } // namespace xmt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |