summaryrefslogtreecommitdiff
path: root/lib/bluetooth/adapter.vala
blob: 99a59fb104eb6a9ab4dc140acf28345cc186ff15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
 * Object representing an [[https://github.com/RadiusNetworks/bluez/blob/master/doc/adapter-api.txt|adapter]].
 */
public class AstalBluetooth.Adapter : Object {
    private IAdapter proxy;

    internal string object_path { owned get; private set; }

    internal Adapter(IAdapter proxy) {
        this.proxy = proxy;
        this.object_path = proxy.g_object_path;
        proxy.g_properties_changed.connect((props) => {
            var map = (HashTable<string, Variant>)props;
            foreach (var key in map.get_keys()) {
                var prop = kebab_case(key);
                if (get_class().find_property(prop) != null) {
                    notify_property(prop);
                }
            }
        });
    }

    /**
     * List of 128-bit UUIDs that represents the available local services.
     */
    public string[] uuids { owned get { return proxy.uuids; } }

    /**
     * Indicates that a device discovery procedure is active.
     */
    public bool discovering { get { return proxy.discovering; } }

    /**
     * Local Device ID information in modalias format used by the kernel and udev.
     */
    public string modalias { owned get { return proxy.modalias; } }

    /**
     * The Bluetooth system name (pretty hostname).
     */
    public string name { owned get { return proxy.name; } }

    /**
     * The Bluetooth class of device.
     */
    public uint class { get { return proxy.class; } }

    /**
     * The Bluetooth device address.
     */
    public string address { owned get { return proxy.address; } }


    /**
     * Switch an adapter to discoverable or non-discoverable
     * to either make it visible or hide it.
     */
    public bool discoverable {
        get { return proxy.discoverable; }
        set { proxy.discoverable = value; }
    }


    /**
     * Switch an adapter to pairable or non-pairable.
     */
    public bool pairable {
        get { return proxy.pairable; }
        set { proxy.pairable = value; }
    }


    /**
     * Switch an adapter on or off.
     */
    public bool powered {
        get { return proxy.powered; }
        set { proxy.powered = value; }
    }


    /**
     * The Bluetooth friendly name.
     *
     * In case no alias is set, it will return [[email protected]:name].
     */
    public string alias {
        owned get { return proxy.alias; }
        set { proxy.alias = value; }
    }


    /**
     * The discoverable timeout in seconds.
     * A value of zero means that the timeout is disabled
     * and it will stay in discoverable/limited mode forever
     * until [[email protected]_discovery] is invoked.
     * The default value for the discoverable timeout should be `180`.
     */
    public uint discoverable_timeout {
        get { return proxy.discoverable_timeout; }
        set { proxy.discoverable_timeout = value; }
    }


    /**
     * The pairable timeout in seconds.
     *
     * A value of zero means that the timeout is disabled and it will stay in pairable mode forever.
     * The default value for pairable timeout should be disabled `0`.
     */
    public uint pairable_timeout {
        get { return proxy.pairable_timeout; }
        set { proxy.pairable_timeout = value; }
    }


    /**
     * This removes the remote device and the pairing information.
     *
     * Possible errors: `InvalidArguments`, `Failed`.
     */
    public void remove_device(Device device) throws Error {
        proxy.remove_device(device.object_path);
    }


    /**
     * This method starts the device discovery procedure.
     *
     * Possible errors: `NotReady`, `Failed`.
     */
    public void start_discovery() throws Error {
        proxy.start_discovery();
    }


    /**
     * This method will cancel any previous [[email protected]_discovery] procedure.
     *
     * Possible errors: `NotReady`, `Failed`, `NotAuthorized`.
     */
    public void stop_discovery() throws Error {
        proxy.stop_discovery();
    }
}