Power Manager
Power Manager provides a set of power management APIs that allow applications to receive callbacks when the power state, properties or error conditions of components change, as well as APIs to get device components power state and properties, and to set certain component power states. More...
Classes
Name | |
---|---|
struct | MLPowerManagerComponentProperty A structure to encapsulate the data for each MLPowerManagerPropertyType. |
union | MLPowerManagerComponentProperty.unnamed |
struct | MLPowerManagerPropertyData A structure to encapsulate output data when getting the current properties. |
struct | MLPowerManagerPropertyTypeData A structure to encapsulate output data when getting a component's available property types. |
struct | MLPowerManagerPropertyTypeInfo A structure to encapsulate information used by the Power Manager when getting the available property types. |
struct | MLPowerManagerPropertyInfo A structure to encapsulate info data used by the Power Manager when getting the current properties. |
struct | MLPowerManagerPowerStateSettings A structure to encapsulate settings used by the Power Manager when requesting the power state to be changed. |
struct | MLPowerManagerPowerStateInfo A structure to encapsulate info data used by the Power Manager when getting the current power state. |
struct | MLPowerManagerPowerStateData A structure to encapsulate output data when either getting available power states, or the current power state. |
struct | MLPowerManagerCallbacks A structure containing Power Manager callback events. Individual callbacks which are not required by the Power Manager can be NULL. |
Types
Name | |
---|---|
typedef struct MLPowerManagerComponentProperty | MLPowerManagerComponentProperty A structure to encapsulate the data for each MLPowerManagerPropertyType. |
typedef struct MLPowerManagerPropertyData | MLPowerManagerPropertyData A structure to encapsulate output data when getting the current properties. |
typedef struct MLPowerManagerPropertyTypeData | MLPowerManagerPropertyTypeData A structure to encapsulate output data when getting a component's available property types. |
typedef struct MLPowerManagerPropertyTypeInfo | MLPowerManagerPropertyTypeInfo A structure to encapsulate information used by the Power Manager when getting the available property types. |
typedef struct MLPowerManagerPropertyInfo | MLPowerManagerPropertyInfo A structure to encapsulate info data used by the Power Manager when getting the current properties. |
typedef struct MLPowerManagerPowerStateSettings | MLPowerManagerPowerStateSettings A structure to encapsulate settings used by the Power Manager when requesting the power state to be changed. |
typedef struct MLPowerManagerPowerStateInfo | MLPowerManagerPowerStateInfo A structure to encapsulate info data used by the Power Manager when getting the current power state. |
typedef struct MLPowerManagerPowerStateData | MLPowerManagerPowerStateData A structure to encapsulate output data when either getting available power states, or the current power state. |
typedef struct MLPowerManagerCallbacks | MLPowerManagerCallbacks A structure containing Power Manager callback events. Individual callbacks which are not required by the Power Manager can be NULL. |
Enums
Functions
Detailed Description
Power Manager provides a set of power management APIs that allow applications to receive callbacks when the power state, properties or error conditions of components change, as well as APIs to get device components power state and properties, and to set certain component power states.
The API uses component specific handles, as such an application should create a handle for each kind of component it wishes to get/set power state or properties for.
Shared Object:
- power_manager.magicleap*
Enums Documentation
Anonymous Enum 24
Enumerator | Value | Description |
---|---|---|
MLResultAPIPrefix_PowerManager | ( 0x4c8a << 16) | Defines the prefix for Power Manager return codes. |
MLPowerManagerResult
Enumerator | Value | Description |
---|---|---|
MLPowerManagerResult_NotConnected | MLResultAPIPrefix_PowerManager | Indicates the component is not connected. |
MLPowerManagerResult_InvalidStateTransition | Indicates the component does not currently support transitioning to requested state. | |
MLPowerManagerResult_StateTransitionsDisabled | Indicates the component does not currently support transitioning to a different state. | |
MLPowerManagerResult_UnsupportedState | Indicates the component does not support the requested power state. | |
MLPowerManagerResult_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Power Manager specific return codes.
API Level:
- 27
MLPowerManagerComponent
Enumerator | Value | Description |
---|---|---|
MLPowerManagerComponent_None | 0 | Invalid or no component. |
MLPowerManagerComponent_Controller | 1 | Controller. |
MLPowerManagerComponent_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Represents the different components which can be accessed/controlled using the Power Manager.
API Level:
- 27
MLPowerManagerError
Enumerator | Value | Description |
---|---|---|
MLPowerManagerError_InvalidSKU | 0 | Controller component could not be connected due to Invalid SKU. |
MLPowerManagerError_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Power Manager error codes.
API Level:
- 27
MLPowerManagerPowerState
Enumerator | Value | Description |
---|---|---|
MLPowerManagerPowerState_None | 0 | Invalid or no power state. |
MLPowerManagerPowerState_Normal | 1 | Normal mode, this is the default or active state of the component. |
MLPowerManagerPowerState_DisabledWhileCharging | 2 | Charging only mode. When charging component it cannot be used. |
MLPowerManagerPowerState_Standby | 3 | Standby mode. |
MLPowerManagerPowerState_Sleep | 4 | Sleep mode. |
MLPowerManagerPowerState_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Power states. Query MLPowerManagerGetAvailablePowerStates() to determine which power state is available for each component.
Component | Power State | Description |
---|---|---|
Controller | Normal | Controller is active |
Disabled While Charging | Certain SKUs cannot use controller while charging | |
Standby | Controller is turned on but inactive, press home button to switch to active manually | |
Sleep | Not supported for this component |
API Level:
- 27
MLPowerManagerChargingState
Enumerator | Value | Description |
---|---|---|
MLPowerManagerChargingState_NotCharging | 0 | Not charging. |
MLPowerManagerChargingState_ChargingNormally | 1 | Charging normally. |
MLPowerManagerChargingState_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Power Manager charging states.
API Level:
- 27
MLPowerManagerConnectionState
Enumerator | Value | Description |
---|---|---|
MLPowerManagerConnectionState_Connected | 0 | Component is connected. |
MLPowerManagerConnectionState_Disconnected | 1 | Component is disconnected. |
MLPowerManagerConnectionState_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Connection state of the component.
API Level:
- 27
MLPowerManagerBatteryInfo
Enumerator | Value | Description |
---|---|---|
MLPowerManagerBatteryInfo_OK | 0 | No issues reported. |
MLPowerManagerBatteryInfo_BatteryLow | 1 | Charge the component soon. |
MLPowerManagerBatteryInfo_BatteryCritical | 2 | Charge the component immediately. |
MLPowerManagerBatteryInfo_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Battery info/warning codes.
API Level:
- 27
MLPowerManagerPropertyType
Enumerator | Value | Description |
---|---|---|
MLPowerManagerPropertyType_BatteryInfo | 0 | Extra info about battery, as represented by MLPowerManagerBatteryInfo. |
MLPowerManagerPropertyType_BatteryLevel | 1 | Battery level. Range is between 0 and 100. |
MLPowerManagerPropertyType_ChargingState | 2 | Charging state. |
MLPowerManagerPropertyType_ConnectionState | 3 | Connection state. |
MLPowerManagerPropertyType_Ensure32Bits | 0x7FFFFFFF | Ensure enum is represented as 32 bits. |
Power Manager property types. Query MLPowerManagerGetAvailableProperties() to determine which Power Manager properties are available for each component.
API Level:
- 27
Types Documentation
MLPowerManagerComponentProperty
typedef struct MLPowerManagerComponentProperty MLPowerManagerComponentProperty;
A structure to encapsulate the data for each MLPowerManagerPropertyType.
This struct and union is used as a flexible way for each component to output an array containing distinct types of data.
The below code shows how a Controller could output battery_info, battery_level, charging_state or connection_state. Where data is an instance of MLPowerManagerPropertyData returned from MLPowerManagerGetComponentProperties.
auto properties = data.properties;
for (int num = 0; num < data.size; num++) {
switch (properties[num]->property_type) {
case (MLPowerManagerPropertyType_BatteryInfo):
// Process properties[num]->battery_info enum
break;
case (MLPowerManagerPropertyType_BatteryLevel):
// Process properties[num]->battery_level as integer
break;
case (MLPowerManagerPropertyType_ChargingState):
// Process properties[num]->charging_state as enum
break;
case (MLPowerManagerPropertyType_ConnectionState):
// Process properties[num]->connection_state as enum
break;
default:
// Error handle if default case
break;
}
}
API Level:
- 27
MLPowerManagerPropertyData
typedef struct MLPowerManagerPropertyData MLPowerManagerPropertyData;
A structure to encapsulate output data when getting the current properties.
API Level:
- 27
MLPowerManagerPropertyTypeData
typedef struct MLPowerManagerPropertyTypeData MLPowerManagerPropertyTypeData;
A structure to encapsulate output data when getting a component's available property types.
API Level:
- 27
MLPowerManagerPropertyTypeInfo
typedef struct MLPowerManagerPropertyTypeInfo MLPowerManagerPropertyTypeInfo;
A structure to encapsulate information used by the Power Manager when getting the available property types.
This structure must be initialized by calling MLPowerManagerPropertyTypeInfoInit before use.
API Level:
- 27
MLPowerManagerPropertyInfo
typedef struct MLPowerManagerPropertyInfo MLPowerManagerPropertyInfo;
A structure to encapsulate info data used by the Power Manager when getting the current properties.
This structure must be initialized by calling MLPowerManagerPropertyInfoInit before use.
API Level:
- 27
MLPowerManagerPowerStateSettings
typedef struct MLPowerManagerPowerStateSettings MLPowerManagerPowerStateSettings;
A structure to encapsulate settings used by the Power Manager when requesting the power state to be changed.
This structure must be initialized by calling MLPowerManagerPowerStateSettingsInit before use.
API Level:
- 27
MLPowerManagerPowerStateInfo
typedef struct MLPowerManagerPowerStateInfo MLPowerManagerPowerStateInfo;
A structure to encapsulate info data used by the Power Manager when getting the current power state.
This structure must be initialized by calling MLPowerManagerPowerStateInfoInit before use.
API Level:
- 27
MLPowerManagerPowerStateData
typedef struct MLPowerManagerPowerStateData MLPowerManagerPowerStateData;
A structure to encapsulate output data when either getting available power states, or the current power state.
API Level:
- 27
MLPowerManagerCallbacks
typedef struct MLPowerManagerCallbacks MLPowerManagerCallbacks;
A structure containing Power Manager callback events. Individual callbacks which are not required by the Power Manager can be NULL.
API Level:
- 27
Functions Documentation
MLPowerManagerPropertyTypeInfoInit
static inline void MLPowerManagerPropertyTypeInfoInit(
MLPowerManagerPropertyTypeInfo * inout_property_type_info
)
Initializes the default values for MLPowerManagerPropertyTypeInfo.
Parameters
MLPowerManagerPropertyTypeInfo * | inout_property_type_info | The object to initialize with default values. |
API Level:
- 27
MLPowerManagerPropertyInfoInit
static inline void MLPowerManagerPropertyInfoInit(
MLPowerManagerPropertyInfo * inout_property_info
)
Initializes the default values for MLPowerManagerPropertyInfo.
Parameters
MLPowerManagerPropertyInfo * | inout_property_info | The object to initialize with default values. |
API Level:
- 27
MLPowerManagerPowerStateSettingsInit
static inline void MLPowerManagerPowerStateSettingsInit(
MLPowerManagerPowerStateSettings * inout_power_settings
)
Initializes the default values for MLPowerManagerPowerStateSettings.
Parameters
MLPowerManagerPowerStateSettings * | inout_power_settings | The object to initialize with default values. |
API Level:
- 27
MLPowerManagerPowerStateInfoInit
static inline void MLPowerManagerPowerStateInfoInit(
MLPowerManagerPowerStateInfo * inout_power_info
)
Initializes the default values for MLPowerManagerPowerStateInfo.
Parameters
MLPowerManagerPowerStateInfo * | inout_power_info | The object to initialize with default values. |
API Level:
- 27
MLPowerManagerCallbacksInit
static inline void MLPowerManagerCallbacksInit(
MLPowerManagerCallbacks * inout_cb
)
Initializes the default values for MLPowerManagerCallbacks.
Parameters
MLPowerManagerCallbacks * | inout_cb | The object to initialize with default values. |
API Level:
- 27
MLPowerManagerCreate
MLResult MLPowerManagerCreate(
MLPowerManagerComponent component,
MLHandle * out_handle
)
Creates a Power Manager handle for a specified component.
Parameters
MLPowerManagerComponent | component | The component specific to the handle to be created. |
MLHandle * | out_handle | The handle to be created. |
Returns
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MlResult_HandleExists | Handle for this component already exists. |
MLResult | MLResult_Ok | Power Manager handle was successfully created. |
MLResult | MLResult_UnspecifiedFailure | Power Manager handle failed to be created. |
Required Permissions:
- none
In a single application multiple calls to this API method, for the same component type will return a new handle each time. The handle is valid until MLPowerManagerDestroy for that specific handle is called.
API Level:
- 27
MLPowerManagerDestroy
MLResult MLPowerManagerDestroy(
MLHandle handle
)
Destroys a Power Manager handle.
Parameters
MLHandle | handle | The Power Manager handle for a specific component to be destroyed. |
Returns
MLResult | MLResult_InvalidParam | Passed handle was invalid. |
MLResult | MLResult_Ok | Power Manager handle was successfully destroyed. |
Required Permissions:
- None
API Level:
- 27
MLPowerManagerSetCallbacks
MLResult MLPowerManagerSetCallbacks(
MLHandle handle,
MLPowerManagerCallbacks * cb,
void * user_data
)
Register Power Manager callbacks for a specific handle.
Parameters
MLHandle | handle | Power Manager handle for component to set MLPowerManagerCallbacks for. |
MLPowerManagerCallbacks * | cb | Callbacks to receive Power Manager events. Set this to NULL to unregister callbacks. |
void * | user_data | The caller can pass in user context data that will be returned in the callback (can be NULL). |
Returns
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MLResult_Ok | The callbacks have been registered. |
MLResult | MLResult_UnspecifiedFailure | The operation failed with an unspecified error. |
Required Permissions:
- None
The MLPowerManagerCallbacks structure can be set for each handle, whether those handles are for the same or different component types.
API Level:
- 27
MLPowerManagerSetPowerState
MLResult MLPowerManagerSetPowerState(
MLHandle handle,
const MLPowerManagerPowerStateSettings * settings
)
Sets the power state of a component. The new power state of a component will persist if the application loses focus, or exits.
Parameters
MLHandle | handle | Power Manager handle for component to set power state for. |
const MLPowerManagerPowerStateSettings * | settings | Settings used by the Power Manager updating a component's power state. |
Returns
MLResult | MLResult_IllegalState | The component does not support the requested power state. |
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MLPowerManagerResult_InvalidStateTransition | The component does not support transitioning to the requested state. |
MLResult | MLPowerManagerResult_NotConnected | The component is not connected. |
MLResult | MLResult_Ok | The power state of the controller was set successfully. |
MLResult | MLPowerManagerResult_StateTransitionsDisabled | The component currently does not support transitioning to a different state. |
MLResult | MLResult_UnspecifiedFailure | The operation failed with an unspecified error. |
MLResult | MLPowerManagerResult_UnsupportedState | The component does not support the requested power state. |
Required Permissions:
- None
API Level:
- 27
MLPowerManagerGetComponentProperties
MLResult MLPowerManagerGetComponentProperties(
MLHandle handle,
const MLPowerManagerPropertyInfo * in_info,
MLPowerManagerPropertyData * out_properties
)
Gets the power manager properties of a component.
Parameters
MLHandle | handle | Power Manager handle for component to get properties of. |
const MLPowerManagerPropertyInfo * | in_info | MLPowerManagerPropertyInfo struct filled with information about the power manager properties of a component to request. |
MLPowerManagerPropertyData * | out_properties | Information about the properties of a component. Must be released using MLPowerManagerReleasePropertyData after each successful call. |
Returns
MLResult | MLResult_AllocFailed | Failed due to memory allocation failure. |
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MLResult_Ok | The property of the controller was retrieved successfully. |
MLResult | MLResult_UnspecifiedFailure | The operation failed with an unspecified error. |
Required Permissions:
- None
API Level:
- 27
MLPowerManagerReleasePropertyData
MLResult MLPowerManagerReleasePropertyData(
MLHandle handle,
MLPowerManagerPropertyData * properties
)
Releases specified MLPowerManagerPropertyData.
Parameters
MLHandle | handle | Power Manager handle for component relating to MLPowerManagerPropertyData. |
MLPowerManagerPropertyData * | properties | Pointer to a MLPowerManagerPropertyData returned from MLPowerManagerGetComponentProperties. |
Returns
MLResult | MLResult_Ok | Successfully released MLPowerManagerPropertyData. |
MLResult | MLResult_InvalidParam | properties parameter was not valid (NULL). |
MLResult | MLResult_UnspecifiedFailure | Failed due to internal error. |
Required Permissions:
- None
This function should be called exactly once for each successful call to MLPowerManagerGetComponentProperties.
MLPowerManagerGetAvailablePowerStates
MLResult MLPowerManagerGetAvailablePowerStates(
MLHandle handle,
const MLPowerManagerPowerStateInfo * in_info,
MLPowerManagerPowerStateData * out_states
)
Query available power states for a component.
Parameters
MLHandle | handle | Power Manager handle for component to get list of all available power states for. |
const MLPowerManagerPowerStateInfo * | in_info | MLPowerManagerPowerStateInfo struct filled with data to be used by the Power Manager when requesting/receiving all available power states. |
MLPowerManagerPowerStateData * | out_states | MLPowerManagerPowerStateData holding list of available power states. Must be released using MLPowerManagerReleasePowerStateData after each successful call. |
Returns
MLResult | MLResult_AllocFailed | Failed due to memory allocation failure. |
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MLResult_Ok | Query completed and out_states has been populated. |
MLResult | MLResult_UnspecifiedFailure | The operation failed with an unspecified error. |
Required Permissions:
- None
API Level:
- 27
MLPowerManagerGetPowerState
MLResult MLPowerManagerGetPowerState(
MLHandle handle,
const MLPowerManagerPowerStateInfo * in_info,
MLPowerManagerPowerStateData * out_state
)
Gets the power state of a component.
Parameters
MLHandle | handle | Power Manager handle for component to get power state from. |
const MLPowerManagerPowerStateInfo * | in_info | MLPowerManagerPowerStateInfo struct filled with data to be used by the Power Manager when requesting/receiving power state. |
MLPowerManagerPowerStateData * | power_state | MLPowerManagerPowerStateData with the current power state. Must be released using MLPowerManagerReleasePowerStateData after each successful call. |
Returns
MLResult | MLPowerManagerResult_NotConnected | The component is not connected. |
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MLResult_Ok | The power state of the controller was retrieved successfully. |
MLResult | MLResult_UnspecifiedFailure | The operation failed with an unspecified error. |
Required Permissions:
- None
API Level:
- 27
MLPowerManagerReleasePowerStateData
MLResult MLPowerManagerReleasePowerStateData(
MLHandle handle,
MLPowerManagerPowerStateData * power_states
)
Releases specified MLPowerManagerPowerStateData.
Parameters
MLHandle | handle | Power Manager handle for component relating to MLPowerManagerPowerStateData. |
MLPowerManagerPowerStateData * | power_states | Pointer to a MLPowerManagerPowerStateData. |
Returns
MLResult | MLResult_Ok | Successfully released MLPowerManagerPowerStateData. |
MLResult | MLResult_InvalidParam | power_states parameter was not valid (NULL). |
MLResult | MLResult_UnspecifiedFailure | Failed due to internal error. |
Required Permissions:
- None
This function should be called exactly once for each successful call to MLPowerManagerGetAvailablePowerStates.
MLPowerManagerGetAvailableProperties
MLResult MLPowerManagerGetAvailableProperties(
MLHandle handle,
const MLPowerManagerPropertyTypeInfo * in_info,
MLPowerManagerPropertyTypeData * out_properties
)
Request a list of the available MLPowerManagerPropertyType.
Parameters
MLHandle | handle | Power Manager handle for component to get properties from. |
const MLPowerManagerPropertyTypeInfo * | in_info | MLPowerManagerPropertyTypeInfo struct filled with data to be used by the Power Manager when requesting/receiving available property types. |
MLPowerManagerPropertyTypeData * | out_properties | Information about the properties of a component. Must be released using MLPowerManagerReleasePropertyTypeData after each successful call. |
Returns
MLResult | MLResult_AllocFailed | Failed due to memory allocation failure. |
MLResult | MLResult_InvalidParam | Failed due to an invalid parameter. |
MLResult | MLResult_Ok | Query completed and out_properties has been populated. |
MLResult | MLResult_UnspecifiedFailure | The operation failed with an unspecified error. |
Required Permissions:
- None
API Level:
- 27
MLPowerManagerReleasePropertyTypeData
MLResult MLPowerManagerReleasePropertyTypeData(
MLHandle handle,
MLPowerManagerPropertyTypeData * properties
)
Releases specified MLPowerManagerPropertyTypeData.
Parameters
MLHandle | handle | Power Manager handle for component relating to MLPowerManagerPropertyTypeData. |
MLPowerManagerPropertyTypeData * | properties | Pointer to a MLPowerManagerPropertyTypeData. |
Returns
MLResult | MLResult_Ok | Successfully MLPowerManagerPropertyTypeData. |
MLResult | MLResult_InvalidParam | properties parameter was not valid (NULL). |
MLResult | MLResult_UnspecifiedFailure | Failed due to internal error. |
Required Permissions:
- None
This function should be called exactly once for each successful call to MLPowerManagerGetAvailableProperties.
MLPowerManagerGetResultString
const char * MLPowerManagerGetResultString(
MLResult result_code
)
Returns an ASCII string for each result code.
Parameters
MLResult | result_code | MLResult to select the result code. |
Returns
const char * | ASCII | string containing readable version of result code. |
Required Permissions:
- None
API Level:
- 27