mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
#ifndef PLATFORM_IMPL_LINUX_WIFI_LAN_H_
|
|
#define PLATFORM_IMPL_LINUX_WIFI_LAN_H_
|
|
#include <memory>
|
|
|
|
#include "absl/container/flat_hash_map.h"
|
|
#include "absl/synchronization/mutex.h"
|
|
#include "internal/platform/implementation/linux/avahi.h"
|
|
#include "internal/platform/implementation/linux/wifi_medium.h"
|
|
#include "internal/platform/implementation/wifi_lan.h"
|
|
#include "internal/platform/nsd_service_info.h"
|
|
|
|
namespace nearby {
|
|
namespace linux {
|
|
class WifiLanMedium : public api::WifiLanMedium {
|
|
public:
|
|
WifiLanMedium(sdbus::IConnection &system_bus);
|
|
~WifiLanMedium() override = default;
|
|
|
|
bool IsNetworkConnected() const override;
|
|
|
|
bool StartAdvertising(const NsdServiceInfo &nsd_service_info) override
|
|
ABSL_LOCKS_EXCLUDED(entry_groups_mutex_);
|
|
bool StopAdvertising(const NsdServiceInfo &nsd_service_info) override
|
|
ABSL_LOCKS_EXCLUDED(entry_groups_mutex_);
|
|
|
|
bool StartDiscovery(const std::string &service_type,
|
|
DiscoveredServiceCallback callback) override
|
|
ABSL_LOCKS_EXCLUDED(service_browsers_mutex_);
|
|
bool StopDiscovery(const std::string &service_type) override
|
|
ABSL_LOCKS_EXCLUDED(service_browsers_mutex_);
|
|
|
|
std::unique_ptr<api::WifiLanSocket>
|
|
ConnectToService(const NsdServiceInfo &remote_service_info,
|
|
CancellationFlag *cancellation_flag) override {
|
|
return ConnectToService(remote_service_info.GetIPAddress(),
|
|
remote_service_info.GetPort(), cancellation_flag);
|
|
};
|
|
std::unique_ptr<api::WifiLanSocket>
|
|
ConnectToService(const std::string &ip_address, int port,
|
|
CancellationFlag *cancellation_flag) override;
|
|
std::unique_ptr<api::WifiLanServerSocket>
|
|
ListenForService(int port = 0) override;
|
|
absl::optional<std::pair<std::int32_t, std::int32_t>>
|
|
GetDynamicPortRange() override {
|
|
return std::nullopt;
|
|
}
|
|
|
|
private:
|
|
sdbus::IConnection &system_bus_;
|
|
|
|
std::shared_ptr<NetworkManager> network_manager_;
|
|
|
|
std::shared_ptr<avahi::Server> avahi_;
|
|
|
|
absl::Mutex entry_groups_mutex_;
|
|
absl::flat_hash_map<std::pair<std::string, std::string>,
|
|
std::unique_ptr<avahi::EntryGroup>>
|
|
entry_groups_ ABSL_GUARDED_BY(entry_groups_mutex_);
|
|
|
|
absl::Mutex service_browsers_mutex_;
|
|
absl::flat_hash_map<std::string, std::unique_ptr<avahi::ServiceBrowser>>
|
|
service_browsers_ ABSL_GUARDED_BY(service_browsers_mutex_);
|
|
};
|
|
} // namespace linux
|
|
} // namespace nearby
|
|
|
|
#endif
|