TinyB  0.5.1
TinyB - The Tiny Bluetooth LE library
BluetoothGattDescriptor.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 <vector>
28 #include <functional>
29 
30 /* Forward declaration of types */
31 struct _Object;
32 typedef struct _Object Object;
33 struct _GattDescriptor1;
34 typedef struct _GattDescriptor1 GattDescriptor1;
35 
41 {
42 
44 friend class tinyb::BluetoothManager;
45 friend class tinyb::BluetoothEventManager;
46 friend class tinyb::BluetoothNotificationHandler;
47 
48 private:
49  GattDescriptor1 *object;
50 
51 
52 protected:
53  BluetoothGattDescriptor(GattDescriptor1 *object);
54 
55  static std::unique_ptr<BluetoothGattDescriptor> make(Object *object,
56  BluetoothType type = BluetoothType::GATT_DESCRIPTOR,
57  std::string *name = nullptr,
58  std::string *identifier = nullptr,
59  BluetoothObject *parent = nullptr);
60 
61  std::function<void(std::vector<unsigned char> &)> value_changed_callback;
62 
63 public:
64 
65  static std::string java_class() {
66  return std::string(JAVA_PACKAGE "/BluetoothGattDescriptor");
67  }
68  static BluetoothType class_type() { return BluetoothType::GATT_DESCRIPTOR; }
69 
70  virtual std::string get_java_class() const;
71  virtual std::string get_class_name() const;
72  virtual std::string get_object_path() const;
73  virtual BluetoothType get_bluetooth_type() const;
74 
77  virtual BluetoothGattDescriptor *clone() const;
78 
79  /* D-Bus method calls: */
83  std::vector<unsigned char> read_value (
84  uint16_t offset = 0
85  );
86 
92  bool write_value (
93  const std::vector<unsigned char> &arg_value,
94  uint16_t offset = 0
95  );
96 
110  std::function<void(BluetoothGattDescriptor &descriptor, std::vector<unsigned char> &value,void *userdata)> callback,
111  void *user_data);
121  std::function<void(std::vector<unsigned char> &value)> callback);
122  bool disable_value_notifications();
123 
124  /* D-Bus property accessors: */
128  std::string get_uuid ();
129 
134 
138  std::vector<unsigned char> get_value ();
139 
140 };
virtual BluetoothGattDescriptor * clone() const
Definition: BluetoothObject.hpp:63
virtual std::string get_object_path() const
std::vector< unsigned char > read_value(uint16_t offset=0)
bool write_value(const std::vector< unsigned char > &arg_value, uint16_t offset=0)
Definition: BluetoothManager.hpp:31
virtual std::string get_java_class() const
bool enable_value_notifications(std::function< void(BluetoothGattDescriptor &descriptor, std::vector< unsigned char > &value, void *userdata)> callback, void *user_data)
virtual std::string get_class_name() const
std::vector< unsigned char > get_value()
Definition: BluetoothGattCharacteristic.hpp:44
virtual BluetoothType get_bluetooth_type() const
Definition: BluetoothGattDescriptor.hpp:40
BluetoothGattCharacteristic get_characteristic()