public class PeripheralManager
extends java.lang.Object
PeripheralManager
class provides methods for opening and registering peripheral devices that can then be
handled as Peripheral
instances. Peripheral
instance of a particular type can be opened using their
platform-specific numerical ID or name as well as properties.
Peripheral
instances are uniquely identified by a numerical ID. This ID is unrelated to the hardware number
(hardware addressing information) that may be used to identify a device such as a GPIO pin number or an I2C slave
device address. The numerical ID of a peripheral device must be greater than or equal to 0
and must be
unique. Yet the same peripheral device may be directly and indirectly mapped through several IDs; each ID may
correspond to a different configuration, representation or abstraction for the same underlying peripheral device
hardware resource.Constructor and Description |
---|
PeripheralManager() |
Modifier and Type | Method and Description |
---|---|
static java.util.Enumeration |
list()
List all platform- and user-registered peripheral devices.
|
static java.util.Enumeration |
list(java.lang.Class intf)
List all platform- and user-registered peripheral devices of the designated type.
|
static Peripheral |
open(java.lang.Class intf,
PeripheralConfig config)
Opens a
Peripheral instance of the specified type with the specified hardware addressing information and
configuration. |
static Peripheral |
open(int id)
Looks up and opens a
Peripheral instance for the provided numerical ID. |
static Peripheral |
open(int id,
java.lang.Class intf)
Looks up and opens a
Peripheral instance for the provided numerical ID and type. |
static Peripheral |
open(PeripheralConfig config)
Opens a
Peripheral instance with the specified hardware addressing information and configuration. |
static Peripheral |
open(java.lang.String name,
java.lang.Class intf,
java.lang.String[] properties)
Looks up and opens a
Peripheral instance for the specified name, type and/or properties. |
static int |
register(int id,
java.lang.Class intf,
PeripheralConfig config,
java.lang.String name,
java.lang.String[] properties)
Registers under the specified ID (and optionally name and properties) a new peripheral device supporting the
provided configuration.
|
static void |
unregister(int id)
Unregisters the peripheral device associated with the specified ID.
|
public static java.util.Enumeration list()
Peripheral
instances returned are in a
closed state and a call to Peripheral.isOpen()
will return false
.java.lang.SecurityException
- if the caller has no permission to access the designated peripheral.public static java.util.Enumeration list(java.lang.Class intf) throws PeripheralTypeNotSupportedException
Peripheral
instances returned are in a closed state and a call to Peripheral.isOpen()
will return false
.intf
- the interface (sub-interface of Peripheral
) of the peripherals to list.PeripheralTypeNotSupportedException
- if the designated peripheral type is not supported.java.lang.SecurityException
- if the caller does not have the required permission.public static Peripheral open(java.lang.Class intf, PeripheralConfig config) throws java.io.IOException, PeripheralConfigInvalidException, PeripheralTypeNotSupportedException, PeripheralNotFoundException, PeripheralNotAvailableException, PeripheralExistsException
Peripheral
instance of the specified type with the specified hardware addressing information and
configuration. Note that the returned Peripheral
instance's ID and name are undefined. A new instance is
returned upon each call.intf
- the interface (sub-interface of Peripheral
) of the peripheral being looked up.config
- the peripheral configuration (which includes hardware addressing information as well as configuration
parameters).Peripheral
instance for the specified configuration.java.io.IOException
- if any I/O error occurred.PeripheralTypeNotSupportedException
- if the designated peripheral type is not supported.PeripheralConfigInvalidException
- if the provided peripheral configuration is not valid/supported.PeripheralNotFoundException
- if the designated peripheral is not found.PeripheralNotAvailableException
- if the designated peripheral is not currently available.PeripheralExistsException
- if the specified configuration designates a peripheral device for which a user-defined or
platform-defined configuration already exists.java.lang.SecurityException
- if the caller has no permission to access the designated peripheral.java.lang.NullPointerException
- if config
is null
.public static Peripheral open(int id) throws java.io.IOException, PeripheralNotFoundException, PeripheralNotAvailableException
Peripheral
instance for the provided numerical ID. A new instance is returned upon
each call.id
- the numerical peripheral id.Peripheral
instance for the given numerical ID.java.io.IOException
- if any I/O error occurred.PeripheralNotFoundException
- if the designated peripheral is not found.PeripheralNotAvailableException
- if the designated peripheral is not currently available.java.lang.SecurityException
- if the caller has no permission to access the designated peripheral.java.lang.IllegalArgumentException
- if id
is not greater than or equal to 0
.public static Peripheral open(int id, java.lang.Class intf) throws java.io.IOException, PeripheralTypeNotSupportedException, PeripheralNotFoundException, PeripheralNotAvailableException
Peripheral
instance for the provided numerical ID and type. A new instance is
returned upon each call.id
- the numerical peripheral id.intf
- the interface (sub-interface of Peripheral
) of the peripheral being looked up.Peripheral
instance for the given numerical ID.java.io.IOException
- if any I/O error occurred.PeripheralNotFoundException
- if the designated peripheral is not found.PeripheralTypeNotSupportedException
- if the designated peripheral type is not supported.PeripheralNotAvailableException
- if the designated peripheral is not currently available.java.lang.SecurityException
- if the caller has no permission to access the designated peripheral.java.lang.IllegalArgumentException
- if id
is not greater than or equal to 0
.public static Peripheral open(PeripheralConfig config) throws java.io.IOException, PeripheralConfigInvalidException, PeripheralTypeNotSupportedException, PeripheralNotFoundException, PeripheralNotAvailableException, PeripheralExistsException
Peripheral
instance with the specified hardware addressing information and configuration. Note
that the returned Peripheral
instance's ID and name are undefined. A new instance is returned upon each
call.config
- the peripheral configuration (which includes hardware addressing information as well as configuration
parameters).Peripheral
instance for the specified configuration.java.io.IOException
- if any I/O error occurred.PeripheralTypeNotSupportedException
- if the designated peripheral type is not supported.PeripheralConfigInvalidException
- if the provided peripheral configuration is not valid/supported.PeripheralNotFoundException
- if the designated peripheral is not found.PeripheralNotAvailableException
- if the designated peripheral is not currently available.java.lang.SecurityException
- if the caller has no permission to access the designated peripheral.java.lang.NullPointerException
- if config
is null
.PeripheralExistsException
public static Peripheral open(java.lang.String name, java.lang.Class intf, java.lang.String[] properties) throws java.io.IOException, PeripheralTypeNotSupportedException, PeripheralNotFoundException, PeripheralNotAvailableException
Peripheral
instance for the specified name, type and/or properties. A new instance
is returned upon each call.
Property-based lookup only uses exact (case-insensitive) matching and does not perform any semantic
interpretation.name
- the peripheral name; may be null
.intf
- the interface (sub-interface of Peripheral
) of the peripheral being looked up.properties
- the list of required properties; may be null
.Peripheral
instance for the given name and required properties.java.io.IOException
- if any I/O error occurred.PeripheralTypeNotSupportedException
- if the designated peripheral type is not supported.PeripheralNotFoundException
- if the designated peripheral is not found.PeripheralNotAvailableException
- if the designated peripheral is not currently available.java.lang.SecurityException
- if the caller has no permission to access the designated peripheral.java.lang.IllegalArgumentException
- if both name
and properties
are null
.public static int register(int id, java.lang.Class intf, PeripheralConfig config, java.lang.String name, java.lang.String[] properties) throws java.io.IOException, PeripheralConfigInvalidException, PeripheralTypeNotSupportedException, PeripheralNotFoundException, PeripheralExistsException
PeripheralManager.register(10, // the peripheral device ID ModemUART.class, // the peripheral device type/interface new UARTConfig(0, 2400, UARTConfig.DATABITS_8, UARTConfig.PARITY_EVEN, UARTConfig.STOPBITS_1, UARTConfig.FLOWCONTROL_NONE), // the peripheral device configuration "MODEM", // the peripheral device name new String[] { "com.foobar.modem.xxx=true", "com.foobar.modem.yyy=true" } // the device capabilities );
id
- the peripheral ID; if id
is equal to -1
a free ID will be allocated.intf
- the interface (sub-interface of Peripheral
) of the peripheral to be registered.config
- the peripheral configuration.name
- the name of the peripheral to be registered; may be null
.properties
- the list of properties/capabilities of the peripheral to be registered; may be null
.PeripheralConfigInvalidException
- if the provided peripheral configuration is not valid/supported.PeripheralTypeNotSupportedException
- if the designated peripheral type is not supported.PeripheralNotFoundException
- if the designated peripheral is not found.PeripheralExistsException
- if id
is already assigned to a peripheral device.java.lang.NullPointerException
- if config
is null
.java.lang.IllegalArgumentException
- if id
is not greater than or equal to 0
.java.io.IOException
- if any I/O error occurred.java.lang.SecurityException
- if the caller does not have the required permission.public static void unregister(int id)
id
- the ID of the peripheral device to unregister.java.lang.IllegalArgumentException
- if id
is not greater than or equal to 0
or if id
corresponds to a peripheral
device registered by the platform.java.lang.SecurityException
- if the caller does not have the required permission.Copyright (c) 2012, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.