powersources

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package powersources provides purego-based Go bindings for the macOS PowerSources framework.

Apple documentation: https://developer.apple.com/documentation/powersources

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IOPSCopyExternalPowerAdapterDetails

func IOPSCopyExternalPowerAdapterDetails() unsafe.Pointer

@function IOPSCopyExternalPowerAdapterDetails @abstract Returns a CFDictionary that describes the attached (AC) external power adapter (if any external power adapter is attached. @discussion Use the kIOPSPowerAdapter... keys described in IOPSKeys.h to interpret the returned CFDictionary. @result Returns a CFDictionary on success. Caller must release the returned dictionary. If no adapter is attached, or if there's an error, returns NULL.

func IOPSCopyPowerSourcesInfo

func IOPSCopyPowerSourcesInfo() unsafe.Pointer

@function IOPSCopyPowerSourcesInfo @abstract Returns a blob of Power Source information in an opaque CFTypeRef. @discussion Clients should not directly access data in the returned CFTypeRef - they should use the accessor functions IOPSCopyPowerSourcesList and IOPSGetPowerSourceDescription, instead. @result NULL if errors were encountered, a CFTypeRef otherwise. Caller must CFRelease() the return value when done accessing it.

func IOPSCopyPowerSourcesList

func IOPSCopyPowerSourcesList(blob unsafe.Pointer) unsafe.Pointer

@function IOPSCopyPowerSourcesList @abstract Returns a CFArray of Power Source handles, each of type CFTypeRef. @discussion The caller shouldn't directly access the CFTypeRefs, but should use IOPSGetPowerSourceDescription on each member of the CFArrayRef. @param blob Takes the CFTypeRef returned by IOPSCopyPowerSourcesInfo() @result Returns NULL if errors were encountered, otherwise a CFArray of CFTypeRefs. Caller must CFRelease() the returned CFArrayRef.

func IOPSCreateLimitedPowerNotification

func IOPSCreateLimitedPowerNotification(callback unsafe.Pointer, context_ unsafe.Pointer) unsafe.Pointer

@function IOPSCreateLimitedPowerNotification @abstract Returns a CFRunLoopSourceRef that notifies the caller when power source changes from an unlimited power source (like attached to wall, car, or airplane power), to a limited power source (like a battery or UPS). @discussion Returns a CFRunLoopSourceRef for scheduling with your CFRunLoop. If your project does not use a CFRunLoop, you can alternatively receive this notification via <code>notify.h</code> using the name <code>@link kIOPSNotifyPowerSource @/link</code> @param callback A function to be called whenever the power source changes from AC to DC.. @param context Any user-defined pointer, passed to the IOPowerSource callback. @result Returns NULL if an error was encountered, otherwise a CFRunLoopSource. Caller must release the CFRunLoopSource.

func IOPSGetPowerSourceDescription

func IOPSGetPowerSourceDescription(blob unsafe.Pointer, ps unsafe.Pointer) unsafe.Pointer

@function IOPSGetPowerSourceDescription @abstract Returns a CFDictionary with readable information about the specific power source. @discussion See the C-strings defined in IOPSKeys.h for specific keys into the dictionary. Don't expect all keys to be present in any dictionary. Some power sources, for example, may not support the "Time Remaining To Empty" key and it will not be present in their dictionaries. @param blob The CFTypeRef returned by IOPSCopyPowerSourcesInfo() @param ps One of the CFTypeRefs in the CFArray returned by IOPSCopyPowerSourcesList() @result Returns NULL if an error was encountered, otherwise a CFDictionary. Caller should NOT release the returned CFDictionary - it will be released as part of the CFTypeRef returned by IOPSCopyPowerSourcesInfo().

func IOPSGetProvidingPowerSourceType

func IOPSGetProvidingPowerSourceType(snapshot unsafe.Pointer) unsafe.Pointer

@function IOPSGetProvidingPowerSourceType @abstract Indicates the power source the computer is currently drawing from. @discussion Determines which power source is providing power. @param snapshot The CFTypeRef returned by IOPSCopyPowerSourcesInfo() @result One of: CFSTR(kIOPMACPowerKey), CFSTR(kIOPMBatteryPowerKey), CFSTR(kIOPMUPSPowerKey)

func IOPSGetTimeRemainingEstimate

func IOPSGetTimeRemainingEstimate() float64

@function IOPSGetTimeRemainingEstimate @abstract Returns the estimated minutes remaining until all power sources (battery and/or UPS's) are empty, or returns <code>@link kIOPSTimeRemainingUnlimited@/link </code> if attached to an unlimited power source. @discussion If attached to an "Unlimited" power source, like AC power or any external source, the return value is <code>@link kIOPSTimeRemainingUnlimited@/link </code> If the system is on "Limited" power, like a battery or UPS, but is still calculating the time remaining, which may take several seconds after each system power event (e.g. waking from sleep, or unplugging AC Power), the return value is <code>@link kIOPSTimeRemainingUnknown@/link </code> Otherwise, if the system is on "Limited" power and the system has an accurate time remaining estimate, the system returns a CFTimeInterval estimate of the time remaining until the system is out of battery power. If you require more detailed battery information, use <code>@link IOPSCopyPowerSourcesInfo @/link></code> and <code>@link IOPSGetPowerSourceDescription @/link></code>. @result Returns <code>@link kIOPSTimeRemainingUnknown@/link</code> if the OS cannot determine the time remaining. Returns <code>@link kIOPSTimeRemainingUnlimited@/link</code> if the system has an unlimited power source. Otherwise returns a positive number of type CFTimeInterval, indicating the time remaining in seconds until all power sources are depleted.

func IOPSNotificationCreateRunLoopSource

func IOPSNotificationCreateRunLoopSource(callback unsafe.Pointer, context_ unsafe.Pointer) unsafe.Pointer

@function IOPSNotificationCreateRunLoopSource @abstract Returns a CFRunLoopSourceRef that notifies the caller when power source information changes. @discussion Returns a CFRunLoopSourceRef for scheduling with your CFRunLoop. If your project does not use a CFRunLoop, you can alternatively receive notifications via mach port, dispatch, or signal, via <code>notify.h</code> using the name <code>@link kIOPSTimeRemainingNotificationKey @/link</code>. IOKit delivers this notification when percent remaining or time remaining changes. Thus it fires fairly frequently while discharging or charging the battery; please consider using: <code>@link IOPSCreateLimitedPowerNotification @/link</code> if you only require notifications when the power source type changes from limited to unlimited. @param callback A function to be called whenever any power source is added, removed, or changes. @param context Any user-defined pointer, passed to the IOPowerSource callback. @result Returns NULL if an error was encountered, otherwise a CFRunLoopSource. Caller must release the CFRunLoopSource.

func SymbolAvailable

func SymbolAvailable(symbol string) bool

SymbolAvailable reports whether the named C symbol was bound when the library loaded. Calling a generated wrapper whose symbol is unavailable dereferences a nil function variable and panics.

Types

type Acl_entry_id_t

type Acl_entry_id_t int64
const (
	ACL_FIRST_ENTRY Acl_entry_id_t = 0
	ACL_NEXT_ENTRY  Acl_entry_id_t = -1
	ACL_LAST_ENTRY  Acl_entry_id_t = -2
)

func (Acl_entry_id_t) String

func (e Acl_entry_id_t) String() string

type Acl_flag_t

type Acl_flag_t int64
const (
	ACL_FLAG_DEFER_INHERIT      Acl_flag_t = 1
	ACL_FLAG_NO_INHERIT         Acl_flag_t = 131072
	ACL_ENTRY_INHERITED         Acl_flag_t = 16
	ACL_ENTRY_FILE_INHERIT      Acl_flag_t = 32
	ACL_ENTRY_DIRECTORY_INHERIT Acl_flag_t = 64
	ACL_ENTRY_LIMIT_INHERIT     Acl_flag_t = 128
	ACL_ENTRY_ONLY_INHERIT      Acl_flag_t = 256
)

func (Acl_flag_t) String

func (e Acl_flag_t) String() string

type Acl_perm_t

type Acl_perm_t int64
const (
	ACL_READ_DATA           Acl_perm_t = 2
	ACL_LIST_DIRECTORY      Acl_perm_t = 2
	ACL_WRITE_DATA          Acl_perm_t = 4
	ACL_ADD_FILE            Acl_perm_t = 4
	ACL_EXECUTE             Acl_perm_t = 8
	ACL_SEARCH              Acl_perm_t = 8
	ACL_DELETE              Acl_perm_t = 16
	ACL_APPEND_DATA         Acl_perm_t = 32
	ACL_ADD_SUBDIRECTORY    Acl_perm_t = 32
	ACL_DELETE_CHILD        Acl_perm_t = 64
	ACL_READ_ATTRIBUTES     Acl_perm_t = 128
	ACL_WRITE_ATTRIBUTES    Acl_perm_t = 256
	ACL_READ_EXTATTRIBUTES  Acl_perm_t = 512
	ACL_WRITE_EXTATTRIBUTES Acl_perm_t = 1024
	ACL_READ_SECURITY       Acl_perm_t = 2048
	ACL_WRITE_SECURITY      Acl_perm_t = 4096
	ACL_CHANGE_OWNER        Acl_perm_t = 8192
	ACL_SYNCHRONIZE         Acl_perm_t = 1048576
)

func (Acl_perm_t) String

func (e Acl_perm_t) String() string

type Acl_tag_t

type Acl_tag_t int64
const (
	ACL_UNDEFINED_TAG  Acl_tag_t = 0
	ACL_EXTENDED_ALLOW Acl_tag_t = 1
	ACL_EXTENDED_DENY  Acl_tag_t = 2
)

func (Acl_tag_t) String

func (e Acl_tag_t) String() string

type Acl_type_t

type Acl_type_t int64
const (
	ACL_TYPE_EXTENDED Acl_type_t = 256
	ACL_TYPE_ACCESS   Acl_type_t = 0
	ACL_TYPE_DEFAULT  Acl_type_t = 1
	ACL_TYPE_AFS      Acl_type_t = 2
	ACL_TYPE_CODA     Acl_type_t = 3
	ACL_TYPE_NTFS     Acl_type_t = 4
	ACL_TYPE_NWFS     Acl_type_t = 5
)

func (Acl_type_t) String

func (e Acl_type_t) String() string

type Clockid_t

type Clockid_t int64

func (Clockid_t) String

func (e Clockid_t) String() string

type Dispatch_autorelease_frequency_t

type Dispatch_autorelease_frequency_t uint64
const (
	DISPATCH_AUTORELEASE_FREQUENCY_INHERIT   Dispatch_autorelease_frequency_t = 0
	DISPATCH_AUTORELEASE_FREQUENCY_WORK_ITEM Dispatch_autorelease_frequency_t = 1
	DISPATCH_AUTORELEASE_FREQUENCY_NEVER     Dispatch_autorelease_frequency_t = 2
)

func (Dispatch_autorelease_frequency_t) String

type Dispatch_block_flags_t

type Dispatch_block_flags_t uint64
const (
	DISPATCH_BLOCK_BARRIER           Dispatch_block_flags_t = 1
	DISPATCH_BLOCK_DETACHED          Dispatch_block_flags_t = 2
	DISPATCH_BLOCK_ASSIGN_CURRENT    Dispatch_block_flags_t = 4
	DISPATCH_BLOCK_NO_QOS_CLASS      Dispatch_block_flags_t = 8
	DISPATCH_BLOCK_INHERIT_QOS_CLASS Dispatch_block_flags_t = 16
	DISPATCH_BLOCK_ENFORCE_QOS_CLASS Dispatch_block_flags_t = 32
)

func (Dispatch_block_flags_t) String

func (e Dispatch_block_flags_t) String() string

type Filesec_property_t

type Filesec_property_t int64
const (
	FILESEC_OWNER         Filesec_property_t = 1
	FILESEC_GROUP         Filesec_property_t = 2
	FILESEC_UUID          Filesec_property_t = 3
	FILESEC_MODE          Filesec_property_t = 4
	FILESEC_ACL           Filesec_property_t = 5
	FILESEC_GRPUUID       Filesec_property_t = 6
	FILESEC_ACL_RAW       Filesec_property_t = 100
	FILESEC_ACL_ALLOCSIZE Filesec_property_t = 101
)

func (Filesec_property_t) String

func (e Filesec_property_t) String() string

type IOPSLowBatteryWarningLevel

type IOPSLowBatteryWarningLevel int64

@enum IOPSLowBatteryWarningLevel @discussion Possible return values from <code>@link IOPSGetBatteryWarningLevel@/link</code>

const (
	// @constant   kIOPSLowBatteryWarningNone @abstract   The system is not in a low battery situation, or is on drawing from an external power source. @discussion The system displays no low power warnings; neither should application clients of this API.
	KIOPSLowBatteryWarningNone IOPSLowBatteryWarningLevel = 1
	// @constant   kIOPSLowBatteryWarningEarly @abstract   The battery can provide no more than 20 minutes of runtime. @discussion OS X makes no guarantees that the system shall remain in Early Warning for 20 minutes. Batteries are frequently calibrated differently and may provide runtime for more, or less, than the estimated 20 minutes. OS X alerts the user by changing the color of BatteryMonitor to red. Warning the user is optional for full screen apps.
	KIOPSLowBatteryWarningEarly IOPSLowBatteryWarningLevel = 2
	// @constant   kIOPSLowBatteryWarningFinal @abstract   The battery can provide no more than 10 minutes of runtime. @discussion OS X makes no guarantees that the system shall remain in Final Warning for 10 minutes. Batteries are frequently calibrated differently and may provide runtime for more, or less, than the estimated 10 minutes.
	KIOPSLowBatteryWarningFinal IOPSLowBatteryWarningLevel = 3
)

func IOPSGetBatteryWarningLevel

func IOPSGetBatteryWarningLevel() IOPSLowBatteryWarningLevel

@function IOPSGetBatteryWarningLevel @abstract Indicates whether the system is at a low battery warning level. @discussion If your app runs in full screen mode and occludes OS X's battery monitor's low battery warnings, you should alert the user at least when the system is in kIOPSLowBatteryWarnFinal.

func (IOPSLowBatteryWarningLevel) String

type Idtype_t

type Idtype_t int64
const (
	P_ALL  Idtype_t = 0
	P_PID  Idtype_t = 1
	P_PGID Idtype_t = 2
)

func (Idtype_t) String

func (e Idtype_t) String() string

type Mpo_flags_t

type Mpo_flags_t int64
const (
	MPO_PORT                            Mpo_flags_t = 0
	MPO_SERVICE_PORT                    Mpo_flags_t = 1024
	MPO_CONNECTION_PORT                 Mpo_flags_t = 2048
	MPO_REPLY_PORT                      Mpo_flags_t = 4096
	MPO_WEAK_REPLY_PORT                 Mpo_flags_t = 16384
	MPO_NOTIFICATION_PORT               Mpo_flags_t = 17408
	MPO_EXCEPTION_PORT                  Mpo_flags_t = 32768
	MPO_CONNECTION_PORT_WITH_PORT_ARRAY Mpo_flags_t = 65536
)

func (Mpo_flags_t) String

func (e Mpo_flags_t) String() string

type Os_clockid_t

type Os_clockid_t int64
const (
	OS_CLOCK_MACH_ABSOLUTE_TIME Os_clockid_t = 32
)

func (Os_clockid_t) String

func (e Os_clockid_t) String() string

type Ptrauth_key

type Ptrauth_key int64
const (
	Ptrauth_key_none                     Ptrauth_key = -1
	Ptrauth_key_asia                     Ptrauth_key = 0
	Ptrauth_key_asib                     Ptrauth_key = 1
	Ptrauth_key_asda                     Ptrauth_key = 2
	Ptrauth_key_asdb                     Ptrauth_key = 3
	Ptrauth_key_process_independent_code Ptrauth_key = 0
	Ptrauth_key_process_dependent_code   Ptrauth_key = 1
	Ptrauth_key_process_independent_data Ptrauth_key = 2
	Ptrauth_key_process_dependent_data   Ptrauth_key = 3
	Ptrauth_key_return_address           Ptrauth_key = 1
	Ptrauth_key_frame_pointer            Ptrauth_key = 3
	Ptrauth_key_function_pointer         Ptrauth_key = 0
	Ptrauth_key_block_function           Ptrauth_key = 0
	Ptrauth_key_cxx_vtable_pointer       Ptrauth_key = 2
	Ptrauth_key_method_list_pointer      Ptrauth_key = 2
	Ptrauth_key_objc_isa_pointer         Ptrauth_key = 2
	Ptrauth_key_objc_super_pointer       Ptrauth_key = 2
	Ptrauth_key_objc_sel_pointer         Ptrauth_key = 3
	Ptrauth_key_objc_class_ro_pointer    Ptrauth_key = 2
	Ptrauth_key_block_descriptor_pointer Ptrauth_key = 2
	Ptrauth_key_init_fini_pointer        Ptrauth_key = 0
)

func (Ptrauth_key) String

func (e Ptrauth_key) String() string

type Qos_class_t

type Qos_class_t uint32
const (
	QOS_CLASS_USER_INTERACTIVE Qos_class_t = 33
	QOS_CLASS_USER_INITIATED   Qos_class_t = 25
	QOS_CLASS_DEFAULT          Qos_class_t = 21
	QOS_CLASS_UTILITY          Qos_class_t = 17
	QOS_CLASS_BACKGROUND       Qos_class_t = 9
	QOS_CLASS_UNSPECIFIED      Qos_class_t = 0
)

func (Qos_class_t) String

func (e Qos_class_t) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL