diff --git a/ChangeLog b/ChangeLog index 90c6927d5..360dbf83c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ * Source/UnixFileHandle.m: Permit accept/connect on descriptors by default. * Source/WindowsFileHandle.m: ditto + * Headers/Foundation/NSProcessInfo.h: Added MacOS-X operating system + methods and enum + * Source/NSProcessInfo.m: Added operating system methods and documented + all methods for autogsdoc. 2002-04-07 Richard Frith-Macdonald diff --git a/Headers/gnustep/base/NSProcessInfo.h b/Headers/gnustep/base/NSProcessInfo.h index 490aeef08..9d52874bb 100644 --- a/Headers/gnustep/base/NSProcessInfo.h +++ b/Headers/gnustep/base/NSProcessInfo.h @@ -34,22 +34,42 @@ @class NSData; @class NSMutableSet; +#ifndef STRICT_OPENSTEP +/* + * Constants returned by -operatingSystem + * NB. The presence of a constant in this list does *NOT* imply that + * the named operating system is supported. Some values are provided + * for MacOS-X compatibility only. + */ +enum { + NSWindowsNTOperatingSystem = 1, + NSWindows95OperatingSystem, + NSSolarisOperatingSystem, + NSHPUXOperatingSystem, + NSMACHOperatingSystem, + NSSunOSOperatingSystem, + NSOSF1OperatingSystem, + NSGNULinuxOperatingSystem = 100, + NSBSDOperatingSystem +}; +#endif + + @interface NSProcessInfo: NSObject -/* Getting an NSProcessInfo Object */ + (NSProcessInfo*) processInfo; -/* Returning Process Information */ - (NSArray*) arguments; - (NSDictionary*) environment; +- (NSString*) globallyUniqueString; - (NSString*) hostName; #ifndef STRICT_OPENSTEP +- (unsigned int) operatingSystem; +- (NSString*) operatingSystemName; - (int) processIdentifier; #endif - (NSString*) processName; -- (NSString*) globallyUniqueString; -/* Specifying a Process Name */ - (void) setProcessName: (NSString*)newName; @end diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index 630e6967d..2b62d1cf8 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -535,9 +536,9 @@ int main(int argc, char *argv[], char *env[]) #endif /* HAS_LOAD_METHOD && HAS_PROCFS */ -/************************************************************************* - *** Getting an NSProcessInfo Object - *************************************************************************/ +/** + * Returns the shared NSProcessInfo object for the current process. + */ + (NSProcessInfo *) processInfo { // Check if the main() function was successfully called @@ -556,45 +557,31 @@ int main(int argc, char *argv[], char *env[]) return _gnu_sharedProcessInfoObject; } -/************************************************************************* - *** Returning Process Information - *************************************************************************/ +/** + * Returns an array containing the arguments supplied to start this + * process. NB. In GNUstep, any arguments of the form --GNU-Debug=... + * are not included in this array ... they are part of the + * debug mechanism, and are hidden so that setting debug variables + * will not effect the normal operation of the program. + */ - (NSArray *) arguments { return _gnu_arguments; } +/** + * Returns a dictionary giving the environment variables which were + * provided for the process to use. + */ - (NSDictionary *) environment { return _gnu_environment; } -- (NSString *) hostName -{ - if (!_gnu_hostName) - { - _gnu_hostName = [[[NSHost currentHost] name] copy]; - } - return _gnu_hostName; -} - -- (int) processIdentifier -{ - int pid; - -#if defined(__MINGW__) - pid = (int)GetCurrentProcessId(); -#else - pid = (int)getpid(); -#endif - return pid; -} - -- (NSString *) processName -{ - return _gnu_processName; -} - +/** + * Returns a string which may be used as a unique identifier for the + * current process. + */ - (NSString *) globallyUniqueString { int pid; @@ -612,6 +599,120 @@ int main(int argc, char *argv[], char *env[]) [self hostName], pid, [NSDate date]]; } +/** + * Returns the name of the machine on which this process is running. + */ +- (NSString *) hostName +{ + if (!_gnu_hostName) + { + _gnu_hostName = [[[NSHost currentHost] name] copy]; + } + return _gnu_hostName; +} + +/** + * Return a number representing the operating system type.
+ * The known types are listed in the header file, but not all of the + * listed types are actually implemented ... some are present for + * MacOS-X compatibility only.
+ * + * NSWindowsNTOperatingSystem - used for windows NT, 2000, XP + * NSWindows95OperatingSystem - probably never to be implemented + * NSSolarisOperatingSystem - not yet recognised + * NSHPUXOperatingSystem - not implemented + * NSMACHOperatingSystem - perhaps the HURD in future? + * NSSunOSOperatingSystem - probably never to be implemented + * NSOSF1OperatingSystem - probably never to be implemented + * NSGNULinuxOperatingSystem - the GNUstep 'standard' + * NSBSDOperatingSystem - BSD derived operating systems + * + */ +- (unsigned int) operatingSystem +{ + static unsigned int os = 0; + + if (os == 0) + { + NSString *n = [self operatingSystemName]; + + if ([n isEqualToString: @"linux-gnu"] == YES) + { + os = NSGNULinuxOperatingSystem; + } + else if ([n isEqualToString: @"mingw"] == YES) + { + os = NSWindowsNTOperatingSystem; + } + else if ([n isEqualToString: @"cygwin"] == YES) + { + os = NSWindowsNTOperatingSystem; + } + else if ([n hasPrefix: @"bsd"] == YES) + { + os = NSBSDOperatingSystem; + } + else if ([n hasPrefix: @"freebsd"] == YES) + { + os = NSBSDOperatingSystem; + } + else if ([n hasPrefix: @"netbsd"] == YES) + { + os = NSBSDOperatingSystem; + } + else if ([n hasPrefix: @"openbsd"] == YES) + { + os = NSBSDOperatingSystem; + } + else + { + NSLog(@"Unable to determine O/S ... assuming GNU/Linux"); + os = NSGNULinuxOperatingSystem; + } + } + return os; +} + +/** + * Returns the name of the operating system in use. + */ +- (NSString*) operatingSystemName +{ + static NSString *os = nil; + + if (os == nil) + { + os = [[NSBundle _gnustep_target_os] copy]; + } + return os; +} + +/** + * Returns the process identifier number which identifies this process + * on this machine. + */ +- (int) processIdentifier +{ + int pid; + +#if defined(__MINGW__) + pid = (int)GetCurrentProcessId(); +#else + pid = (int)getpid(); +#endif + return pid; +} + +/** + * Returns the process name for this process. This may have been set using + * the -setProcessName: method, or may be the default process name (the + * file name of the binary being executed). + */ +- (NSString *) processName +{ + return _gnu_processName; +} + /** * Change the name of the current process to newName. */