CSProcessInfo – English Description

Deutsche Leser bitte nicht verwirren lassen: Erklärung folgt in Kürze!

CSProcessInfo is a standalone class containing NSProcessInfo, usable on macOS and iOs as well.

It is useful for requesting some system information and to avoid sleep or sudden termination, a feature the system uses to close down apps more quickly. Disallowing these functions gives you the means to finish longer lasting processes without having to fear that these could be interrupted by user or system requests.

On iOS, it is even possible to invoke real preemptive threads, but please be aware these need some kind of preparation and are not officially supported by Xojo. Also there are some limitations on what can be done in these threads. More below.

Where not noted otherwise, the properties and methods are available on both systems.

Important! This class needs Joe Ranieri’s ObjC Blocks plugin for macOS which can be found here.

How to get it

An encrypted demo version (unlimited but with a nag message box that appears in builds) is available here.

You can get a lifetime license (meaning a version without the nag screen and updated if anything should change in the future) by sending a PayPal payment of 10 € to bogun@satzservice.de, containing the message ProcessInfo.

You can get the unencoded Xojo code for 30 € the same way.

Disclaimer

This class is provided as-is, and it is important that you make sure you don’t try any not-allowed features with PerformExpiringActivity or your app will crash. Again, background threads are not officially supported by Xojo and could in theory stop working at some time. No serial included, no home phoning, no spying. I trust you and you can trust me.

Usage

Either drop an instance of the class on your window or iOSView or install it as a property:

Dim CSP as New CSProcessInfo

Important: CSProcessinfo installs a few notifications on itself, using NSNotificationCenter. This could cause circular references. On macOS, when using CSProcessInfo like a control dropped below a window layout, you need not worry. The class will remove these modifications once the parent window closes. In other cases (iOS or usage as a property), you should call the Unregister() method when you want to clear the memory fully.

Events

Open

Fires when the instance initialized.

Close

Fires on macOS when the control placed on a window layout is about to close.

StateChanged

On macOS: The thermal state has changed. (Since macOS 10.10.3)
On iOS: LowPowerMode has changed. (Since iOS 9.0)

Properties

ActiveProcessorCount As Integer

The number of active processing cores available on the computer. (read-only).
There are a number of different factors that may cause a core to not be active, including boot arguments, thermal throttling, or a manufacturing defect.
Available since macOS 10.5, iOS 2.0.

AutomaticTerminationSupportEnabled As Boolean

Whether the app supports automatic termination. without his property set to true, the methods Enable- and DisableAutomaticTermination have no function.
Available only on macOS since macOS 10.7.

Environment As Xojo.Core.Dictionary

A Dictionary containing variable names (keys) and their values in the environment from which the process was launched. (read-only). Available since macOS 10.0, iOS 2.0.

FullUserName as Text

The full name of the current user. (read-only) Available only on macOS since 10.12.

GloballyUniqueString As Text

Global unique identifier for the process. (read-only). Only available on macOS.

HostName as Text

The name of the host computer on which the process is executing. (read-only)

LowPowerModeEnabled as Boolean

Whether Low Power Mode is enabled on an iOS device. (read-only) Available since iOS 9.0. Changes fire the StateChanged event.

MajorVersion as Integer

The major version of the operating system on which the process is executing. (read-only)

MinorVersion as Integer

The minor version of the operating system on which the process is executing. (read-only)

OperatingSystemVersion as CSPropertyInfo.NSOperatingSystemVersion

The version of the operating system on which the process is executing. (read-only). The structure is MajorVersion As integer, MinorVersion As integer, PatchVersion As Integer.

OperatingSystemVersionString as Text

A string containing the version of the operating system on which the process is executing. (read-only)

PatchVersion as Integer

The patch version of the operating system on which the process is executing. (read-only)

PhysicalMemory as UInt64

The amount of physical memory on the computer in bytes. (read-only). Available since macOS 10.5, iOS 2.0.

ProcessIdentifier as Int32

The identifier of the process (often called process ID). (read-only)

ProcessName as Text

The name of the process.
User defaults and other aspects of the environment might depend on the process name, so be very careful if you change it.

ProcessorCount as Integer

The number of processing cores available on the computer. (read-only). Available since macOS 10.5, iOS 2.0.

SystemUptime as Double

The amount of time the system has been awake since the last time it was restarted. (read-only). Available since macOS 10.5, iOS 4.0.

ThermalState as CSProcessInfo.NSProcessInfoThermalState

