Kallisto Linux API
Library for interacting with Kallisto devices
bluetooth_scanner.hpp
Go to the documentation of this file.
1 
42 #ifndef BLUETOOTH_SCANNER_HPP_
43 #define BLUETOOTH_SCANNER_HPP_
44 
45 #include <thread>
46 #include <mutex>
47 
48 #include "../../util/error/kallisto_error.hpp"
49 #include "../../util/executor/executor.hpp"
50 #include "../adapter/bluetooth_adapter.hpp"
53 
54 namespace kallisto {
55 namespace bluetooth {
56 
60 class BluetoothScanner : BluetoothAdapter::ScanListener {
61 private:
63  BluetoothAdapter& m_adapter; //Holds our Bluetooth adapter
65  BluetoothScannerConfiguration m_scan_configuration = BluetoothScannerConfiguration::Builder().buildDefault(); //Holds the scanner configuration
67  BluetoothScannerFilter m_scan_filter = BluetoothScannerFilter::Builder().buildDefault(); //Holds the scanner filter
69  BluetoothAdapter::ScanListener* m_listener = nullptr; //Event listener
71  std::atomic_bool m_running{false}; //Signals if scanner is running
73  util::Executor m_event_dispatcher{"BluetoothScanner", 1}; //Event dispatcher
75  std::thread m_scanner_thread;
77  std::mutex m_scanner_mtx;
79  std::condition_variable m_scanner_cv;
80 
84  void scannerRunnable();
85 
89  void onScanStart();
90 
94  void onScanStartFailed();
95 
100  void onScanStop(std::vector<BluetoothDevice*> devices_found);
101 
107  void onScan(BluetoothDevice& device, const ScanRecord record);
108 
112  BluetoothScanner(BluetoothScanner const&) = delete;
113  BluetoothScanner(BluetoothScanner&&) = delete;
114  void operator=(BluetoothScanner const&) = delete;
115  void operator=(BluetoothScanner &&) = delete;
116 
117 public:
121  BluetoothScanner(BluetoothAdapter& adapter);
122 
127 
136  error::KallistoDetailedResult start(BluetoothScannerConfiguration& configuration, BluetoothScannerFilter& filter, BluetoothAdapter::ScanListener& listener);
137 
143  error::KallistoDetailedResult stop();
144 
149  const BluetoothScannerConfiguration& getConfiguration(){
150  return m_scan_configuration;
151  }
152 
157  const BluetoothScannerFilter& getFilter(){
158  return m_scan_filter;
159  }
160 
166  error::KallistoDetailedResult setConfiguration(BluetoothScannerConfiguration& configuration);
167 
173  error::KallistoDetailedResult setFilter(BluetoothScannerFilter& filter);
174 };
175 
176 } /* namespace bluetooth */
177 } /* namespace kallisto */
178 
179 #endif /* BLUETOOTH_SCANNER_HPP_ */
error::KallistoDetailedResult start(BluetoothScannerConfiguration &configuration, BluetoothScannerFilter &filter, BluetoothAdapter::ScanListener &listener)
error::KallistoDetailedResult setFilter(BluetoothScannerFilter &filter)
Definition: bluetooth_adapter.hpp:52
error::KallistoDetailedResult stop()
const BluetoothScannerFilter & getFilter()
Definition: bluetooth_scanner.hpp:156
error::KallistoDetailedResult setConfiguration(BluetoothScannerConfiguration &configuration)
const BluetoothScannerConfiguration & getConfiguration()
Definition: bluetooth_scanner.hpp:148