33 #ifndef __INCLUDE_MIST_ENVIRONMENT__
34 #define __INCLUDE_MIST_ENVIRONMENT__
37 #ifndef __INCLUDE_MIST_CONF_H__
41 #ifndef __INCLUDE_MIST_SINGLETON__
47 #if defined( __MIST_WINDOWS__ ) && __MIST_WINDOWS__ > 0
51 #pragma comment( lib, "shlwapi.lib" )
66 namespace __environment__
68 #if defined( __MIST_WINDOWS__ ) && __MIST_WINDOWS__ > 0
69 static std::string cpu(
size_t &num_processors )
72 memset( &info, 0,
sizeof( info ) );
73 GetSystemInfo( &info );
78 std::string cpu =
"unknown";
79 std::string machine =
"unknown";
81 if( SHGetValue( HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
"ProcessorNameString", &type, value, &length ) == ERROR_SUCCESS )
86 for(
size_t i = 0 ; i < cpu.size( ) ; i++ )
98 cpu = cpu.substr( index );
100 num_processors = info.dwNumberOfProcessors;
106 static std::string user( )
111 if( GetUserName( value, &length ) )
113 return ( std::string( value ) );
117 return (
"unknown" );
121 static std::string machine( )
126 if( GetComputerName( value, &length ) )
128 return ( std::string( value ) );
132 return (
"unknown" );
136 static std::string os( )
138 std::string os =
"unknown";
139 OSVERSIONINFO osinfo;
140 memset( &osinfo, 0,
sizeof( osinfo ) );
141 osinfo.dwOSVersionInfoSize =
sizeof( osinfo );
143 if( GetVersionEx( &osinfo ) )
145 switch( osinfo.dwPlatformId )
147 case VER_PLATFORM_WIN32s:
148 os =
"Win32s on Windows 3.1";
151 case VER_PLATFORM_WIN32_WINDOWS:
152 switch( osinfo.dwMinorVersion )
168 case VER_PLATFORM_WIN32_NT:
169 if( osinfo.dwMajorVersion == 5 )
171 switch( osinfo.dwMinorVersion )
182 os =
"Windows Server 2003 family";
186 else if( osinfo.dwMajorVersion == 3 )
188 os =
"Windows NT 3.51";
190 else if( osinfo.dwMajorVersion == 4 )
192 os =
"Windows NT 4.0";
208 static std::string cpu(
size_t &num_processors )
210 typedef std::string::size_type size_type;
213 fi.open(
"/proc/cpuinfo" );
220 std::string cpuinfo =
"";
225 fi.getline( buff, 4094 );
233 size_type indx = cpuinfo.find(
"processor", 0 );
234 size_type num_cpu = 0;
235 while( indx != cpuinfo.npos )
238 indx = cpuinfo.find(
"processor", indx + 1 );
241 num_processors = num_cpu;
244 std::string cpuname =
"";
245 indx = cpuinfo.find(
"model name", 0 );
246 if( indx != cpuinfo.npos )
248 size_type sindx = cpuinfo.find(
':', indx );
249 size_type eindx = cpuinfo.find(
'\n', indx );
250 if( sindx != cpuinfo.npos && eindx != cpuinfo.npos )
252 cpuname = cpuinfo.substr( sindx + 2, eindx - sindx - 2 );
260 static std::string chomp(
const std::string &str )
266 else if( str.length( ) > 1 )
268 if( str[ str.length( ) - 1 ] ==
'\n' )
270 if( str[ str.length( ) - 2 ] ==
'\r' )
272 return( str.substr( 0, str.length( ) - 2 ) );
276 return( str.substr( 0, str.length( ) - 1 ) );
280 else if( str[ 0 ] ==
'\n' )
288 static std::string system_command(
const std::string &command )
290 FILE *gid = popen( command.c_str( ),
"r" );
299 fgets( buff, 4096, gid );
303 return( chomp( std::string( buff ) ) );
306 static std::string user( )
308 return( system_command(
"whoami" ) );
311 static std::string machine( )
313 return( system_command(
"uname -n" ) );
316 static std::string os( )
318 return( system_command(
"uname -sr" ) );
323 struct environment_info
326 std::string cpu_name;
328 std::string machine_name;
329 std::string user_name;
331 environment_info( ) :
333 machine_name( machine( ) ),
390 #endif // __INCLUDE_MIST_ENVIRONMENT__