forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bluetooth] Added support for connection based discovery (openhab#7056)
* Added support for connection based discovery * Added multiDiscoverySingleConnectionTest * applied spotless check Signed-off-by: Connor Petty <[email protected]>
- Loading branch information
Showing
20 changed files
with
1,282 additions
and
83 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
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
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
12 changes: 6 additions & 6 deletions
12
bundles/org.openhab.binding.bluetooth/src/main/feature/feature.xml
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<features name="org.openhab.binding.bluetooth-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"> | ||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository> | ||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository> | ||
|
||
<feature name="openhab-binding-bluetooth" description="Bluetooth Binding" version="${project.version}"> | ||
<feature>openhab-runtime-base</feature> | ||
<feature>openhab-transport-serial</feature> | ||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.bluetooth/${project.version}</bundle> | ||
</feature> | ||
<feature name="openhab-binding-bluetooth" description="Bluetooth Binding" version="${project.version}"> | ||
<feature>openhab-runtime-base</feature> | ||
<feature>openhab-transport-serial</feature> | ||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.bluetooth/${project.version}</bundle> | ||
</feature> | ||
</features> |
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
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
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
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
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
55 changes: 55 additions & 0 deletions
55
...rc/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothAddressLocker.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,55 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.bluetooth.discovery.internal; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import org.openhab.binding.bluetooth.BluetoothAddress; | ||
|
||
/** | ||
* The {@link BluetoothAddressLocker} handles global locking of BluetoothAddress. | ||
* This is used to make sure that devices with handlers are not connected to during discovery. | ||
* | ||
* @author Connor Petty - Initial Contribution | ||
*/ | ||
public class BluetoothAddressLocker { | ||
|
||
private static Map<BluetoothAddress, LockReference> locks = new ConcurrentHashMap<>(); | ||
|
||
public static void lock(BluetoothAddress address) { | ||
locks.compute(address, (addr, oldRef) -> { | ||
LockReference ref = oldRef; | ||
if (ref == null) { | ||
ref = new LockReference(); | ||
} | ||
ref.count++; | ||
return ref; | ||
}).lock.lock(); | ||
} | ||
|
||
public static void unlock(BluetoothAddress address) { | ||
locks.computeIfPresent(address, (addr, ref) -> { | ||
ref.count--; | ||
ref.lock.unlock(); | ||
return ref.count <= 0 ? null : ref; | ||
}); | ||
} | ||
|
||
private static class LockReference { | ||
private int count = 0; | ||
private Lock lock = new ReentrantLock(); | ||
} | ||
} |
Oops, something went wrong.