The current thermal state of the system. (read-only). Only macOS since 10.10.3
States are nominal = 0, fair = 1, serious = 2 and critical = 3.

UserName as Text

The short name of the current user. (read-only) Available only on macOS since 10.12.

Methods

Arguments() as Text()

Returns an array of text with the command-line arguments for the process.

BeginActivity(LatencyCritical as Boolean, IdleSystemSleepDisabled as Boolean, IdleDisplaySleepDisabled as Boolean, SuddenTerminationDisabled as Boolean, AutomaticTerminationDisabled as Boolean, UserInitiated as Boolean, Background as boolean, Reason as CFStringRef) as Ptr

Begins an activity using the given options and reason. Returns a ptr to use in EndActivity. Available since macOS 10.9, iOS 7.
Use this method to prevent sleep or termination until you cast EndActivity.
latencyCritical: Flag to indicate the activity requires the highest amount of timer and I/O precision available.
idleDisplaySleepDisabled: Flag to require the screen to stay powered on.
idleSystemSleepDisabled: Flag to prevent idle sleep.
suddenTerminationDisabled: Flag to prevent sudden termination.
automaticTerminationDisabled: Flag to prevent automatic termination.
userInitiated: Flag to indicate the app is performing a user-requested action.
background: Flag to indicate the app has initiated some kind of work, but not as the direct result of user request.
reason: A string used in debugging to indicate the reason the activity began.

DisableAutomaticTermination(Reason as Cfstringref)

Disables automatic termination for the application. Available only on Mac since macOS 10.7. Reason: see above.
AutomaticTerminationSupportEnabled must be True!

DisableSuddenTermination()

Disables the application for quickly killing using sudden termination. Available only on Mac since macOS 10.6.

EnableAutomaticTermination(Reason as CfstringRef)

Enables automatic termination for the application. Available only on Mac since macOS 10.7.
AutomaticTerminationSupportEnabled must be True!

EnableSuddenTermination()

Enables the application for quickly killing using sudden termination. Available only on Mac since macOS 10.6.

EndActivity(Activity As Ptr)

Ends the given activity started with BeginActivity. Pass the Ptr BeginActivity has returned. Available since iOS 7, macOS 10.9.

PerformActivity(LatencyCritical as Boolean, IdleSystemSleepDisabled as Boolean, IdleDisplaySleepDisabled as Boolean, SuddenTerminationDisabled as Boolean, AutomaticTerminationDisabled as Boolean, UserInitiated as Boolean, Background as boolean, Reason as CFStringRef, BlockHandle as Ptr) as Ptr

Synchronously performs an activity defined by a given block using the given options. (In general this is pretty much like BeginActivity/EndActivity except that you define a block that is run instead of falling the methods mentioned above.)
Available since macOS 10.9, iOS 7.
latencyCritical: Flag to indicate the activity requires the highest amount of timer and I/O precision available.
idleDisplaySleepDisabled: Flag to require the screen to stay powered on.
idleSystemSleepDisabled: Flag to prevent idle sleep.
suddenTerminationDisabled: Flag to prevent sudden termination.
automaticTerminationDisabled: Flag to prevent automatic termination.
userInitiated: Flag to indicate the app is performing a user-requested action.
background: Flag to indicate the app has initiated some kind of work, but not as the direct result of user request.
reason: A string used in debugging to indicate the reason the activity began.
Blockhandle must be the handle of an ObjC- or iOSBlock built from a method without in- and output parameters.

PerformExpiringActivity(Reason as CFStringRef, Block as iOSBlock)

Performs the specified block asynchronously(!) – on a background thread! –  and notifies you if the process is about to be suspended. Avialable only on iOS since 8.2.
Reason is a string used for debugging purposes.

Block must be an iOSBlock created from a method with a boolean input parameter which signals that the activity is about to expire and without output parameters and disable nilobjectChecking, Backgroundtasks and StackoverflowChecking and not use any objects except for those declared as ptr internally. You can address class properties, but not instance properties.

SystemVersionIsAtLeast(majorversion as integer, minorversion as integer = 0, patchversion as integer = 0) as Boolean

Returns a Boolean that indicates if the current system version is equal or higher than the specified version.

Unregister()

Use this method to unregister the class on iOS or also on macOS if you used it as property without a containing window on macOS to avoid circular references and memory leaks.

Ein Gedanke zu “CSProcessInfo – English Description

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s