TinyB  0.5.1
TinyB - The Tiny Bluetooth LE library
BluetoothObject.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 <memory>
27 #include <mutex>
28 #include <atomic>
29 
30 #define JAVA_PACKAGE "tinyb"
31 
32 namespace tinyb {
33 enum class BluetoothType {
34  NONE,
35  ADAPTER,
36  DEVICE,
37  GATT_SERVICE,
38  GATT_CHARACTERISTIC,
39  GATT_DESCRIPTOR
40 };
41  enum class TransportType {
42  AUTO,
43  BREDR,
44  LE
45  };
46 
47  class BluetoothEvent;
48  class BluetoothEventManager;
49  class BluetoothObject;
50  class BluetoothManager;
51  class BluetoothAdapter;
52  class BluetoothDevice;
53  class BluetoothDeviceChangeHandler;
54  class BluetoothGattService;
55  class BluetoothGattCharacteristic;
56  class BluetoothNotificationHandler;
57  class BluetoothGattDescriptor;
58  class BluetoothException;
59  class BluetoothUUID;
60 }
61 
62 
64 {
65 protected:
66  std::mutex lk;
67  std::atomic_bool valid;
68 
69  bool lock() {
70  if (valid) {
71  lk.lock();
72  return true;
73  } else {
74  return false;
75  }
76  }
77 
78  void unlock() {
79  lk.unlock();
80  }
81 
82 public:
83  static BluetoothType class_type() { return BluetoothType::NONE; }
84 
85  static std::string java_class() {
86  return std::string(JAVA_PACKAGE "/BluetoothObject");
87  }
88 
92  virtual std::string get_java_class() const;
93 
97  virtual std::string get_class_name() const;
98 
102  virtual std::string get_object_path() const;
103 
107  virtual BluetoothType get_bluetooth_type() const;
108 
109  virtual ~BluetoothObject() { };
110 
111 
115  virtual BluetoothObject *clone() const;
116 
120  virtual bool operator==(const BluetoothObject &other) const;
121  virtual bool operator!=(const BluetoothObject &other) const;
122 };
Definition: BluetoothObject.hpp:63
Definition: BluetoothObject.hpp:32