1 /* Interface for NSProcessInfo for GNUStep 2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. 3 4 Written by: Georg Tuparev, EMBL & Academia Naturalis, 5 Heidelberg, Germany 6 Tuparev@EMBL-Heidelberg.de 7 Last update: 08-aug-1995 8 9 This file is part of the GNUstep Base Library. 10 11 This library is free software; you can redistribute it and/or 12 modify it under the terms of the GNU Lesser General Public 13 License as published by the Free Software Foundation; either 14 version 2 of the License, or (at your option) any later version. 15 16 This library is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Lesser General Public License for more details. 20 21 You should have received a copy of the GNU Lesser General Public 22 License along with this library; if not, write to the Free 23 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 Boston, MA 02110 USA. 25 */ 26 27 #ifndef __NSProcessInfo_h_GNUSTEP_BASE_INCLUDE 28 #define __NSProcessInfo_h_GNUSTEP_BASE_INCLUDE 29 #import <GNUstepBase/GSVersionMacros.h> 30 31 #import <Foundation/NSObject.h> 32 33 #ifdef __ANDROID__ 34 #include <jni.h> 35 #endif 36 37 #if defined(__cplusplus) 38 extern "C" { 39 #endif 40 41 @class NSArray; 42 @class NSMutableArray; 43 @class NSDictionary; 44 @class NSData; 45 @class NSMutableSet; 46 47 #if OS_API_VERSION(MAC_OS_X_VERSION_10_9,GS_API_LATEST) 48 typedef uint64_t NSActivityOptions; 49 enum 50 { 51 NSActivityIdleDisplaySleepDisabled = (1ULL << 40), 52 NSActivityIdleSystemSleepDisabled = (1ULL << 20), 53 NSActivitySuddenTerminationDisabled = (1ULL << 14), 54 NSActivityAutomaticTerminationDisabled = (1ULL << 15), 55 56 NSActivityUserInitiated = (0x00FFFFFFULL | NSActivityIdleSystemSleepDisabled), 57 NSActivityUserInitiatedAllowingIdleSystemSleep = (NSActivityUserInitiated & ~NSActivityIdleSystemSleepDisabled), 58 59 NSActivityBackground = 0x000000FFULL, 60 61 NSActivityLatencyCritical = 0xFF00000000ULL, 62 }; 63 #endif 64 65 #if OS_API_VERSION(GS_API_MACOSX,GS_API_LATEST) 66 67 /** 68 * Constants returned by the -operatingSystem method. 69 * NB. The presence of a constant in this list does *NOT* imply that 70 * the named operating system is supported. Some values are provided 71 * for MacOS-X compatibility or are obsolete and provided for 72 * backward compatibility. 73 */ 74 enum { 75 NSWindowsNTOperatingSystem = 1, 76 NSWindows95OperatingSystem, 77 NSSolarisOperatingSystem, 78 NSHPUXOperatingSystem, 79 NSMACHOperatingSystem, 80 NSSunOSOperatingSystem, 81 NSOSF1OperatingSystem, 82 #if OS_API_VERSION(GS_API_NONE,GS_API_NONE) 83 GSGNULinuxOperatingSystem = 100, 84 GSBSDOperatingSystem, 85 GSBeOperatingSystem, 86 GSCygwinOperatingSystem 87 88 #if GS_API_VERSION(0,011500) 89 // Defines of deprecated constants for backward compatibility 90 #define NSGNULinuxOperatingSystem GSGNULinuxOperatingSystem 91 #define NSBSDOperatingSystem GSBSDOperatingSystem 92 #define NSBeOperatingSystem GSBeOperatingSystem 93 #define NSCygwinOperatingSystem GSCygwinOperatingSystem 94 #endif /* GS_API_VERSION(0,011500) */ 95 96 #endif /* OS_API_VERSION(GS_API_NONE,GS_API_NONE) */ 97 }; 98 #endif /* OS_API_VERSION(GS_API_MACOSX,GS_API_LATEST) */ 99 100 101 @interface NSProcessInfo: NSObject 102 103 /** 104 * Returns the shared NSProcessInfo object for the current process. 105 */ 106 + (NSProcessInfo*) processInfo; 107 108 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST) 109 #if GS_HAS_DECLARED_PROPERTIES 110 @property (readonly) NSUInteger systemUptime; 111 #else 112 - (NSUInteger) systemUptime; 113 #endif 114 #endif 115 116 /** 117 * Returns an array containing the arguments supplied to start this 118 * process.<br /> 119 * NB. In GNUstep, any arguments of the form --GNU-Debug=... 120 * are <em>not</em> included in this array ... they are part of the 121 * debug mechanism, and are hidden so that setting debug variables 122 * will not effect the normal operation of the program.<br /> 123 * Please note, the special <code>--GNU-Debug=...</code> syntax differs from 124 * that which is used to specify values for the [NSUserDefaults] system.<br /> 125 * User defaults are set on the command line by specifying the default name 126 * (with a leading hyphen) as one argument, and the default value as the 127 * following argument. The arguments used to set user defaults are 128 * present in the array returned by this method. 129 */ 130 - (NSArray*) arguments; 131 132 /** 133 * Returns a dictionary giving the environment variables which were 134 * provided for the process to use. 135 */ 136 - (NSDictionary*) environment; 137 138 /** 139 * Returns a string which may be used as a globally unique identifier.<br /> 140 * The string contains the host name, the process ID, a timestamp and a 141 * counter.<br /> 142 * The first three values identify the process in which the string is 143 * generated, while the fourth ensures that multiple strings generated 144 * within the same process are unique. 145 */ 146 - (NSString*) globallyUniqueString; 147 148 /** 149 * Returns the name of the machine on which this process is running. 150 */ 151 - (NSString*) hostName; 152 153 #if OS_API_VERSION(GS_API_MACOSX,GS_API_LATEST) 154 155 /** 156 * Return a number representing the operating system type.<br /> 157 * The known types are listed in the header file, but not all of the 158 * listed types are actually implemented ... some are present for 159 * MacOS-X compatibility only.<br /> 160 * <list> 161 * <item>NSWindowsNTOperatingSystem - used for Windows NT, and later</item> 162 * <item>NSWindows95OperatingSystem - probably never to be implemented</item> 163 * <item>NSSolarisOperatingSystem - used for Sun Solaris</item> 164 * <item>NSHPUXOperatingSystem - used for HP/UX</item> 165 * <item>NSMACHOperatingSystem - MacOSX and perhaps Hurd in future?</item> 166 * <item>NSSunOSOperatingSystem - Used for Sun Sun/OS</item> 167 * <item>NSOSF1OperatingSystem - Used for OSF/1 (probably obsolete)</item> 168 * <item>GSGNULinuxOperatingSystem - the GNUstep 'standard'</item> 169 * <item>GSBSDOperatingSystem - BSD derived operating systems</item> 170 * <item>GSBeperatingSystem - Used for Be-OS (probably obsolete)</item> 171 * <item>GSCygwinOperatingSystem - cygwin unix-like environment</item> 172 * </list> 173 */ 174 - (NSUInteger) operatingSystem; 175 176 /** 177 * Return a human readable string representing the operating system type.<br /> 178 * The supported types are - 179 * <list> 180 * <item>NSWindowsNTOperatingSystem - used for Windows NT, and later</item> 181 * <item>NSWindows95OperatingSystem - probably never to be implemented</item> 182 * <item>NSSolarisOperatingSystem - used for Sun Solaris</item> 183 * <item>NSHPUXOperatingSystem - used for HP/UX</item> 184 * <item>NSMACHOperatingSystem - MacOSX and perhaps Hurd in future?</item> 185 * <item>NSSunOSOperatingSystem - Used for Sun Sun/OS</item> 186 * <item>NSOSF1OperatingSystem - Used for OSF/1 (probably obsolete)</item> 187 * <item>GSGNULinuxOperatingSystem - the GNUstep 'standard'</item> 188 * <item>GSBSDOperatingSystem - BSD derived operating systems</item> 189 * <item>GSBeperatingSystem - Used for Be-OS (probably obsolete)</item> 190 * <item>GSCygwinOperatingSystem - cygwin unix-like environment</item> 191 * </list> 192 */ 193 - (NSString*) operatingSystemName; 194 195 /** 196 * Returns a human readable version string for the current operating system 197 * version. 198 */ 199 #if OS_API_VERSION(MAC_OS_X_VERSION_10_2,GS_API_LATEST) 200 - (NSString *) operatingSystemVersionString; 201 #endif 202 203 /** 204 * Returns the process identifier number which uniquely identifies 205 * this process on this machine. 206 */ 207 - (int) processIdentifier; 208 #endif 209 210 /** 211 * Returns the process name for this process. This may have been set using 212 * the -setProcessName: method, or may be the default process name (the 213 * file name of the binary being executed). 214 */ 215 - (NSString*) processName; 216 217 /** 218 * Change the name of the current process to newName. 219 */ 220 - (void) setProcessName: (NSString*)newName; 221 222 #if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST) 223 /** Not implemented */ 224 - (NSUInteger) processorCount; 225 /** Not implemented */ 226 - (NSUInteger) activeProcessorCount; 227 /** Not implemented */ 228 - (unsigned long long) physicalMemory; 229 #endif 230 231 #if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST) 232 - (void) enableSuddenTermination; 233 - (void) disableSuddenTermination; 234 #endif 235 236 #if OS_API_VERSION(MAC_OS_X_VERSION_10_9,GS_API_LATEST) 237 DEFINE_BLOCK_TYPE_NO_ARGS(GSPerformActivityBlock, void); 238 DEFINE_BLOCK_TYPE(GSPerformExpiringActivityBlock, void, BOOL); 239 240 - (id) beginActivityWithOptions: (NSActivityOptions)options 241 reason: (NSString *)reason; 242 - (void) endActivity:(id<NSObject>)activity; 243 - (void) performActivityWithOptions:(NSActivityOptions)options 244 reason: (NSString *)reason 245 usingBlock: (GSPerformActivityBlock)block; 246 - (void) performExpiringActivityWithReason: (NSString *)reason 247 usingBlock: (GSPerformExpiringActivityBlock)block; 248 #endif 249 @end 250 251 #if GS_API_VERSION(GS_API_NONE,011700) 252 253 /** 254 * Provides GNUstep-specific methods for controlled debug logging (a GNUstep 255 * facility) and an internal/developer-related method. 256 */ 257 @interface NSProcessInfo (GNUstep) 258 259 /** 260 * Set the file to which NSLog output should be directed.<br /> 261 * Returns YES on success, NO on failure.<br /> 262 * By default logging goes to standard error. 263 */ 264 - (BOOL) setLogFile: (NSString*)path; 265 266 /** Obsolete ... the GSInitializeProcess() function has the same effect and 267 * can be called more easily from other languages (particularly C). 268 */ 269 + (void) initializeWithArguments: (char**)argv 270 count: (int)argc 271 environment: (char**)env; 272 273 #ifdef __ANDROID__ 274 - (jobject) androidContext; 275 - (NSString *) androidFilesDir; 276 - (NSString *) androidCacheDir; 277 #endif 278 279 @end 280 281 /** 282 * Fallback/override function.<br /> 283 * The developer must call this method to initialize 284 * the NSProcessInfo system if none of the system-specific hacks to 285 * auto-initialize it are working.<br /> 286 * It is also safe to call this function to override the effects 287 * of the automatic initialisation, which some applications may need 288 * to do when using GNUstep libraries embedded within other frameworks. 289 */ 290 GS_EXPORT void GSInitializeProcess(int argc, char **argv, char **envp); 291 292 #ifdef __ANDROID__ 293 /** 294 * Android process initialization function. 295 * This should be called on Android to initialize GNUstep with the JNI 296 * environment and application context, which is used to set up support 297 * for the Android data directory and asset loading via NSBundle. 298 */ 299 GS_EXPORT void GSInitializeProcessAndroid(JNIEnv *env, jobject context); 300 #endif 301 302 /** 303 * Function for rapid testing to see if a debug level is set.<br /> 304 * This is used by the debugging macros.<br /> 305 * If debug logging has been turned off, this returns NO even if 306 * the specified level exists in the set of debug levels. 307 */ 308 GS_EXPORT BOOL GSDebugSet(NSString *level); 309 310 #endif /* GS_API_NONE */ 311 312 #if defined(__cplusplus) 313 } 314 #endif 315 316 #if !NO_GNUSTEP && !defined(GNUSTEP_BASE_INTERNAL) 317 #import <GNUstepBase/NSProcessInfo+GNUstepBase.h> 318 #endif 319 320 #endif /* __NSProcessInfo_h_GNUSTEP_BASE_INCLUDE */ 321