TinyB  0.5.1
TinyB - The Tiny Bluetooth LE library
BluetoothDevice.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 "BluetoothAdapter.hpp"
28 #include "BluetoothGattService.hpp"
29 #include "BluetoothManager.hpp"
30 #include <cstdint>
31 #include <vector>
32 #include <functional>
33 #include <map>
34 
35 /* Forward declaration of types */
36 struct _Object;
37 typedef struct _Object Object;
38 struct _Device1;
39 typedef struct _Device1 Device1;
40 
46 {
47 
48 friend class tinyb::BluetoothManager;
49 friend class tinyb::BluetoothEventManager;
50 friend class tinyb::BluetoothAdapter;
51 friend class tinyb::BluetoothGattService;
52 friend class tinyb::BluetoothNotificationHandler;
53 
54 private:
55  Device1 *object;
56 
57 protected:
58  BluetoothDevice(Device1 *object);
59 
60  static std::unique_ptr<BluetoothDevice> make(Object *object,
61  BluetoothType type = BluetoothType::DEVICE,
62  std::string *name = nullptr,
63  std::string *identifier = nullptr,
64  BluetoothObject *parent = nullptr);
65 
66  std::function<void(int16_t)> rssi_callback;
67  std::function<void(bool)> trusted_callback;
68  std::function<void(bool)> paired_callback;
69  std::function<void(bool)> connected_callback;
70  std::function<void(bool)> blocked_callback;
71  std::function<void(std::map<uint16_t, std::vector<uint8_t>> &)> mfg_callback;
72  std::function<void(std::map<std::string, std::vector<uint8_t>> &)> service_callback;
73  std::function<void(bool)> services_resolved_callback;
74 
75 public:
76 
77  static std::string java_class() {
78  return std::string(JAVA_PACKAGE "/BluetoothDevice");
79  }
80  static BluetoothType class_type() { return BluetoothType::DEVICE; }
81 
82  virtual std::string get_java_class() const;
83  virtual std::string get_class_name() const;
84  virtual std::string get_object_path() const;
85  virtual BluetoothType get_bluetooth_type() const;
86 
87  BluetoothDevice(const BluetoothDevice &object);
88  ~BluetoothDevice();
89  virtual BluetoothDevice *clone() const;
90 
91  std::unique_ptr<BluetoothGattService> find(
92  std::string *identifier,
93  std::chrono::milliseconds timeout = std::chrono::milliseconds::zero())
94  {
95 
97  return manager->find<BluetoothGattService>(nullptr, identifier, this, timeout);
98  }
99 
100  /* D-Bus method calls: */
101 
106  bool disconnect (
107  );
108 
113  bool connect (
114  );
115 
120  bool connect_profile (
121  const std::string &arg_UUID
122  );
123 
128  bool disconnect_profile (
129  const std::string &arg_UUID
130  );
131 
136  bool pair (
137  );
138 
142  bool remove_device(
143  );
144 
148  bool cancel_pairing (
149  );
150 
155  std::vector<std::unique_ptr<BluetoothGattService>> get_services (
156  );
157 
158  /* D-Bus property accessors: */
162  std::string get_address ();
163 
167  std::string get_name ();
168 
172  std::string get_alias ();
173 
176  void set_alias (const std::string &value);
177 
181  unsigned int get_class ();
182 
186  uint16_t get_appearance ();
187 
191  std::unique_ptr<std::string> get_icon ();
192 
196  bool get_paired ();
197 
209  std::function<void(BluetoothDevice &device, bool paired, void *userdata)> callback,
210  void *userdata);
219  std::function<void(bool paired)> callback);
225 
229  bool get_trusted ();
230 
233  void set_trusted (bool value);
234 
246  std::function<void(BluetoothDevice &device, bool trusted, void *userdata)> callback,
247  void *userdata);
256  std::function<void(bool trusted)> callback);
262 
266  bool get_blocked ();
267 
270  void set_blocked (bool value);
271 
283  std::function<void(BluetoothDevice &device, bool blocked, void *userdata)> callback,
284  void *userdata);
293  std::function<void(bool blocked)> callback);
299 
303  bool get_legacy_pairing ();
304 
308  int16_t get_rssi ();
309 
310 
322  std::function<void(BluetoothDevice &device, int16_t rssi, void *userdata)> callback,
323  void *userdata = nullptr);
332  std::function<void(int16_t rssi)> callback);
338 
342  bool get_connected ();
343 
355  std::function<void(BluetoothDevice &device, bool connected, void *userdata)> callback,
356  void *userdata);
365  std::function<void(bool connected)> callback);
371 
375  std::vector<std::string> get_uuids ();
376 
380  std::unique_ptr<std::string> get_modalias ();
381 
387 
392  std::map<uint16_t, std::vector<uint8_t>> get_manufacturer_data();
404  std::function<void(BluetoothDevice &device, std::map<uint16_t, std::vector<uint8_t>> &mfgdata, void *userdata)> callback,
405  void *userdata);
414  std::function<void(std::map<uint16_t, std::vector<uint8_t>> &mfgdata)> callback);
420 
421 
426  std::map<std::string, std::vector<uint8_t>> get_service_data();
438  std::function<void(BluetoothDevice &device, std::map<std::string, std::vector<uint8_t>> &servicedata, void *userdata)> callback,
439  void *userdata);
448  std::function<void(std::map<std::string, std::vector<uint8_t>> &servicedata)> callback);
454 
458  int16_t get_tx_power ();
459 
463  bool get_services_resolved ();
475  std::function<void(BluetoothDevice &device, bool services_resolved, void *userdata)> callback,
476  void *userdata);
485  std::function<void(bool connec)> callback);
491 
492 };
void enable_trusted_notifications(std::function< void(BluetoothDevice &device, bool trusted, void *userdata)> callback, void *userdata)
void disable_blocked_notifications()
Definition: BluetoothObject.hpp:63
std::unique_ptr< std::string > get_icon()
void enable_rssi_notifications(std::function< void(BluetoothDevice &device, int16_t rssi, void *userdata)> callback, void *userdata=nullptr)
void enable_service_data_notifications(std::function< void(BluetoothDevice &device, std::map< std::string, std::vector< uint8_t >> &servicedata, void *userdata)> callback, void *userdata)
BluetoothAdapter get_adapter()
std::vector< std::string > get_uuids()
Definition: BluetoothAdapter.hpp:41
std::map< uint16_t, std::vector< uint8_t > > get_manufacturer_data()
void disable_services_resolved_notifications()
void enable_manufacturer_data_notifications(std::function< void(BluetoothDevice &device, std::map< uint16_t, std::vector< uint8_t >> &mfgdata, void *userdata)> callback, void *userdata)
void enable_services_resolved_notifications(std::function< void(BluetoothDevice &device, bool services_resolved, void *userdata)> callback, void *userdata)
std::string get_alias()
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
bool connect_profile(const std::string &arg_UUID)
void disable_service_data_notifications()
void enable_connected_notifications(std::function< void(BluetoothDevice &device, bool connected, void *userdata)> callback, void *userdata)
void disable_manufacturer_data_notifications()
unsigned int get_class()
virtual std::string get_class_name() const
Definition: BluetoothGattService.hpp:41
Definition: BluetoothManager.hpp:31
std::unique_ptr< std::string > get_modalias()
std::map< std::string, std::vector< uint8_t > > get_service_data()
std::string get_address()
void disable_connected_notifications()
std::vector< std::unique_ptr< BluetoothGattService > > get_services()
virtual BluetoothDevice * clone() const
virtual std::string get_java_class() const
void disable_paired_notifications()
void set_blocked(bool value)
Definition: BluetoothDevice.hpp:45
void set_trusted(bool value)
virtual BluetoothType get_bluetooth_type() const
void set_alias(const std::string &value)
bool disconnect_profile(const std::string &arg_UUID)
void disable_trusted_notifications()
void enable_blocked_notifications(std::function< void(BluetoothDevice &device, bool blocked, void *userdata)> callback, void *userdata)
void enable_paired_notifications(std::function< void(BluetoothDevice &device, bool paired, void *userdata)> callback, void *userdata)
virtual std::string get_object_path() const
std::string get_name()