TinyB  0.5.1
TinyB - The Tiny Bluetooth LE library
BluetoothGattCharacteristic.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 "BluetoothGattDescriptor.hpp"
29 #include <string>
30 #include <vector>
31 #include <functional>
32 
33 /* Forward declaration of types */
34 struct _Object;
35 typedef struct _Object Object;
36 struct _GattCharacteristic1;
37 typedef struct _GattCharacteristic1 GattCharacteristic1;
38 
39 
45 {
46 
47 friend class tinyb::BluetoothGattService;
49 friend class tinyb::BluetoothManager;
50 friend class tinyb::BluetoothEventManager;
51 friend class BluetoothNotificationHandler;
52 
53 private:
54  GattCharacteristic1 *object;
55 
56 protected:
57  BluetoothGattCharacteristic(GattCharacteristic1 *object);
58 
59  static std::unique_ptr<BluetoothGattCharacteristic> make(Object *object,
60  BluetoothType type = BluetoothType::GATT_CHARACTERISTIC,
61  std::string *name = nullptr,
62  std::string *identifier = nullptr,
63  BluetoothObject *parent = nullptr);
64 
65  std::function<void(std::vector<unsigned char> &)> value_changed_callback;
66 
67  bool start_notify ();
68  bool stop_notify ();
69 
70 public:
71 
72  static std::string java_class() {
73  return std::string(JAVA_PACKAGE "/BluetoothGattCharacteristic");
74  }
75  static BluetoothType class_type() { return BluetoothType::GATT_CHARACTERISTIC; }
76 
77  virtual std::string get_java_class() const;
78  virtual std::string get_class_name() const ;
79  virtual std::string get_object_path() const;
80  virtual BluetoothType get_bluetooth_type() const;
81 
84  virtual BluetoothGattCharacteristic *clone() const;
85 
86  std::unique_ptr<BluetoothGattDescriptor> find(
87  std::string *identifier,
88  std::chrono::milliseconds timeout = std::chrono::milliseconds::zero())
89  {
90 
92  return manager->find<BluetoothGattDescriptor>(nullptr, identifier, this, timeout);
93  }
94 
95  /* D-Bus method calls: */
99  std::vector<unsigned char> read_value (
100  uint16_t offset = 0
101  );
102 
108  bool write_value (const std::vector<unsigned char> &arg_value, uint16_t offset = 0);
109 
124  std::function<void(BluetoothGattCharacteristic &characteristic, std::vector<unsigned char> &value,void *userdata)> callback,
125  void *user_data);
135  std::function<void(std::vector<unsigned char> &value)> callback);
141 
142  /* D-Bus property accessors: */
146  std::string get_uuid ();
147 
152 
156  std::vector<unsigned char> get_value ();
157 
162  bool get_notifying ();
163 
167  std::vector<std::string> get_flags ();
168 
173  std::vector<std::unique_ptr<BluetoothGattDescriptor>> get_descriptors ();
174 
175 };
Definition: BluetoothObject.hpp:63
virtual std::string get_java_class() const
bool write_value(const std::vector< unsigned char > &arg_value, uint16_t offset=0)
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
std::vector< std::unique_ptr< BluetoothGattDescriptor > > get_descriptors()
std::vector< unsigned char > get_value()
Definition: BluetoothGattService.hpp:41
Definition: BluetoothManager.hpp:31
virtual std::string get_class_name() const
virtual std::string get_object_path() const
BluetoothGattService get_service()
virtual BluetoothGattCharacteristic * clone() const
Definition: BluetoothGattCharacteristic.hpp:44
std::vector< std::string > get_flags()
Definition: BluetoothGattDescriptor.hpp:40
std::vector< unsigned char > read_value(uint16_t offset=0)
virtual BluetoothType get_bluetooth_type() const
bool enable_value_notifications(std::function< void(BluetoothGattCharacteristic &characteristic, std::vector< unsigned char > &value, void *userdata)> callback, void *user_data)