From aaea08204d1f78c2c56db45266b57afe3586a7cb Mon Sep 17 00:00:00 2001 From: Anay Wadhera Date: Thu, 8 Sep 2022 05:40:30 -0700 Subject: [PATCH] Introduce Device Provider interface PiperOrigin-RevId: 472964206 --- connections/BUILD | 1 + connections/core.h | 3 +++ connections/device_provider.h | 38 +++++++++++++++++++++++++++++ internal/BUILD | 3 ++- internal/device.h | 2 ++ internal/platform/BUILD | 17 +++++++++++++ internal/platform/connection_info.h | 35 ++++++++++++++++++++++++++ 7 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 connections/device_provider.h create mode 100644 internal/platform/connection_info.h diff --git a/connections/BUILD b/connections/BUILD index 2fd77715..a84402a6 100644 --- a/connections/BUILD +++ b/connections/BUILD @@ -55,6 +55,7 @@ cc_library( hdrs = [ "advertising_options.h", "connection_options.h", + "device_provider.h", "discovery_options.h", "listeners.h", "medium_selector.h", diff --git a/connections/core.h b/connections/core.h index f16c9777..c195a5ce 100644 --- a/connections/core.h +++ b/connections/core.h @@ -20,6 +20,7 @@ #include "absl/strings/string_view.h" #include "absl/types/span.h" +#include "connections/device_provider.h" #include "connections/implementation/client_proxy.h" #include "connections/implementation/service_controller.h" #include "connections/implementation/service_controller_router.h" @@ -267,6 +268,8 @@ class Core { void InitiateBandwidthUpgradeV2(const NearbyDevice& device, ResultCallback callback); + void RegisterDeviceProvider(const NearbyDeviceProvider& provider); + private: ClientProxy client_; ServiceControllerRouter* router_ = nullptr; diff --git a/connections/device_provider.h b/connections/device_provider.h new file mode 100644 index 00000000..8d333b37 --- /dev/null +++ b/connections/device_provider.h @@ -0,0 +1,38 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_ +#define THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_ + +#include + +#include "internal/device.h" + +namespace location { +namespace nearby { +namespace connections { + +using ::location::nearby::NearbyDevice; + +class NearbyDeviceProvider { + virtual ~NearbyDeviceProvider() = default; + virtual NearbyDevice* GetLocalDevice() = 0; + virtual std::string GetServiceId() = 0; +}; + +} // namespace connections +} // namespace nearby +} // namespace location + +#endif // THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_ diff --git a/internal/BUILD b/internal/BUILD index dc935e49..be742aa0 100644 --- a/internal/BUILD +++ b/internal/BUILD @@ -8,7 +8,8 @@ cc_library( "//presence:__subpackages__", ], deps = [ - "@com_google_absl//absl/status", + "//internal/platform:base", + "//internal/platform:connection_info", "@com_google_absl//absl/status:statusor", ], ) diff --git a/internal/device.h b/internal/device.h index 83ea7f66..e34fa57e 100644 --- a/internal/device.h +++ b/internal/device.h @@ -18,6 +18,7 @@ #include #include "absl/status/statusor.h" +#include "internal/platform/connection_info.h" namespace location { namespace nearby { @@ -36,6 +37,7 @@ class NearbyDevice { NearbyDevice& operator=(const NearbyDevice&) = delete; virtual absl::StatusOr GetEndpointId() const = 0; virtual std::string GetEndpointInfo() const = 0; + virtual absl::Span GetConnectionInfos() const = 0; virtual Type GetType() const { return Type::kUnknownDevice; } }; diff --git a/internal/platform/BUILD b/internal/platform/BUILD index 619ffe75..6ec0484b 100644 --- a/internal/platform/BUILD +++ b/internal/platform/BUILD @@ -48,6 +48,7 @@ cc_library( defines = ["NO_WEBRTC"], visibility = [ "//connections:__subpackages__", + "//internal:__pkg__", "//internal/analytics:__subpackages__", "//internal/platform:__subpackages__", "//internal/platform/implementation:__subpackages__", @@ -141,6 +142,22 @@ cc_library( ], ) +cc_library( + name = "connection_info", + hdrs = [ + "connection_info.h", + ], + defines = ["NO_WEBRTC"], + visibility = [ + "//connections:__subpackages__", + "//internal:__pkg__", + "//internal/platform/implementation:__subpackages__", + ], + deps = [ + "//internal/platform:base", + ], +) + cc_library( name = "error_code_recorder", srcs = [ diff --git a/internal/platform/connection_info.h b/internal/platform/connection_info.h new file mode 100644 index 00000000..48fc6796 --- /dev/null +++ b/internal/platform/connection_info.h @@ -0,0 +1,35 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_CONNECTION_INFO_H_ +#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_CONNECTION_INFO_H_ + +#include "internal/platform/byte_array.h" + +namespace location { +namespace nearby { +class ConnectionInfo { + public: + enum class MediumType { + kUnknown = 0, + kBluetooth = 1, + }; + virtual ~ConnectionInfo() = default; + virtual MediumType GetMediumType() const = 0; + virtual ByteArray ToBytes() const = 0; +}; +} // namespace nearby +} // namespace location + +#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_CONNECTION_INFO_H_