[complement-svn] SF.net SVN: complement: [1401] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-23 16:15:39
|
Revision: 1401 http://svn.sourceforge.net/complement/?rev=1401&view=rev Author: complement Date: 2006-11-23 08:15:33 -0800 (Thu, 23 Nov 2006) Log Message: ----------- take hostid on Linux Modified Paths: -------------- trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/Makefile.inc Added Paths: ----------- trunk/complement/explore/include/mt/uid.h trunk/complement/explore/lib/mt/uid.cc Added: trunk/complement/explore/include/mt/uid.h =================================================================== --- trunk/complement/explore/include/mt/uid.h (rev 0) +++ trunk/complement/explore/include/mt/uid.h 2006-11-23 16:15:33 UTC (rev 1401) @@ -0,0 +1,56 @@ +// -*- C++ -*- Time-stamp: <06/11/23 16:51:52 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#ifndef __mt_uid_h +#define __mt_uid_h + +#ifndef __config_feature_h +#include <config/feature.h> +#endif + +#include <string> +#include <stdint.h> + +namespace xmt { + +struct uuid_type +{ + union { + uint8_t b[16]; + uint32_t i[4]; + } u; + + + uuid_type() + {} + + uuid_type( const uuid_type& uid ) + { + u.i[0] = uid.u.i[0]; + u.i[1] = uid.u.i[1]; + u.i[2] = uid.u.i[2]; + u.i[3] = uid.u.i[3]; + } + + + bool operator ==( const uuid_type& uid ) + { return u.i[0] == uid.u.i[0] && u.i[1] == uid.u.i[1] && u.i[2] == uid.u.i[2] && u.i[3] == uid.u.i[3]; } + + bool operator !=( const uuid_type& uid ) + { return u.i[0] != uid.u.i[0] || u.i[1] != uid.u.i[1] || u.i[2] != uid.u.i[2] || u.i[3] != uid.u.i[3]; } + +}; + +const std::string& hostid_str(); +const xmt::uuid_type& hostid(); + +} // namespace xmt + +#endif // __mt_uid_h Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2006-11-20 13:20:25 UTC (rev 1400) +++ trunk/complement/explore/lib/mt/ChangeLog 2006-11-23 16:15:33 UTC (rev 1401) @@ -1,3 +1,9 @@ +2006-11-23 Petr Ovtchenkov <pt...@is...> + + * uid.h, uid.cc: return hostid on Linux + + * libxmt: version 1.9.2 + 2006-10-31 Petr Ovtchenkov <pt...@is...> * time.cc: add useful includes, detected when compile Modified: trunk/complement/explore/lib/mt/Makefile.inc =================================================================== --- trunk/complement/explore/lib/mt/Makefile.inc 2006-11-20 13:20:25 UTC (rev 1400) +++ trunk/complement/explore/lib/mt/Makefile.inc 2006-11-23 16:15:33 UTC (rev 1401) @@ -1,8 +1,8 @@ -# -*- Makefile -*- Time-stamp: <06/09/22 22:21:22 ptr> +# -*- Makefile -*- Time-stamp: <06/11/23 17:32:14 ptr> LIBNAME = xmt MAJOR = 1 MINOR = 9 -PATCH = 1 -SRC_CC = xmt.cc thr_mgr.cc time.cc +PATCH = 2 +SRC_CC = xmt.cc thr_mgr.cc time.cc uid.cc SRC_C = fl.c Added: trunk/complement/explore/lib/mt/uid.cc =================================================================== --- trunk/complement/explore/lib/mt/uid.cc (rev 0) +++ trunk/complement/explore/lib/mt/uid.cc 2006-11-23 16:15:33 UTC (rev 1401) @@ -0,0 +1,73 @@ +// -*- C++ -*- Time-stamp: <06/11/23 17:35:29 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License version 3.0 + * + */ + +#include <mt/uid.h> +#include <mt/xmt.h> +#include <fstream> +#include <sstream> +#include <iomanip> + +namespace xmt { + +namespace detail { + +using namespace std; +using namespace xmt; + +class __uid_init +{ + public: + __uid_init(); + + static Mutex _lk; + static uuid_type _host_id; + static string _host_id_str; +}; + +Mutex __uid_init::_lk; +uuid_type __uid_init::_host_id; +string __uid_init::_host_id_str; + +__uid_init::__uid_init() +{ + Locker lock( _lk ); + ifstream f( "/proc/sys/kernel/random/boot_id" ); + + getline( f, _host_id_str ); + + istringstream s( _host_id_str ); + char delimiter; + + s >> hex >> _host_id.u.b[0] >> _host_id.u.b[1] >> _host_id.u.b[2] >> _host_id.u.b[3] + >> delimiter + >> _host_id.u.b[4] >> _host_id.u.b[5] + >> delimiter + >> _host_id.u.b[6] >> _host_id.u.b[7] + >> delimiter + >> _host_id.u.b[8] >> _host_id.u.b[9] + >> delimiter + >> _host_id.u.b[10] >> _host_id.u.b[11] >> _host_id.u.b[12] >> _host_id.u.b[13] >> _host_id.u.b[14] >> _host_id.u.b[15]; +} + +} // namespace detail + +const std::string& hostid_str() +{ + static detail::__uid_init _uid; + return detail::__uid_init::_host_id_str; +} + +const xmt::uuid_type& hostid() +{ + hostid_str(); + return detail::__uid_init::_host_id; +} + +} // namespace xmt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |