20#include <opendht/dhtrunner.h>
21#include <opendht/infohash.h>
60 bool isOnline(
const std::string& uri)
const;
70 std::vector<dht::PkId>
getDevices(
const std::string& uri)
const;
107 std::set<dht::PkId> devices;
108 std::future<size_t> listenToken;
111 TrackedBuddy(dht::InfoHash h)
116 void trackPresence(
const dht::InfoHash& h, TrackedBuddy&
buddy);
117 void notifyListeners(
const std::string& uri,
bool online);
118 void notifyDeviceListeners(
const std::string& uri,
const dht::PkId& deviceId,
bool online);
120 std::shared_ptr<dht::DhtRunner> dht_;
122 mutable std::mutex mutex_;
123 std::map<dht::InfoHash, TrackedBuddy> trackedBuddies_;
125 std::mutex listenersMutex_;
126 std::map<uint64_t, PresenceCallback> listeners_;
127 std::map<uint64_t, DevicePresenceCallback> deviceListeners_;
128 std::atomic_uint64_t nextListenerId_ {1};
std::function< void(const std::string &uri, const dht::PkId &deviceId, bool online)> DevicePresenceCallback
uint64_t addListener(PresenceCallback cb)
Add a listener for presence changes.
void refresh()
Refresh all tracked buddies.
bool isOnline(const std::string &uri) const
Check if a buddy is currently online.
std::map< std::string, bool > getTrackedBuddyPresence() const
Get the presence status of all tracked buddies.
void removeDeviceListener(uint64_t token)
Remove a listener using the token returned by addDeviceListener.
uint64_t addDeviceListener(DevicePresenceCallback cb)
Add a listener for device presence changes.
std::function< void(const std::string &uri, bool online)> PresenceCallback
void trackBuddy(const std::string &uri)
Start tracking a buddy.
void removeListener(uint64_t token)
Remove a listener using the token returned by addListener.
void untrackBuddy(const std::string &uri)
Stop tracking a buddy.
std::vector< dht::PkId > getDevices(const std::string &uri) const
Get the list of devices for a tracked buddy.
void emitSignal(Args... args)