Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
BTManager.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 * Copyright (c) 2020 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26package org.direct_bt;
27
28import java.util.List;
29
30/**
31 * A thread safe singleton handler of the BTAdapter manager, e.g. Linux Kernel's BlueZ manager control channel.
32 *
33 * @see [Direct-BT Overview](namespaceorg_1_1direct__bt.html#details)
34 */
35public interface BTManager
36{
37 /**
38 * Event listener to receive change events regarding the system's {@link BTAdapter} set,
39 * e.g. a removed or added {@link BTAdapter} due to user interaction or 'cold reset'.
40 * <p>
41 * When a new callback is added, all available adapter's will be reported as added,
42 * this allows a fully event driven workflow.
43 * </p>
44 * <p>
45 * The callback is performed on a dedicated thread,
46 * allowing the user to perform complex operations.
47 * </p>
48 * @since 2.0.0
49 * @see BTManager#addChangedAdapterSetListener(ChangedAdapterSetListener)
50 * @see BTManager#removeChangedAdapterSetListener(ChangedAdapterSetListener)
51 * @see [Direct-BT Overview](namespaceorg_1_1direct__bt.html#details)
52 */
53 public static interface ChangedAdapterSetListener {
54 /**
55 * {@link BTAdapter} was added to the system.
56 * @param adapter the newly added {@link BTAdapter} to the system
57 */
58 void adapterAdded(final BTAdapter adapter);
59
60 /**
61 * {@link BTAdapter} was removed from the system.
62 * <p>
63 * {@link BTAdapter#close()} is being called by the native manager after issuing all
64 * {@link #adapterRemoved(BTAdapter)} calls.
65 * </p>
66 * @param adapter the removed {@link BTAdapter} from the system
67 */
68 void adapterRemoved(final BTAdapter adapter);
69 }
70
71 /** Returns a list of BluetoothAdapters available in the system
72 * @return A list of BluetoothAdapters available in the system
73 */
74 public List<BTAdapter> getAdapters();
75
76 /**
77 * Returns the BluetoothAdapter matching the given dev_id or null if not found.
78 * <p>
79 * The adapters internal device id is constant across the adapter lifecycle,
80 * but may change after its destruction.
81 * </p>
82 * @param dev_id the internal temporary adapter device id
83 * @since 2.0.0
84 */
85 public BTAdapter getAdapter(final int dev_id);
86
87 /**
88 * Sets a default adapter to use for discovery.
89 * @return TRUE if the device was set
90 * @implNote not implemented for jau.direct_bt
91 */
92 public boolean setDefaultAdapter(BTAdapter adapter);
93
94 /**
95 * Gets the default adapter to use for discovery.
96 * <p>
97 * The default adapter is either the first {@link BTAdapter#isPowered() powered} {@link BTAdapter},
98 * or function returns nullptr if none is enabled.
99 * </p>
100 * @return the used default adapter
101 */
103
104 /**
105 * Add the given {@link ChangedAdapterSetListener} to this manager.
106 * <p>
107 * When a new callback is added, all available adapter's will be reported as added,
108 * this allows a fully event driven workflow.
109 * </p>
110 * <p>
111 * The callback is performed on a dedicated thread,
112 * allowing the user to perform complex operations.
113 * </p>
114 * @since 2.0.0
115 */
117
118 /**
119 * Remove the given {@link ChangedAdapterSetListener} from this manager.
120 * @param l the to be removed element
121 * @return the number of removed elements
122 * @since 2.0.0
123 */
125
126 /**
127 * Remove all added {@link ChangedAdapterSetListener} entries from this manager.
128 * @return the number of removed elements
129 * @since 2.7.0
130 */
132
133 /**
134 * Release the native memory associated with this object and all related Bluetooth resources.
135 * The object should not be used following a call to close
136 * <p>
137 * Shutdown method is intended to allow a clean Bluetooth state at program exist.
138 * </p>
139 */
140 public void shutdown();
141}
BTAdapter represents one local Bluetooth Controller.
Definition: BTAdapter.java:48
Event listener to receive change events regarding the system's BTAdapter set, e.g.
Definition: BTManager.java:53
void adapterAdded(final BTAdapter adapter)
BTAdapter was added to the system.
void adapterRemoved(final BTAdapter adapter)
BTAdapter was removed from the system.
A thread safe singleton handler of the BTAdapter manager, e.g.
Definition: BTManager.java:36
void addChangedAdapterSetListener(final ChangedAdapterSetListener l)
Add the given ChangedAdapterSetListener to this manager.
int removeAllChangedAdapterSetListener()
Remove all added ChangedAdapterSetListener entries from this manager.
List< BTAdapter > getAdapters()
Returns a list of BluetoothAdapters available in the system.
int removeChangedAdapterSetListener(final ChangedAdapterSetListener l)
Remove the given ChangedAdapterSetListener from this manager.
BTAdapter getAdapter(final int dev_id)
Returns the BluetoothAdapter matching the given dev_id or null if not found.
void shutdown()
Release the native memory associated with this object and all related Bluetooth resources.
boolean setDefaultAdapter(BTAdapter adapter)
Sets a default adapter to use for discovery.
BTAdapter getDefaultAdapter()
Gets the default adapter to use for discovery.