TinyB  0.5.1
TinyB - The Tiny Bluetooth LE library
BluetoothAdapter.hpp
1 /*
2  * Author: Petre Eftime <petre.p.eftime@intel.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 #include "BluetoothObject.hpp"
27 #include "BluetoothManager.hpp"
28 #include "BluetoothUUID.hpp"
29 #include <vector>
30 
31 /* Forward declaration of types */
32 struct _Object;
33 typedef struct _Object Object;
34 struct _Adapter1;
35 typedef struct _Adapter1 Adapter1;
36 
42 {
43 
44 friend class tinyb::BluetoothManager;
45 friend class tinyb::BluetoothEventManager;
46 friend class tinyb::BluetoothDevice;
47 friend class tinyb::BluetoothNotificationHandler;
48 
49 private:
50  Adapter1 *object;
51 
52 protected:
53  BluetoothAdapter(Adapter1 *object);
54 
55  static std::unique_ptr<BluetoothAdapter> make(Object *object,
56  BluetoothType type = BluetoothType::ADAPTER,
57  std::string *name = nullptr,
58  std::string *identifier = nullptr,
59  BluetoothObject *parent = nullptr);
60 
61  std::function<void(bool)> powered_callback;
62  std::function<void(bool)> discoverable_callback;
63  std::function<void(bool)> pairable_callback;
64  std::function<void(bool)> discovering_callback;
65 
66 public:
67 
68  static std::string java_class() {
69  return std::string(JAVA_PACKAGE "/BluetoothAdapter");
70  }
71  static BluetoothType class_type() { return BluetoothType::ADAPTER; }
72 
73  virtual std::string get_java_class() const;
74  virtual std::string get_class_name() const;
75  virtual std::string get_object_path() const;
76  virtual BluetoothType get_bluetooth_type() const;
77 
78  BluetoothAdapter(const BluetoothAdapter &object);
80  virtual BluetoothAdapter *clone() const;
81 
82  std::unique_ptr<BluetoothDevice> find(std::string *name,
83  std::string *identifier,
84  std::chrono::milliseconds timeout = std::chrono::milliseconds::zero())
85  {
86 
88  return manager->find<BluetoothDevice>(name, identifier, this, timeout);
89  }
90 
91  /* D-Bus method calls: */
92 
97  bool remove_device (
98  const std::string &arg_device
99  );
100 
104  bool start_discovery (
105  );
106 
110  bool stop_discovery (
111  );
112 
120  bool set_discovery_filter (std::vector<BluetoothUUID> uuids,
121  int16_t rssi, uint16_t pathloss, const TransportType &transport);
122 
127  std::vector<std::unique_ptr<BluetoothDevice>> get_devices (
128  );
129 
130  /* D-Bus property accessors: */
134  std::string get_address ();
135 
139  std::string get_name ();
140 
144  std::string get_alias ();
145 
148  void set_alias (const std::string &value);
149 
153  unsigned int get_class ();
154 
158  bool get_powered ();
159 
162  void set_powered (bool value);
163 
175  std::function<void(BluetoothAdapter &adapter, bool powered, void *userdata)> callback,
176  void *userdata);
184  void enable_powered_notifications(std::function<void(bool powered)> callback);
190 
194  bool get_discoverable ();
195 
198  void set_discoverable (bool value);
199 
211  std::function<void(BluetoothAdapter &adapter, bool discoverable, void *userdata)> callback,
212  void *userdata);
220  void enable_discoverable_notifications(std::function<void(bool discoverable)> callback);
225 
226 
230  unsigned int get_discoverable_timeout ();
231 
235  void set_discoverable_timeout (unsigned int value);
236 
240  bool get_pairable ();
241 
244  void set_pairable (bool value);
245 
257  std::function<void(BluetoothAdapter &adapter, bool pairable, void *userdata)> callback,
258  void *userdata);
266  void enable_pairable_notifications(std::function<void(bool pairable)> callback);
271 
276  unsigned int get_pairable_timeout ();
277 
280  void set_pairable_timeout (unsigned int value);
281 
286  bool get_discovering ();
287 
299  std::function<void(BluetoothAdapter &adapter, bool discovering, void *userdata)> callback,
300  void *userdata);
308  void enable_discovering_notifications(std::function<void(bool discovering)> callback);
313 
317  std::vector<std::string> get_uuids ();
318 
322  std::unique_ptr<std::string> get_modalias ();
323 
324 };
Definition: BluetoothObject.hpp:63
void set_pairable(bool value)
virtual BluetoothAdapter * clone() const
void enable_discoverable_notifications(std::function< void(BluetoothAdapter &adapter, bool discoverable, void *userdata)> callback, void *userdata)
virtual std::string get_object_path() const
void disable_pairable_notifications()
std::string get_name()
void disable_discoverable_notifications()
Definition: BluetoothAdapter.hpp:41
unsigned int get_discoverable_timeout()
unsigned int get_pairable_timeout()
static BluetoothManager * get_bluetooth_manager()
std::unique_ptr< T > find(std::string *name, std::string *identifier, BluetoothObject *parent, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero())
Definition: BluetoothManager.hpp:113
void set_discoverable(bool value)
void set_powered(bool value)
bool set_discovery_filter(std::vector< BluetoothUUID > uuids, int16_t rssi, uint16_t pathloss, const TransportType &transport)
void disable_discovering_notifications()
unsigned int get_class()
Definition: BluetoothManager.hpp:31
std::unique_ptr< std::string > get_modalias()
virtual std::string get_java_class() const
std::string get_address()
virtual std::string get_class_name() const
virtual BluetoothType get_bluetooth_type() const
bool remove_device(const std::string &arg_device)
void enable_pairable_notifications(std::function< void(BluetoothAdapter &adapter, bool pairable, void *userdata)> callback, void *userdata)
std::vector< std::unique_ptr< BluetoothDevice > > get_devices()
void enable_discovering_notifications(std::function< void(BluetoothAdapter &adapter, bool discovering, void *userdata)> callback, void *userdata)
void disable_powered_notifications()
Definition: BluetoothDevice.hpp:45
std::string get_alias()
void enable_powered_notifications(std::function< void(BluetoothAdapter &adapter, bool powered, void *userdata)> callback, void *userdata)
void set_discoverable_timeout(unsigned int value)
void set_pairable_timeout(unsigned int value)
std::vector< std::string > get_uuids()
void set_alias(const std::string &value)