Kallisto Linux API
Library for interacting with Kallisto devices
bluetooth_device.hpp
Go to the documentation of this file.
1 
42 #ifndef BLUETOOTH_DEVICE_HPP
43 #define BLUETOOTH_DEVICE_HPP
44 
45 #include <string>
46 #include <memory>
47 
48 #include "../../util/error/kallisto_error.hpp"
49 #include "bluetooth_dispatcher.hpp"
50 
51 namespace kallisto {
52 namespace bluetooth {
53 
54 class BluetoothDeviceNative; //Forward declaration of the native implementation
55 
59 class BluetoothDevice : public BluetoothDispatcher {
60 public:
65  typedef std::function<void(bool connected)> ConnectionListener;
66 
67 private:
68  //Holds the native implementation
69  std::unique_ptr<BluetoothDeviceNative> m_native_implementation;
70 
72  std::string m_name;
74  std::string m_address;
75 
76 public:
80  BluetoothDevice(std::string name, std::string address);
81 
85  virtual ~BluetoothDevice();
86 
90  BluetoothDevice(BluetoothDevice const&) = delete;
91  void operator=(BluetoothDevice const&) = delete;
92 
97 
101  BluetoothDevice& operator= (BluetoothDevice&& other);
102 
107  std::string getName() const {
108  return m_name;
109  }
110 
115  std::string getAddress() const {
116  return m_address;
117  }
118 
124  error::KallistoDetailedResult connect(ConnectionListener listener);
125 
131  error::KallistoDetailedResult disconnect(bool no_callback);
132 
137  bool getConnected();
138 
142  void close();
143 
144  /*************************************************************
145  * BluetoothDispatcher methods.
146  * @see BluetoothDispatcher
147  *************************************************************/
148  error::KallistoDetailedResult getRssi(int& buffer);
149  std::vector<std::string> getServices();
150  std::vector<std::string> getCharacteristics(std::string service_uuid);
151  error::KallistoDetailedResult readCharacteristic(std::string service_uuid, std::string characteristic_uuid, std::vector<unsigned char>& buffer);
152  error::KallistoDetailedResult writeCharacteristic(std::string service_uuid, std::string characteristic_uuid, std::vector<unsigned char>& buffer);
153  error::KallistoDetailedResult enableNotification(std::string service_uuid, std::string characteristic_uuid, BluetoothDispatcher::NotificationListener& listener);
154  error::KallistoDetailedResult disableNotification(std::string service_uuid, std::string characteristic_uuid, BluetoothDispatcher::NotificationListener& listener);
155 
156  bool operator== (const BluetoothDevice &other) const {
157  return (this->getAddress() == other.getAddress());
158  }
159 
160  bool operator!= (const BluetoothDevice &other) const {
161  return !(*this == other);
162  }
163 };
164 
165 } /* namespace bluetooth */
166 } /* namespace kallisto */
167 
168 #endif // BLUETOOTH_DEVICE_HPP
std::vector< std::string > getServices()
Definition: bluetooth_adapter.hpp:52
std::string getAddress() const
Definition: bluetooth_device.hpp:114
error::KallistoDetailedResult disableNotification(std::string service_uuid, std::string characteristic_uuid, BluetoothDispatcher::NotificationListener &listener)
std::vector< std::string > getCharacteristics(std::string service_uuid)
error::KallistoDetailedResult getRssi(int &buffer)
error::KallistoDetailedResult enableNotification(std::string service_uuid, std::string characteristic_uuid, BluetoothDispatcher::NotificationListener &listener)
error::KallistoDetailedResult disconnect(bool no_callback)
std::string getName() const
Definition: bluetooth_device.hpp:106
BluetoothDevice(std::string name, std::string address)
error::KallistoDetailedResult readCharacteristic(std::string service_uuid, std::string characteristic_uuid, std::vector< unsigned char > &buffer)
std::function< void(bool connected)> ConnectionListener
Definition: bluetooth_device.hpp:64
error::KallistoDetailedResult connect(ConnectionListener listener)
error::KallistoDetailedResult writeCharacteristic(std::string service_uuid, std::string characteristic_uuid, std::vector< unsigned char > &buffer)