diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index 5bdc2a6e..a8357302 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -376,6 +376,8 @@ cc_library( "@com_google_absl//absl/time", "@com_google_absl//absl/types:optional", "@com_google_absl//absl/types:span", + "@com_google_protobuf//:protobuf", + "@com_google_protobuf//json", "@nlohmann_json//:json", ], ) diff --git a/internal/platform/implementation/windows/ble_gatt_client.cc b/internal/platform/implementation/windows/ble_gatt_client.cc index d9a051d8..83ed7695 100644 --- a/internal/platform/implementation/windows/ble_gatt_client.cc +++ b/internal/platform/implementation/windows/ble_gatt_client.cc @@ -27,15 +27,10 @@ #include #include "absl/functional/any_invocable.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" #include "absl/types/optional.h" -#include "internal/flags/nearby_flags.h" -#include "internal/platform/byte_array.h" -#include "internal/platform/flags/nearby_platform_feature_flags.h" #include "internal/platform/implementation/ble.h" #include "internal/platform/implementation/windows/bluetooth_adapter.h" #include "internal/platform/implementation/windows/utils.h" @@ -48,8 +43,7 @@ #include "winrt/Windows.Foundation.h" #include "winrt/Windows.Storage.Streams.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { using ::winrt::Windows::Devices::Bluetooth::BluetoothCacheMode; @@ -66,8 +60,6 @@ using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: GattCommunicationStatus; using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: GattDeviceService; -using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: - GattDeviceServicesResult; using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: GattReadResult; using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: @@ -665,5 +657,4 @@ void BleGattClient::OnCharacteristicValueChanged( } } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/ble_gatt_server.cc b/internal/platform/implementation/windows/ble_gatt_server.cc index 52f27bf7..d3c2a939 100644 --- a/internal/platform/implementation/windows/ble_gatt_server.cc +++ b/internal/platform/implementation/windows/ble_gatt_server.cc @@ -25,11 +25,9 @@ #include #include -#include "absl/container/flat_hash_map.h" #include "absl/functional/any_invocable.h" #include "absl/status/status.h" #include "absl/strings/escaping.h" -#include "absl/strings/str_format.h" #include "absl/synchronization/mutex.h" #include "absl/time/clock.h" #include "absl/time/time.h" @@ -45,8 +43,7 @@ #include "winrt/Windows.Storage.Streams.h" #include "winrt/base.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { using ::winrt::Windows::Devices::Bluetooth::BluetoothError; @@ -78,8 +75,6 @@ using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: GattServiceProviderAdvertisingParameters; using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: GattServiceProviderResult; -using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: - GattSubscribedClient; using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile:: GattWriteRequestedEventArgs; using ::winrt::Windows::Foundation::Collections::IVectorView; @@ -753,5 +748,4 @@ BleGattServer::FindGattCharacteristicData( return nullptr; } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/ble_server_socket.cc b/internal/platform/implementation/windows/ble_server_socket.cc index 4b902b52..41fb39c1 100644 --- a/internal/platform/implementation/windows/ble_server_socket.cc +++ b/internal/platform/implementation/windows/ble_server_socket.cc @@ -19,17 +19,14 @@ #include #include "absl/synchronization/mutex.h" -#include "absl/synchronization/notification.h" #include "internal/platform/exception.h" #include "internal/platform/implementation/ble.h" #include "internal/platform/implementation/bluetooth_adapter.h" #include "internal/platform/implementation/windows/ble_socket.h" #include "internal/platform/implementation/windows/bluetooth_adapter.h" -#include "internal/platform/implementation/windows/utils.h" #include "internal/platform/logging.h" -namespace nearby { -namespace windows { +namespace nearby::windows { BleServerSocket::BleServerSocket(api::BluetoothAdapter* adapter) : adapter_(dynamic_cast(adapter)) { @@ -53,7 +50,6 @@ std::unique_ptr BleServerSocket::Accept() { } Exception BleServerSocket::Close() { - // TODO(b/271031645): implement BLE socket using weave absl::MutexLock lock(mutex_); VLOG(1) << __func__ << ": Close is called."; @@ -68,10 +64,8 @@ Exception BleServerSocket::Close() { } bool BleServerSocket::Bind() { - // TODO(b/271031645): implement BLE socket using weave LOG(ERROR) << __func__ << ": GATT socket started."; return true; } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/bluetooth_adapter.cc b/internal/platform/implementation/windows/bluetooth_adapter.cc index 0d757b2d..9bef1fae 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.cc +++ b/internal/platform/implementation/windows/bluetooth_adapter.cc @@ -57,8 +57,7 @@ typedef std::basic_string tstring; #define BLUETOOTH_RADIO_REGISTRY_NAME_KEY "Local Name" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { struct LocalSettings { std::string original_radio_name; @@ -545,7 +544,7 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { // lpWideCharStr. nullptr, // Pointer to a buffer that receives the converted string. 0, // Size, in bytes, of the buffer indicated by lpMultiByteStr. - NULL, // Pointer to the character to use if a character cannot be + nullptr, // Pointer to the character to use if a character cannot be // represented in the specified code page. &defaultCharUsed); // Pointer to a flag that indicates if the function // has used a default character in the conversion. @@ -570,8 +569,8 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { .data(), // Pointer to a buffer that receives the converted string. guid_str_size, // Size, in bytes, of the buffer indicated by // lpMultiByteStr. - NULL, // // Pointer to the character to use if a character cannot be - // represented in the specified code page. + nullptr, // Pointer to the character to use if a character cannot be + // represented in the specified code page. &defaultCharUsed); // // Pointer to a flag that indicates if the // function has used a default character in the // conversion. @@ -613,11 +612,11 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { // opened. GENERIC_WRITE, // The requested access to the file or device. 0, // The requested sharing mode of the file or device. - NULL, // A pointer to a SECURITY_ATTRIBUTES structure. + nullptr, // A pointer to a SECURITY_ATTRIBUTES structure. OPEN_EXISTING, // An action to take on a file or device that exists or // does not exist. 0, // The file or device attributes and flags. - NULL); // A valid handle to a template file with the GENERIC_READ + nullptr); // A valid handle to a template file with the GENERIC_READ // access right. This parameter can be NULL. if (hDevice == INVALID_HANDLE_VALUE) { @@ -656,7 +655,7 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { return false; } - if (name != "") { + if (!name.empty()) { // Sets the data and type of a specified value under a registry key. // https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regsetvalueexa status = RegSetValueExA( @@ -703,12 +702,12 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { &reload, // A pointer to the input buffer that contains the data // required to perform the operation. sizeof(reload), // The size of the input buffer, in bytes. - NULL, // A pointer to the output buffer that is to receive the data - // returned by the operation. - 0, // The size of the output buffer, in bytes. - &bytes, // A pointer to a variable that receives the size of the - // data stored in the output buffer, in bytes. - NULL)) { // A pointer to an OVERLAPPED structure. + nullptr, // A pointer to the output buffer that is to receive the + // data returned by the operation. + 0, // The size of the output buffer, in bytes. + &bytes, // A pointer to a variable that receives the size of the + // data stored in the output buffer, in bytes. + nullptr)) { // A pointer to an OVERLAPPED structure. LOG(ERROR) << __func__ << ": Failed to update radio module local name. Error code: " << GetLastError(); @@ -777,7 +776,8 @@ BluetoothAdapter::GetGenericBluetoothAdapterInstanceID() const { // computer. // https://docs.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupdigetclassdevsa hDevInfo = - SetupDiGetClassDevsA(&GUID_DEVCLASS_BLUETOOTH, NULL, NULL, DIGCF_PRESENT); + SetupDiGetClassDevsA(&GUID_DEVCLASS_BLUETOOTH, /*Enumerator=*/nullptr, + /*hwndParent=*/nullptr, DIGCF_PRESENT); if (hDevInfo == INVALID_HANDLE_VALUE) { LOG(ERROR) << __func__ @@ -904,5 +904,4 @@ std::string BluetoothAdapter::GetNameFromComputerName() const { return ""; } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/bluetooth_pairing.cc b/internal/platform/implementation/windows/bluetooth_pairing.cc index 3ecb2c2a..2cddfeda 100644 --- a/internal/platform/implementation/windows/bluetooth_pairing.cc +++ b/internal/platform/implementation/windows/bluetooth_pairing.cc @@ -22,7 +22,6 @@ #include #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "internal/platform/implementation/bluetooth_classic.h" #include "internal/platform/implementation/windows/generated/winrt/impl/Windows.Devices.Enumeration.0.h" #include "internal/platform/logging.h" @@ -31,8 +30,7 @@ #include "winrt/Windows.Foundation.Collections.h" #include "winrt/base.h" -namespace nearby { -namespace windows { +namespace nearby::windows { namespace { using ::winrt::Windows::Devices::Bluetooth::BluetoothDevice; @@ -44,7 +42,6 @@ using ::winrt::Windows::Devices::Enumeration::DevicePairingResult; using ::winrt::Windows::Devices::Enumeration::DevicePairingResultStatus; using ::winrt::Windows::Devices::Enumeration::DeviceUnpairingResult; using ::winrt::Windows::Devices::Enumeration::DeviceUnpairingResultStatus; -using ::winrt::Windows::Foundation::IAsyncOperation; using PairingError = ::nearby::api::BluetoothPairingCallback::PairingError; using PairingType = ::nearby::api::PairingParams::PairingType; } // namespace @@ -322,5 +319,4 @@ void BluetoothPairing::OnPair(DevicePairingResult& pairing_result) { pairing_callback_.on_pairing_error_cb(PairingError::kFailed); } -} // namespace windows -} // namespace nearby +} // namespace nearby::windows diff --git a/internal/platform/implementation/windows/platform.cc b/internal/platform/implementation/windows/platform.cc index ce847292..4d896be9 100644 --- a/internal/platform/implementation/windows/platform.cc +++ b/internal/platform/implementation/windows/platform.cc @@ -83,38 +83,12 @@ #include "internal/platform/os_name.h" #include "internal/platform/payload_id.h" -namespace nearby { -namespace api { +namespace nearby::api { namespace { constexpr char kNCRelativePath[] = "Google/Nearby/Connections"; -std::string GetApplicationName(DWORD pid) { - HANDLE handle = - OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, - pid); // Modify pid to the pid of your application - if (!handle) { - return ""; - } - - std::string szProcessName("", MAX_PATH); - DWORD len = MAX_PATH; - - if (NULL != handle) { - GetModuleFileNameExA(handle, nullptr, szProcessName.data(), len); - } - - szProcessName.resize(szProcessName.find_first_of('\0') + 1); - - auto just_the_file_name_and_ext = szProcessName.substr( - szProcessName.find_last_of('\\') + 1, - szProcessName.length() - szProcessName.find_last_of('\\') + 1); - - return just_the_file_name_and_ext.substr( - 0, just_the_file_name_and_ext.find_last_of('.')); -} - } // namespace std::string ImplementationPlatform::GetCustomSavePath( @@ -253,7 +227,6 @@ ImplementationPlatform::CreateBluetoothClassicMedium( return std::make_unique(adapter); } -// TODO(b/184975123): replace with real implementation. std::unique_ptr ImplementationPlatform::CreateBleMedium( api::BluetoothAdapter& adapter) { return std::make_unique(adapter); @@ -264,7 +237,6 @@ ImplementationPlatform::CreateCredentialStorage() { return nullptr; } -// TODO(b/184975123): replace with real implementation. std::unique_ptr ImplementationPlatform::CreateWifiMedium() { return std::make_unique(); } @@ -287,7 +259,6 @@ ImplementationPlatform::CreateWifiDirectMedium() { return std::make_unique(); } -// TODO(b/261663238) replace with real implementation. std::unique_ptr ImplementationPlatform::CreateWebRtcMedium() { return nullptr; } @@ -318,5 +289,4 @@ ImplementationPlatform::CreatePreferencesManager(absl::string_view path) { return std::make_unique(FilePath{path}); } -} // namespace api -} // namespace nearby +} // namespace nearby::api diff --git a/internal/platform/implementation/windows/wifi_lan_mdns.cc b/internal/platform/implementation/windows/wifi_lan_mdns.cc index 9794573c..bb32848e 100644 --- a/internal/platform/implementation/windows/wifi_lan_mdns.cc +++ b/internal/platform/implementation/windows/wifi_lan_mdns.cc @@ -36,7 +36,6 @@ namespace nearby::windows { namespace { // mDNS information for advertising and discovery -const char kMdnsHostName[] = "%s.local"; const char kMdnsInstanceNameFormat[] = "%s.%slocal"; // Timeout for starting mDNS service