Class AbstractBluetoothObject

java.lang.Object
com.github.hypfvieh.bluetooth.wrapper.AbstractBluetoothObject
Direct Known Subclasses:
AgentHandler, AgentManager, BluetoothAdapter, BluetoothBattery, BluetoothDevice, BluetoothGattCharacteristic, BluetoothGattDescriptor, BluetoothGattService, ProfileManager

public abstract class AbstractBluetoothObject extends Object
Base class of all bluetooth wrapper object classes.
Author:
hypfvieh
  • Constructor Details

    • AbstractBluetoothObject

      public AbstractBluetoothObject(BluetoothDeviceType _bluetoothType, org.freedesktop.dbus.connections.impl.DBusConnection _dbusConnection, String _dbusPath)
  • Method Details

    • getInterfaceClass

      protected abstract Class<? extends org.freedesktop.dbus.interfaces.DBusInterface> getInterfaceClass()
      DBus-Interface class used in this wrapper object.
      Returns:
      class which implements the interface
    • getBluetoothType

      public BluetoothDeviceType getBluetoothType()
    • getDbusPath

      public String getDbusPath()
    • getDbusConnection

      public org.freedesktop.dbus.connections.impl.DBusConnection getDbusConnection()
    • getRemoteObjects

      protected <T extends org.freedesktop.dbus.interfaces.DBusInterface> Map<String,T> getRemoteObjects(Set<String> _objectNames, String _parentPath, Class<T> _type)
      Helper to get remote objects from DBus.
      Type Parameters:
      T - class/interface extending DBusInterface
      Parameters:
      _objectNames - Set of object names to retrieve [e.g service0000, service0001]
      _parentPath - DBus parent path (objectName will be appended) [e.g. /org/bluez/hci0]
      _type - Expected DBusInterface type [e.g. Device1]
      Returns:
      Map of string key and the given interface
    • getTyped

      protected <T> T getTyped(String _field, Class<T> _type)
      Helper to get a value of a DBus property.
      Type Parameters:
      T - class of the expected result
      Parameters:
      _field - DBus property key
      _type - expected return type of DBus property
      Returns:
      value of _field as _type class or null
    • setTyped

      protected void setTyped(String _field, Object _value)
      Helper to set a value on a DBus property.
      Parameters:
      _field - DBus property key
      _value - value to set
    • optionsToVariantMap

      protected Map<String,org.freedesktop.dbus.types.Variant<?>> optionsToVariantMap(Map<String,Object> _options)
      Convert options for read/write commands to the correct Map-type.
      DBus library uses a custom object class names 'variant' which is some sort of wrapper
      for any object. As the variant class 'allows' specifying the underlying object type, it produces
      lots of compiler warnings (rawtype).

      To get around that ugly behavior, this library uses Maps with object value.
      This method will convert the object values to variant values.
      Parameters:
      _options - options map
      Returns:
      map of variant, maybe empty but never null
    • byteListToByteArray

      protected byte[] byteListToByteArray(List<?> _list)
    • toPrimitives

      protected byte[] toPrimitives(Byte[] oBytes)
      Convert Byte[] to byte[] array.
      Parameters:
      oBytes - the array to convert
      Returns:
      primitive byte array