11 #include <Poco/Condition.h>
12 #include <Poco/Mutex.h>
13 #include <Poco/RunnableAdapter.h>
14 #include <Poco/SharedPtr.h>
15 #include <Poco/Thread.h>
16 #include <Poco/Timespan.h>
17 #include <Poco/Timestamp.h>
19 #include "bluetooth/HciInfo.h"
20 #include "bluetooth/HciInterface.h"
21 #include "bluetooth/GlibPtr.h"
22 #include "bluetooth/org-bluez-adapter1.h"
23 #include "bluetooth/org-bluez-device1.h"
24 #include "bluetooth/org-bluez-gattcharacteristic1.h"
25 #include "net/MACAddress.h"
26 #include "util/Loggable.h"
27 #include "util/WaitCondition.h"
48 typedef Poco::SharedPtr<DBusHciInterface> Ptr;
49 typedef std::function<bool(const std::string& path)> PathFilter;
50 typedef std::pair<Poco::FastMutex, std::map<MACAddress, Device>> ThreadSafeDevices;
67 const uint64_t rssiHandle);
74 uint64_t rssiHandle()
const
81 m_lastSeen = Poco::Timestamp();
84 Poco::Timestamp lastSeen()
const
89 uint64_t watchHandle()
const
96 Poco::SharedPtr<WatchCallback> callBack)
98 m_watchHandle = watchHandle;
99 m_callBack = callBack;
105 m_callBack =
nullptr;
108 bool isWatched()
const
110 return !m_callBack.isNull();
119 Poco::Timestamp m_lastSeen;
120 uint64_t m_rssiHandle;
121 uint64_t m_watchHandle;
122 Poco::SharedPtr<WatchCallback> m_callBack;
136 const std::string& name,
137 const Poco::Timespan& leMaxAgeRssi,
138 const Poco::Timespan& leMaxUnavailabilityTime,
139 const Poco::Timespan& classicArtificialAvaibilityTimeout);
148 void up()
const override;
149 void reset()
const override;
163 std::map<MACAddress, std::string>
scan()
const override;
170 std::map<MACAddress, std::string>
lescan(
171 const Poco::Timespan &timeout)
const override;
180 const Poco::Timespan& timeout)
const override;
184 Poco::SharedPtr<WatchCallback> callBack)
override;
200 GDBusObjectManager* objectManager,
209 OrgBluezDevice1* device,
210 GVariant* properties,
211 const gchar*
const* invalidatedProperties,
218 OrgBluezDevice1* device,
219 GVariant* properties,
220 const gchar*
const* invalidatedProperties,
228 OrgBluezDevice1* device,
248 const std::string& trasport)
const;
260 void initDiscoveryFilter(
262 const std::string& trasport)
const;
267 std::vector<GlibPtr<OrgBluezDevice1>> processKnownDevices(
273 void removeUnvailableDevices()
const;
285 static std::vector<std::string> retrievePathsOfBluezObjects(
287 PathFilter pathFilter,
288 const std::string& objectFilter);
293 static const std::string createAdapterPath(
const std::string& name);
298 static const std::string createDevicePath(
299 const std::string& name,
326 Poco::RunnableAdapter<DBusHciInterface> m_loopThread;
327 Poco::Thread m_thread;
329 uint64_t m_objectManagerHandle;
330 mutable ThreadSafeDevices m_devices;
332 Poco::Timespan m_leMaxAgeRssi;
333 Poco::Timespan m_leMaxUnavailabilityTime;
335 mutable std::map<MACAddress, Poco::Timestamp> m_seenClassicDevices;
336 Poco::Timespan m_classicArtificialAvaibilityTimeout;
337 mutable Poco::FastMutex m_classicMutex;
339 mutable Poco::Condition m_condition;
340 mutable Poco::FastMutex m_statusMutex;
341 mutable Poco::FastMutex m_discoveringMutex;
348 void setLeMaxAgeRssi(
const Poco::Timespan& time);
349 void setLeMaxUnavailabilityTime(
const Poco::Timespan& time);
357 HciInterface::Ptr lookup(
const std::string &name)
override;
360 Poco::FastMutex m_mutex;
361 std::map<std::string, DBusHciInterface::Ptr> m_interfaces;
362 Poco::Timespan m_leMaxAgeRssi;
363 Poco::Timespan m_leMaxUnavailabilityTime;
364 Poco::Timespan m_classicArtificialAvaibilityTimeout;
void down() const
Sets hci interface down.
Definition: DBusHciInterface.cpp:112
Definition: HciInterface.h:87
bool detect(const MACAddress &address) const override
Uses detect method of BluezHciInterface class to check state of device with MACAddress. If the device is unavailable and has been seen within a certain time (m_classicUnavailableMaxAge), the method returns true.
Definition: DBusHciInterface.cpp:134
The class realizes communication with BlueZ deamon using D-Bus. It allows to find new BLE and Bluetoo...
Definition: DBusHciInterface.h:43
static gboolean onStopLoop(gpointer loop)
Callback handling the timeout event which stops the given GMainLoop.
Definition: DBusHciInterface.cpp:432
static gboolean onDeviceRSSIChanged(OrgBluezDevice1 *device, GVariant *properties, const gchar *const *invalidatedProperties, gpointer userData)
Callback handling the event of RSSI changed. It is used to detecting that the device is available...
Definition: DBusHciInterface.cpp:469
static void processManufacturerData(OrgBluezDevice1 *device, GVariant *value, gpointer userData)
Process the single advertising data and call callback stored in userData.
Definition: DBusHciInterface.cpp:524
HciConnection::Ptr connect(const MACAddress &address, const Poco::Timespan &timeout) const override
Definition: DBusHciInterface.cpp:223
Definition: MACAddress.h:8
void reset() const override
Definition: DBusHciInterface.cpp:128
static void onDBusObjectAdded(GDBusObjectManager *objectManager, GDBusObject *object, gpointer userData)
Callback handling the event of creating new device. The method adds the new device to m_devices and r...
Definition: DBusHciInterface.cpp:438
std::map< MACAddress, std::string > scan() const override
Uses scan method of BluezHciInterface class to discover the bluetooh classic devices.
Definition: DBusHciInterface.cpp:167
Device(const GlibPtr< OrgBluezDevice1 > device, const uint64_t rssiHandle)
Definition: DBusHciInterface.cpp:604
DBusHciInterface(const std::string &name, const Poco::Timespan &leMaxAgeRssi, const Poco::Timespan &leMaxUnavailabilityTime, const Poco::Timespan &classicArtificialAvaibilityTimeout)
Definition: DBusHciInterface.cpp:28
void up() const override
Definition: DBusHciInterface.cpp:97
The class represents connection with Bluetooth Low energy device. It allows sending read/write reques...
Definition: DBusHciConnection.h:24
HciInfo info() const override
Uses BluezHciInterface to retrieve hci info.
Definition: DBusHciInterface.cpp:217
Definition: Loggable.h:19
void watch(const MACAddress &address, Poco::SharedPtr< WatchCallback > callBack) override
Definition: DBusHciInterface.cpp:249
std::map< MACAddress, std::string > lescan(const Poco::Timespan &timeout) const override
Scans the Bluetooth LE network and returns all available devices. The method returns devices whitch u...
Definition: DBusHciInterface.cpp:173
void unwatch(const MACAddress &address) override
Definition: DBusHciInterface.cpp:277
WaitCondition works as a barrier that waits until some condition is met. When the condition is met an...
Definition: WaitCondition.h:19
void setClassicArtificialAvaibilityTimeout(const Poco::Timespan &time)
Sets the maximum time from the last seen of the Bluetooth Classic device to declare the device is ava...
Definition: DBusHciInterface.cpp:656
Definition: HciInterface.h:16
Definition: DBusHciInterface.h:344
static gboolean onDeviceManufacturerDataRecieved(OrgBluezDevice1 *device, GVariant *properties, const gchar *const *invalidatedProperties, gpointer userData)
Callback handling the event of receiving advertising data.
Definition: DBusHciInterface.cpp:499
The class represents the Bluetooth Low Energy device and stores necessary data about device such as i...
Definition: DBusHciInterface.h:59