/* 
 SYSTEM STATUS driver.
 
 Copyright (C)	H. Nikolaus Schaller <hns@computer.org>
 Date:			2004
 
 This file is part of the mySTEP Library and is provided
 under the terms of the GNU Library General Public License.
 */ 

#import <SystemStatus/NSSystemStatus.h>

#include <sys/utsname.h>

@implementation NSSystemStatus

#define setmySTEP(PACKAGE_NAME, mySTEP_MAJOR_VERSION, mySTEP_MINOR_VERSION) [d setObject:[NSString stringWithFormat:@"%@.%@", @#mySTEP_MAJOR_VERSION, @#mySTEP_MINOR_VERSION] forKey:@#PACKAGE_NAME]

+ (NSDictionary *) sysInfo;
{ // collect all reasonable info we can get
	NSMutableDictionary *d=[NSMutableDictionary dictionaryWithCapacity:10];
	struct utsname u;
	NSData *da;
	NSString *s;
	uname(&u);
	setmySTEP(PACKAGE_NAME, mySTEP_MAJOR_VERSION, mySTEP_MINOR_VERSION);
	[d setObject:[NSString stringWithCString: u.sysname] forKey:@"SysName"];
	[d setObject:[NSString stringWithCString: u.nodename] forKey:@"Nodename"];
	[d setObject:[NSString stringWithCString: u.release] forKey:@"SysRelease"];
	[d setObject:[NSString stringWithCString: u.version] forKey:@"SysVersion"];
	// read more processor details from /proc/cpuinfo
	[d setObject:[NSString stringWithCString: u.machine] forKey:@"Processor"];
	[d setObject:@"x MHz" forKey:@"Clock"];
	[d setObject:@"RAM" forKey:@"MemoryType"];
	[d setObject:@"64 MB" forKey:@"Memory"];
	da=[NSData dataWithContentsOfFile:@"/proc/deviceinfo/product"];
	s=da?[[[NSString alloc] initWithData:da encoding:NSUTF8StringEncoding] autorelease]:nil;
	if(s) [d setObject:[s stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:@"Product"];
#if 0
	struct sysinfo s_info;
	int error;
	error = sysinfo(&s_info);
	printf("code error = %d\n", error);
	printf("Uptime = %ds\nLoad: 1 min %d / 5 min %d / 15 min %d\n"
		   "RAM: total %d / free %d / shared %d\n"
		   "Memory in buffers = %d\nSwap: total %d / free %d\n"
		   "Number of processes = %d\n",
		   s_info.uptime, s_info.loads[0],
		   s_info.loads[1], s_info.loads[2],
		   s_info.totalram, s_info.freeram,
		   s_info.sharedram, s_info.bufferram,
		   s_info.totalswap, s_info.freeswap,
		   s_info.procs);
#endif	// read memory from /proc/meminfo
	NSLog(@"sysInfo=%@", d);
	return d;
}

@end
