-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
bluez-dbus/src/main/java/com/github/hypfvieh/bluetooth/wrapper/ProfileChangeListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.hypfvieh.bluetooth.wrapper; | ||
|
||
import java.util.Map; | ||
|
||
import org.freedesktop.dbus.FileDescriptor; | ||
import org.freedesktop.dbus.types.Variant; | ||
|
||
public interface ProfileChangeListener { | ||
void onProfileConnection(String _dbusPath, FileDescriptor _fd, Map<String, Variant<?>> _fdProperties); | ||
|
||
void onProfileDisconnectRequest(String _path); | ||
|
||
void onProfileRelease(); | ||
} |
45 changes: 45 additions & 0 deletions
45
bluez-dbus/src/main/java/com/github/hypfvieh/bluetooth/wrapper/ProfileHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.github.hypfvieh.bluetooth.wrapper; | ||
|
||
import java.util.Map; | ||
|
||
import org.bluez.Profile1; | ||
import org.bluez.exceptions.BluezCanceledException; | ||
import org.bluez.exceptions.BluezRejectedException; | ||
import org.freedesktop.dbus.DBusPath; | ||
import org.freedesktop.dbus.FileDescriptor; | ||
import org.freedesktop.dbus.types.Variant; | ||
|
||
public final class ProfileHandler implements Profile1 { | ||
private final String objectPath; | ||
private final ProfileChangeListener profileChangeListener; | ||
|
||
public ProfileHandler(String _objectPath, ProfileChangeListener _profileChangeListener) { | ||
this.objectPath = _objectPath; | ||
this.profileChangeListener = _profileChangeListener; | ||
} | ||
|
||
@Override | ||
public void NewConnection(DBusPath _device, FileDescriptor _fd, Map<String, Variant<?>> _fdProperties) throws BluezRejectedException, BluezCanceledException { | ||
profileChangeListener.onProfileConnection(_device.getPath(), _fd, _fdProperties); | ||
} | ||
|
||
@Override | ||
public void Release() { | ||
profileChangeListener.onProfileRelease(); | ||
} | ||
|
||
@Override | ||
public void RequestDisconnection(DBusPath _device) throws BluezRejectedException, BluezCanceledException { | ||
profileChangeListener.onProfileDisconnectRequest(_device.getPath()); | ||
} | ||
|
||
@Override | ||
public String getObjectPath() { | ||
return objectPath; | ||
} | ||
|
||
@Override | ||
public boolean isRemote() { | ||
return false; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
bluez-dbus/src/main/java/com/github/hypfvieh/bluetooth/wrapper/ProfileManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.hypfvieh.bluetooth.wrapper; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import org.bluez.ProfileManager1; | ||
import org.bluez.exceptions.BluezAlreadyExistsException; | ||
import org.bluez.exceptions.BluezDoesNotExistException; | ||
import org.bluez.exceptions.BluezInvalidArgumentsException; | ||
import org.freedesktop.dbus.DBusPath; | ||
import org.freedesktop.dbus.connections.impl.DBusConnection; | ||
import org.freedesktop.dbus.interfaces.DBusInterface; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.github.hypfvieh.DbusHelper; | ||
|
||
public class ProfileManager extends AbstractBluetoothObject { | ||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private final ProfileManager1 rawProfileManager; | ||
|
||
public ProfileManager(DBusConnection _dbusConnection) { | ||
super(BluetoothDeviceType.PROFILE_MANAGER, _dbusConnection, "/org/bluez"); | ||
rawProfileManager = DbusHelper.getRemoteObject(_dbusConnection, getDbusPath(), ProfileManager1.class); | ||
|
||
} | ||
|
||
@Override | ||
protected Class<? extends DBusInterface> getInterfaceClass() { | ||
return ProfileManager1.class; | ||
} | ||
|
||
public boolean registerProfile(String _path, String _uuid, Map<String, Object> _options) { | ||
try { | ||
rawProfileManager.RegisterProfile(new DBusPath(_path), _uuid, optionsToVariantMap(_options)); | ||
return true; | ||
} catch (BluezAlreadyExistsException e) { | ||
logger.debug("Profile already exists (UUID: {}, Path: {}).", _uuid, _path, e); | ||
return true; | ||
} catch (BluezInvalidArgumentsException e) { | ||
logger.error("Error while registering Profile (UUID: {}, Path: {}).", _uuid, _path, e); | ||
return false; | ||
} | ||
} | ||
|
||
public boolean unregisterProfile(UUID _uuid, String _path) { | ||
try { | ||
rawProfileManager.UnregisterProfile(new DBusPath(_path)); | ||
return true; | ||
} catch (BluezDoesNotExistException e) { | ||
logger.trace("Profile does not exist (UUID: {}, Path: {}).", _uuid, _path, e); | ||
return false; | ||
} | ||
} | ||
|
||
} |