NSProcessInfo.odin 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package objc_Foundation
  2. import "base:intrinsics"
  3. import "core:c"
  4. @(objc_class="NSProcessInfo")
  5. ProcessInfo :: struct {using _: Object}
  6. // Getting the Process Information Agent
  7. @(objc_type=ProcessInfo, objc_name="processInfo", objc_is_class_method=true)
  8. ProcessInfo_processInfo :: proc "c" () -> ^ProcessInfo {
  9. return msgSend(^ProcessInfo, ProcessInfo, "processInfo")
  10. }
  11. // Accessing Process Information
  12. @(objc_type=ProcessInfo, objc_name="arguments")
  13. ProcessInfo_arguments :: proc "c" (self: ^ProcessInfo) -> ^Array {
  14. return msgSend(^Array, self, "arguments")
  15. }
  16. @(objc_type=ProcessInfo, objc_name="environment")
  17. ProcessInfo_environment :: proc "c" (self: ^ProcessInfo) -> ^Dictionary {
  18. return msgSend(^Dictionary, self, "environment")
  19. }
  20. @(objc_type=ProcessInfo, objc_name="globallyUniqueString")
  21. ProcessInfo_globallyUniqueString :: proc "c" (self: ^ProcessInfo) -> ^String {
  22. return msgSend(^String, self, "globallyUniqueString")
  23. }
  24. @(objc_type=ProcessInfo, objc_name="isMacCatalystApp")
  25. ProcessInfo_isMacCatalystApp :: proc "c" (self: ^ProcessInfo) -> bool {
  26. return msgSend(bool, self, "isMacCatalystApp")
  27. }
  28. @(objc_type=ProcessInfo, objc_name="isiOSAppOnMac")
  29. ProcessInfo_isiOSAppOnMac :: proc "c" (self: ^ProcessInfo) -> bool {
  30. return msgSend(bool, self, "isiOSAppOnMac")
  31. }
  32. @(objc_type=ProcessInfo, objc_name="processIdentifier")
  33. ProcessInfo_processIdentifier :: proc "c" (self: ^ProcessInfo) -> c.int {
  34. return msgSend(c.int, self, "processIdentifier")
  35. }
  36. @(objc_type=ProcessInfo, objc_name="processName")
  37. ProcessInfo_processName :: proc "c" (self: ^ProcessInfo) -> ^String {
  38. return msgSend(^String, self, "processName")
  39. }
  40. // Accessing User Information
  41. @(objc_type=ProcessInfo, objc_name="userName")
  42. ProcessInfo_userName :: proc "c" (self: ^ProcessInfo) -> ^String {
  43. return msgSend(^String, self, "userName")
  44. }
  45. @(objc_type=ProcessInfo, objc_name="fullUserName")
  46. ProcessInfo_fullUserName :: proc "c" (self: ^ProcessInfo) -> ^String {
  47. return msgSend(^String, self, "fullUserName")
  48. }
  49. // Sudden Application Termination
  50. @(objc_type=ProcessInfo, objc_name="disableSuddenTermination")
  51. ProcessInfo_disableSuddenTermination :: proc "c" (self: ^ProcessInfo) {
  52. msgSend(nil, self, "disableSuddenTermination")
  53. }
  54. @(objc_type=ProcessInfo, objc_name="enableSuddenTermination")
  55. ProcessInfo_enableSuddenTermination :: proc "c" (self: ^ProcessInfo) {
  56. msgSend(nil, self, "enableSuddenTermination")
  57. }
  58. // Controlling Automatic Termination
  59. @(objc_type=ProcessInfo, objc_name="disableAutomaticTermination")
  60. ProcessInfo_disableAutomaticTermination :: proc "c" (self: ^ProcessInfo, reason: ^String) {
  61. msgSend(nil, self, "disableAutomaticTermination:", reason)
  62. }
  63. @(objc_type=ProcessInfo, objc_name="enableAutomaticTermination")
  64. ProcessInfo_enableAutomaticTermination :: proc "c" (self: ^ProcessInfo, reason: ^String) {
  65. msgSend(nil, self, "enableAutomaticTermination:", reason)
  66. }
  67. @(objc_type=ProcessInfo, objc_name="automaticTerminationSupportEnabled")
  68. ProcessInfo_automaticTerminationSupportEnabled :: proc "c" (self: ^ProcessInfo) -> bool {
  69. return msgSend(bool, self, "automaticTerminationSupportEnabled")
  70. }
  71. @(objc_type=ProcessInfo, objc_name="setAutomaticTerminationSupportEnabled")
  72. ProcessInfo_setAutomaticTerminationSupportEnabled :: proc "c" (self: ^ProcessInfo, automaticTerminationSupportEnabled: bool) {
  73. msgSend(nil, self, "setAutomaticTerminationSupportEnabled:", automaticTerminationSupportEnabled)
  74. }
  75. // Getting Host Information
  76. @(objc_type=ProcessInfo, objc_name="hostName")
  77. ProcessInfo_hostName :: proc "c" (self: ^ProcessInfo) -> ^String {
  78. return msgSend(^String, self, "hostName")
  79. }
  80. @(objc_type=ProcessInfo, objc_name="operatingSystemVersionString")
  81. ProcessInfo_operatingSystemVersionString :: proc "c" (self: ^ProcessInfo) -> ^String {
  82. return msgSend(^String, self, "operatingSystemVersionString")
  83. }
  84. @(objc_type=ProcessInfo, objc_name="operatingSystemVersion")
  85. ProcessInfo_operatingSystemVersion :: proc "c" (self: ^ProcessInfo) -> OperatingSystemVersion {
  86. return msgSend(OperatingSystemVersion, self, "operatingSystemVersion")
  87. }
  88. @(objc_type=ProcessInfo, objc_name="isOperatingSystemAtLeastVersion")
  89. ProcessInfo_isOperatingSystemAtLeastVersion :: proc "c" (self: ^ProcessInfo, version: OperatingSystemVersion) -> bool {
  90. return msgSend(bool, self, "isOperatingSystemAtLeastVersion:", version)
  91. }
  92. // Getting Computer Information
  93. @(objc_type=ProcessInfo, objc_name="processorCount")
  94. ProcessInfo_processorCount :: proc "c" (self: ^ProcessInfo) -> UInteger {
  95. return msgSend(UInteger, self, "processorCount")
  96. }
  97. @(objc_type=ProcessInfo, objc_name="activeProcessorCount")
  98. ProcessInfo_activeProcessorCount :: proc "c" (self: ^ProcessInfo) -> UInteger {
  99. return msgSend(UInteger, self, "activeProcessorCount")
  100. }
  101. @(objc_type=ProcessInfo, objc_name="physicalMemory")
  102. ProcessInfo_physicalMemory :: proc "c" (self: ^ProcessInfo) -> c.ulonglong {
  103. return msgSend(c.ulonglong, self, "physicalMemory")
  104. }
  105. @(objc_type=ProcessInfo, objc_name="systemUptime")
  106. ProcessInfo_systemUptime :: proc "c" (self: ^ProcessInfo) -> TimeInterval {
  107. return msgSend(TimeInterval, self, "systemUptime")
  108. }
  109. // Managing Activities
  110. @(private)
  111. log2 :: intrinsics.constant_log2
  112. ActivityOptionsBits :: enum u64 {
  113. IdleDisplaySleepDisabled = log2(1099511627776), // Require the screen to stay powered on.
  114. IdleSystemSleepDisabled = log2(1048576), // Prevent idle sleep.
  115. SuddenTerminationDisabled = log2(16384), // Prevent sudden termination.
  116. AutomaticTerminationDisabled = log2(32768), // Prevent automatic termination.
  117. AnimationTrackingEnabled = log2(35184372088832), // Track activity with an animation signpost interval.
  118. TrackingEnabled = log2(70368744177664), // Track activity with a signpost interval.
  119. UserInitiated = log2(16777215), // Performing a user-requested action.
  120. UserInitiatedAllowingIdleSystemSleep = log2(15728639), // Performing a user-requested action, but the system can sleep on idle.
  121. Background = log2(255), // Initiated some kind of work, but not as the direct result of a user request.
  122. LatencyCritical = log2(1095216660480), // Requires the highest amount of timer and I/O precision available.
  123. UserInteractive = log2(1095233437695), // Responding to user interaction.
  124. }
  125. ActivityOptions :: bit_set[ActivityOptionsBits; u64]
  126. @(objc_type=ProcessInfo, objc_name="beginActivityWithOptions")
  127. ProcessInfo_beginActivityWithOptions :: proc "c" (self: ^ProcessInfo, options: ActivityOptions, reason: ^String) -> ^ObjectProtocol {
  128. return msgSend(^ObjectProtocol, self, "beginActivityWithOptions:reason:", options, reason)
  129. }
  130. @(objc_type=ProcessInfo, objc_name="endActivity")
  131. ProcessInfo_endActivity :: proc "c" (self: ^ProcessInfo, activity: ^ObjectProtocol) {
  132. msgSend(nil, self, "endActivity:", activity)
  133. }
  134. @(objc_type=ProcessInfo, objc_name="performActivityWithOptions")
  135. ProcessInfo_performActivityWithOptions :: proc "c" (self: ^ProcessInfo, options: ActivityOptions, reason: ^String, block: proc "c" ()) {
  136. msgSend(nil, self, "performActivityWithOptions:reason:usingBlock:", options, reason, block)
  137. }
  138. @(objc_type=ProcessInfo, objc_name="performExpiringActivityWithReason")
  139. ProcessInfo_performExpiringActivityWithReason :: proc "c" (self: ^ProcessInfo, reason: ^String, block: proc "c" (expired: bool)) {
  140. msgSend(nil, self, "performExpiringActivityWithReason:usingBlock:", reason, block)
  141. }
  142. // Getting the Thermal State
  143. ProcessInfoThermalState :: enum c.long {
  144. Nominal,
  145. Fair,
  146. Serious,
  147. Critical,
  148. }
  149. @(objc_type=ProcessInfo, objc_name="thermalState")
  150. ProcessInfo_thermalState :: proc "c" (self: ^ProcessInfo) -> ProcessInfoThermalState {
  151. return msgSend(ProcessInfoThermalState, self, "thermalState")
  152. }
  153. // Determining Whether Low Power Mode is Enabled
  154. @(objc_type=ProcessInfo, objc_name="isLowPowerModeEnabled")
  155. ProcessInfo_isLowPowerModeEnabled :: proc "c" (self: ^ProcessInfo) -> bool {
  156. return msgSend(bool, self, "isLowPowerModeEnabled")
  157. }