Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
BTRole.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2021 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 */
25package org.direct_bt;
26
27/**
28 * Bluetooth roles from the perspective of the link layer (connection initiator).
29 * <p>
30 * See {@link #get(byte)} for its native integer mapping.
31 * </p>
32 * @see [BTAdapter roles](@ref BTAdapterRoles).
33 * @see [BTDevice roles](@ref BTDeviceRoles).
34 * @since 2.4.0
35 */
36public enum BTRole {
37 /** Undefined role. */
38 None ((byte)0),
39 /** Master or *central* role, discovering remote devices and initiating connection. This is a GATT client. */
40 Master ((byte)1),
41 /** Slave or *peripheral* role, advertising and waiting for connections to accept. This is a GATT server. */
42 Slave ((byte)2);
43
44 public final byte value;
45
46 /**
47 * Maps the specified name to a constant of BTRole.
48 * <p>
49 * Implementation simply returns {@link #valueOf(String)}.
50 * This maps the constant names itself to their respective constant.
51 * </p>
52 * @param name the string name to be mapped to a constant of this enum type.
53 * @return the corresponding constant of this enum type.
54 * @throws IllegalArgumentException if the specified name can't be mapped to a constant of this enum type
55 * as described above.
56 */
57 public static BTRole get(final String name) throws IllegalArgumentException {
58 return valueOf(name);
59 }
60
61 /**
62 * Maps the specified integer value to a constant of {@link BTRole}.
63 * @param value the integer value to be mapped to a constant of this enum type.
64 * @return the corresponding constant of this enum type, using {@link #None} if not supported.
65 */
66 public static BTRole get(final byte value) {
67 switch(value) {
68 case (byte)0x01: return Master;
69 case (byte)0x02: return Slave;
70 default: return None;
71 }
72 }
73
74 BTRole(final byte v) {
75 value = v;
76 }
77
78 /** Returns reversed roled */
79 public final BTRole reverse() {
80 switch(value) {
81 case 0x01: return BTRole.Slave;
82 case 0x02: return BTRole.Master;
83 default: return BTRole.None;
84 }
85 }
86
87}
Bluetooth roles from the perspective of the link layer (connection initiator).
Definition: BTRole.java:36
None
Undefined role.
Definition: BTRole.java:38
Master
Master or central role, discovering remote devices and initiating connection.
Definition: BTRole.java:40
final byte value
Definition: BTRole.java:44
Slave
Slave or peripheral role, advertising and waiting for connections to accept.
Definition: BTRole.java:42
final BTRole reverse()
Returns reversed roled.
Definition: BTRole.java:79
BTRole(final byte v)
Definition: BTRole.java:74