Path: blob/master/thirdparty/metal-cpp/Foundation/NSProcessInfo.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Foundation/NSProcessInfo.hpp3//4// Copyright 2020-2024 Apple Inc.5//6// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.17//18//-------------------------------------------------------------------------------------------------------------------------------------------------------------1920#pragma once2122//-------------------------------------------------------------------------------------------------------------------------------------------------------------2324#include "NSDefines.hpp"25#include "NSNotification.hpp"26#include "NSObject.hpp"27#include "NSPrivate.hpp"28#include "NSTypes.hpp"2930#include <functional>3132//-------------------------------------------------------------------------------------------------------------------------------------------------------------3334namespace NS35{36_NS_CONST(NotificationName, ProcessInfoThermalStateDidChangeNotification);37_NS_CONST(NotificationName, ProcessInfoPowerStateDidChangeNotification);38_NS_CONST(NotificationName, ProcessInfoPerformanceProfileDidChangeNotification);3940_NS_ENUM(NS::Integer, ProcessInfoThermalState) {41ProcessInfoThermalStateNominal = 0,42ProcessInfoThermalStateFair = 1,43ProcessInfoThermalStateSerious = 2,44ProcessInfoThermalStateCritical = 345};4647_NS_OPTIONS(std::uint64_t, ActivityOptions) {48ActivityIdleDisplaySleepDisabled = (1ULL << 40),49ActivityIdleSystemSleepDisabled = (1ULL << 20),50ActivitySuddenTerminationDisabled = (1ULL << 14),51ActivityAutomaticTerminationDisabled = (1ULL << 15),52ActivityUserInitiated = (0x00FFFFFFULL | ActivityIdleSystemSleepDisabled),53ActivityUserInitiatedAllowingIdleSystemSleep = (ActivityUserInitiated & ~ActivityIdleSystemSleepDisabled),54ActivityBackground = 0x000000FFULL,55ActivityLatencyCritical = 0xFF00000000ULL,56};5758typedef NS::Integer DeviceCertification;59_NS_CONST(DeviceCertification, DeviceCertificationiPhonePerformanceGaming);6061typedef NS::Integer ProcessPerformanceProfile;62_NS_CONST(ProcessPerformanceProfile, ProcessPerformanceProfileDefault);63_NS_CONST(ProcessPerformanceProfile, ProcessPerformanceProfileSustained);6465class ProcessInfo : public Referencing<ProcessInfo>66{67public:68static ProcessInfo* processInfo();6970class Array* arguments() const;71class Dictionary* environment() const;72class String* hostName() const;73class String* processName() const;74void setProcessName(const String* pString);75int processIdentifier() const;76class String* globallyUniqueString() const;7778class String* userName() const;79class String* fullUserName() const;8081UInteger operatingSystem() const;82OperatingSystemVersion operatingSystemVersion() const;83class String* operatingSystemVersionString() const;84bool isOperatingSystemAtLeastVersion(OperatingSystemVersion version) const;8586UInteger processorCount() const;87UInteger activeProcessorCount() const;88unsigned long long physicalMemory() const;89TimeInterval systemUptime() const;9091void disableSuddenTermination();92void enableSuddenTermination();9394void disableAutomaticTermination(const class String* pReason);95void enableAutomaticTermination(const class String* pReason);96bool automaticTerminationSupportEnabled() const;97void setAutomaticTerminationSupportEnabled(bool enabled);9899class Object* beginActivity(ActivityOptions options, const class String* pReason);100void endActivity(class Object* pActivity);101void performActivity(ActivityOptions options, const class String* pReason, void (^block)(void));102void performActivity(ActivityOptions options, const class String* pReason, const std::function<void()>& func);103void performExpiringActivity(const class String* pReason, void (^block)(bool expired));104void performExpiringActivity(const class String* pReason, const std::function<void(bool expired)>& func);105106ProcessInfoThermalState thermalState() const;107bool isLowPowerModeEnabled() const;108109bool isiOSAppOnMac() const;110bool isMacCatalystApp() const;111112bool isDeviceCertified(DeviceCertification performanceTier) const;113bool hasPerformanceProfile(ProcessPerformanceProfile performanceProfile) const;114115};116}117118//-------------------------------------------------------------------------------------------------------------------------------------------------------------119120_NS_PRIVATE_DEF_CONST(NS::NotificationName, ProcessInfoThermalStateDidChangeNotification);121_NS_PRIVATE_DEF_CONST(NS::NotificationName, ProcessInfoPowerStateDidChangeNotification);122123// The linker searches for these symbols in the Metal framework, be sure to link it in as well:124_NS_PRIVATE_DEF_CONST(NS::NotificationName, ProcessInfoPerformanceProfileDidChangeNotification);125_NS_PRIVATE_DEF_CONST(NS::DeviceCertification, DeviceCertificationiPhonePerformanceGaming);126_NS_PRIVATE_DEF_CONST(NS::ProcessPerformanceProfile, ProcessPerformanceProfileDefault);127_NS_PRIVATE_DEF_CONST(NS::ProcessPerformanceProfile, ProcessPerformanceProfileSustained);128129//-------------------------------------------------------------------------------------------------------------------------------------------------------------130131_NS_INLINE NS::ProcessInfo* NS::ProcessInfo::processInfo()132{133return Object::sendMessage<ProcessInfo*>(_NS_PRIVATE_CLS(NSProcessInfo), _NS_PRIVATE_SEL(processInfo));134}135136//-------------------------------------------------------------------------------------------------------------------------------------------------------------137138_NS_INLINE NS::Array* NS::ProcessInfo::arguments() const139{140return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(arguments));141}142143//-------------------------------------------------------------------------------------------------------------------------------------------------------------144145_NS_INLINE NS::Dictionary* NS::ProcessInfo::environment() const146{147return Object::sendMessage<Dictionary*>(this, _NS_PRIVATE_SEL(environment));148}149150//-------------------------------------------------------------------------------------------------------------------------------------------------------------151152_NS_INLINE NS::String* NS::ProcessInfo::hostName() const153{154return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(hostName));155}156157//-------------------------------------------------------------------------------------------------------------------------------------------------------------158159_NS_INLINE NS::String* NS::ProcessInfo::processName() const160{161return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(processName));162}163164//-------------------------------------------------------------------------------------------------------------------------------------------------------------165166_NS_INLINE void NS::ProcessInfo::setProcessName(const String* pString)167{168Object::sendMessage<void>(this, _NS_PRIVATE_SEL(setProcessName_), pString);169}170171//-------------------------------------------------------------------------------------------------------------------------------------------------------------172173_NS_INLINE int NS::ProcessInfo::processIdentifier() const174{175return Object::sendMessage<int>(this, _NS_PRIVATE_SEL(processIdentifier));176}177178//-------------------------------------------------------------------------------------------------------------------------------------------------------------179180_NS_INLINE NS::String* NS::ProcessInfo::globallyUniqueString() const181{182return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(globallyUniqueString));183}184185//-------------------------------------------------------------------------------------------------------------------------------------------------------------186187_NS_INLINE NS::String* NS::ProcessInfo::userName() const188{189return Object::sendMessageSafe<String*>(this, _NS_PRIVATE_SEL(userName));190}191192//-------------------------------------------------------------------------------------------------------------------------------------------------------------193194_NS_INLINE NS::String* NS::ProcessInfo::fullUserName() const195{196return Object::sendMessageSafe<String*>(this, _NS_PRIVATE_SEL(fullUserName));197}198199//-------------------------------------------------------------------------------------------------------------------------------------------------------------200201_NS_INLINE NS::UInteger NS::ProcessInfo::operatingSystem() const202{203return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(operatingSystem));204}205206//-------------------------------------------------------------------------------------------------------------------------------------------------------------207208_NS_INLINE NS::OperatingSystemVersion NS::ProcessInfo::operatingSystemVersion() const209{210return Object::sendMessage<OperatingSystemVersion>(this, _NS_PRIVATE_SEL(operatingSystemVersion));211}212213//-------------------------------------------------------------------------------------------------------------------------------------------------------------214215_NS_INLINE NS::String* NS::ProcessInfo::operatingSystemVersionString() const216{217return Object::sendMessage<String*>(this, _NS_PRIVATE_SEL(operatingSystemVersionString));218}219220//-------------------------------------------------------------------------------------------------------------------------------------------------------------221222_NS_INLINE bool NS::ProcessInfo::isOperatingSystemAtLeastVersion(OperatingSystemVersion version) const223{224return Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(isOperatingSystemAtLeastVersion_), version);225}226227//-------------------------------------------------------------------------------------------------------------------------------------------------------------228229_NS_INLINE NS::UInteger NS::ProcessInfo::processorCount() const230{231return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(processorCount));232}233234//-------------------------------------------------------------------------------------------------------------------------------------------------------------235236_NS_INLINE NS::UInteger NS::ProcessInfo::activeProcessorCount() const237{238return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(activeProcessorCount));239}240241//-------------------------------------------------------------------------------------------------------------------------------------------------------------242243_NS_INLINE unsigned long long NS::ProcessInfo::physicalMemory() const244{245return Object::sendMessage<unsigned long long>(this, _NS_PRIVATE_SEL(physicalMemory));246}247248//-------------------------------------------------------------------------------------------------------------------------------------------------------------249250_NS_INLINE NS::TimeInterval NS::ProcessInfo::systemUptime() const251{252return Object::sendMessage<TimeInterval>(this, _NS_PRIVATE_SEL(systemUptime));253}254255//-------------------------------------------------------------------------------------------------------------------------------------------------------------256257_NS_INLINE void NS::ProcessInfo::disableSuddenTermination()258{259Object::sendMessageSafe<void>(this, _NS_PRIVATE_SEL(disableSuddenTermination));260}261262//-------------------------------------------------------------------------------------------------------------------------------------------------------------263264_NS_INLINE void NS::ProcessInfo::enableSuddenTermination()265{266Object::sendMessageSafe<void>(this, _NS_PRIVATE_SEL(enableSuddenTermination));267}268269//-------------------------------------------------------------------------------------------------------------------------------------------------------------270271_NS_INLINE void NS::ProcessInfo::disableAutomaticTermination(const String* pReason)272{273Object::sendMessageSafe<void>(this, _NS_PRIVATE_SEL(disableAutomaticTermination_), pReason);274}275276//-------------------------------------------------------------------------------------------------------------------------------------------------------------277278_NS_INLINE void NS::ProcessInfo::enableAutomaticTermination(const String* pReason)279{280Object::sendMessageSafe<void>(this, _NS_PRIVATE_SEL(enableAutomaticTermination_), pReason);281}282283//-------------------------------------------------------------------------------------------------------------------------------------------------------------284285_NS_INLINE bool NS::ProcessInfo::automaticTerminationSupportEnabled() const286{287return Object::sendMessageSafe<bool>(this, _NS_PRIVATE_SEL(automaticTerminationSupportEnabled));288}289290//-------------------------------------------------------------------------------------------------------------------------------------------------------------291292_NS_INLINE void NS::ProcessInfo::setAutomaticTerminationSupportEnabled(bool enabled)293{294Object::sendMessageSafe<void>(this, _NS_PRIVATE_SEL(setAutomaticTerminationSupportEnabled_), enabled);295}296297//-------------------------------------------------------------------------------------------------------------------------------------------------------------298299_NS_INLINE NS::Object* NS::ProcessInfo::beginActivity(ActivityOptions options, const String* pReason)300{301return Object::sendMessage<Object*>(this, _NS_PRIVATE_SEL(beginActivityWithOptions_reason_), options, pReason);302}303304//-------------------------------------------------------------------------------------------------------------------------------------------------------------305306_NS_INLINE void NS::ProcessInfo::endActivity(Object* pActivity)307{308Object::sendMessage<void>(this, _NS_PRIVATE_SEL(endActivity_), pActivity);309}310311//-------------------------------------------------------------------------------------------------------------------------------------------------------------312313_NS_INLINE void NS::ProcessInfo::performActivity(ActivityOptions options, const String* pReason, void (^block)(void))314{315Object::sendMessage<void>(this, _NS_PRIVATE_SEL(performActivityWithOptions_reason_usingBlock_), options, pReason, block);316}317318//-------------------------------------------------------------------------------------------------------------------------------------------------------------319320_NS_INLINE void NS::ProcessInfo::performActivity(ActivityOptions options, const String* pReason, const std::function<void()>& function)321{322__block std::function<void()> blockFunction = function;323324performActivity(options, pReason, ^() { blockFunction(); });325}326327//-------------------------------------------------------------------------------------------------------------------------------------------------------------328329_NS_INLINE void NS::ProcessInfo::performExpiringActivity(const String* pReason, void (^block)(bool expired))330{331Object::sendMessageSafe<void>(this, _NS_PRIVATE_SEL(performExpiringActivityWithReason_usingBlock_), pReason, block);332}333334//-------------------------------------------------------------------------------------------------------------------------------------------------------------335336_NS_INLINE void NS::ProcessInfo::performExpiringActivity(const String* pReason, const std::function<void(bool expired)>& function)337{338__block std::function<void(bool expired)> blockFunction = function;339340performExpiringActivity(pReason, ^(bool expired) { blockFunction(expired); });341}342343//-------------------------------------------------------------------------------------------------------------------------------------------------------------344345_NS_INLINE NS::ProcessInfoThermalState NS::ProcessInfo::thermalState() const346{347return Object::sendMessage<ProcessInfoThermalState>(this, _NS_PRIVATE_SEL(thermalState));348}349350//-------------------------------------------------------------------------------------------------------------------------------------------------------------351352_NS_INLINE bool NS::ProcessInfo::isLowPowerModeEnabled() const353{354return Object::sendMessageSafe<bool>(this, _NS_PRIVATE_SEL(isLowPowerModeEnabled));355}356357//-------------------------------------------------------------------------------------------------------------------------------------------------------------358359_NS_INLINE bool NS::ProcessInfo::isiOSAppOnMac() const360{361return Object::sendMessageSafe<bool>(this, _NS_PRIVATE_SEL(isiOSAppOnMac));362}363364//-------------------------------------------------------------------------------------------------------------------------------------------------------------365366_NS_INLINE bool NS::ProcessInfo::isMacCatalystApp() const367{368return Object::sendMessageSafe<bool>(this, _NS_PRIVATE_SEL(isMacCatalystApp));369}370371//-------------------------------------------------------------------------------------------------------------------------------------------------------------372373_NS_INLINE bool NS::ProcessInfo::isDeviceCertified(DeviceCertification performanceTier) const374{375return Object::sendMessageSafe<bool>(this, _NS_PRIVATE_SEL(isDeviceCertified_), performanceTier);376}377378//-------------------------------------------------------------------------------------------------------------------------------------------------------------379380_NS_INLINE bool NS::ProcessInfo::hasPerformanceProfile(ProcessPerformanceProfile performanceProfile) const381{382return Object::sendMessageSafe<bool>(this, _NS_PRIVATE_SEL(hasPerformanceProfile_), performanceProfile);383}384385//-------------------------------------------------------------------------------------------------------------------------------------------------------------386387388