mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Introduce v3 NC API callbacks
PiperOrigin-RevId: 527747390
This commit is contained in:
committed by
Copybara-Service
parent
d7be59c741
commit
5edd8e25ca
+3
-2
@@ -245,7 +245,7 @@ let package = Package(
|
||||
.target(
|
||||
name: "json",
|
||||
path: "third_party/json",
|
||||
exclude:[
|
||||
exclude: [
|
||||
"json/LICENSES",
|
||||
"json/cmake",
|
||||
"json/docs",
|
||||
@@ -430,10 +430,11 @@ let package = Package(
|
||||
"connections/implementation/mediums/BUILD",
|
||||
"connections/implementation/BUILD",
|
||||
"connections/implementation/fuzzers",
|
||||
"connections/v3/BUILD",
|
||||
"connections/BUILD",
|
||||
"internal/BUILD",
|
||||
"internal/crypto/BUILD",
|
||||
"internal/crypto/BUILD.gn",
|
||||
"internal/interop/BUILD",
|
||||
"internal/weave/BUILD",
|
||||
"internal/platform/flags/BUILD",
|
||||
"internal/platform/implementation/shared/BUILD",
|
||||
|
||||
+3
-4
@@ -30,8 +30,9 @@ cc_library(
|
||||
deps = [
|
||||
":core_types",
|
||||
"//connections/implementation:internal",
|
||||
"//internal:device",
|
||||
"//connections/v3:v3_types",
|
||||
"//internal/analytics:event_logger",
|
||||
"//internal/interop:device",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform:types",
|
||||
@@ -54,7 +55,6 @@ cc_library(
|
||||
hdrs = [
|
||||
"advertising_options.h",
|
||||
"connection_options.h",
|
||||
"device_provider.h",
|
||||
"discovery_options.h",
|
||||
"listeners.h",
|
||||
"medium_selector.h",
|
||||
@@ -74,7 +74,6 @@ cc_library(
|
||||
"//location/nearby/testing:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//internal:device",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform:util",
|
||||
@@ -99,7 +98,7 @@ cc_test(
|
||||
":core",
|
||||
":core_types",
|
||||
"//connections/implementation:internal_test",
|
||||
"//internal:device",
|
||||
"//internal/interop:device",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform:types",
|
||||
|
||||
+257
-22
@@ -20,14 +20,18 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "connections/device_provider.h"
|
||||
#include "connections/connection_options.h"
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
#include "connections/implementation/service_controller.h"
|
||||
#include "connections/implementation/service_controller_router.h"
|
||||
#include "connections/listeners.h"
|
||||
#include "connections/params.h"
|
||||
#include "connections/payload.h"
|
||||
#include "connections/v3/connection_listening_options.h"
|
||||
#include "connections/v3/listeners.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/device.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "internal/interop/device_provider.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
@@ -246,33 +250,264 @@ class Core {
|
||||
|
||||
std::string Dump();
|
||||
|
||||
//******************************* V2 *******************************
|
||||
void RequestConnectionV2(const NearbyDevice& device,
|
||||
const ConnectionRequestInfo& info,
|
||||
ConnectionOptions& connection_options,
|
||||
ResultCallback callback);
|
||||
//******************************* V3 *******************************
|
||||
// NOTE: Do NOT mix with the V1 APIs above, this might result in undefined
|
||||
// behavior!
|
||||
|
||||
void AcceptConnectionV2(const NearbyDevice& device,
|
||||
const PayloadListener& listener,
|
||||
// Starts advertising an endpoint for a local app.
|
||||
//
|
||||
// service_id - An identifier to advertise your app to other endpoints.
|
||||
// This can be an arbitrary string, so long as it uniquely
|
||||
// identifies your service. A good default is to use your
|
||||
// app's package name.
|
||||
// advertising_options - The options for advertising.
|
||||
// local_device - The local device for use when advertising when a
|
||||
// `DeviceProvider` has not been registered.
|
||||
// callback - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if advertising started successfully.
|
||||
// Status::STATUS_ALREADY_ADVERTISING if the app is already advertising.
|
||||
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
|
||||
// connected to remote endpoints; call StopAllEndpoints first.
|
||||
void StartAdvertisingV3(absl::string_view service_id,
|
||||
const AdvertisingOptions& advertising_options,
|
||||
const NearbyDevice& local_device,
|
||||
ResultCallback callback);
|
||||
|
||||
void RejectConnectionV2(const NearbyDevice& device, ResultCallback callback);
|
||||
// Starts advertising an endpoint for a local app.
|
||||
// Should only be used when DeviceProvider has been registered with this
|
||||
// Nearby Connections instance. Otherwise, use the
|
||||
// StartAdvertisingV3(service_id, advertising_options, local_device, callback)
|
||||
// function above.
|
||||
//
|
||||
// service_id - An identifier to advertise your app to other endpoints.
|
||||
// This can be an arbitrary string, so long as it uniquely
|
||||
// identifies your service. A good default is to use your
|
||||
// app's package name.
|
||||
// advertising_options - The options for advertising.
|
||||
// callback - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if advertising started successfully.
|
||||
// Status::STATUS_ALREADY_ADVERTISING if the app is already advertising.
|
||||
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
|
||||
// connected to remote endpoints; call StopAllEndpoints first.
|
||||
void StartAdvertisingV3(absl::string_view service_id,
|
||||
const AdvertisingOptions& advertising_options,
|
||||
ResultCallback callback);
|
||||
|
||||
// Span is being used here as we will not be modifying this block of memory.
|
||||
// We also do not need to own this block of memory, so we can use Span.
|
||||
// We are using NearbyDevice* so as to not lose attributes when using a
|
||||
// vector-like structure of NearbyDevice, as object information is stripped if
|
||||
// using NearbyDevice or NearbyDevice&.
|
||||
void SendPayloadV2(absl::Span<const NearbyDevice*> devices,
|
||||
const Payload& payload, ResultCallback callback);
|
||||
// Stops advertising a local endpoint. Should be called after calling
|
||||
// StartAdvertising, as soon as the application no longer needs to advertise
|
||||
// itself or goes inactive. Payloads can still be sent to connected
|
||||
// endpoints after advertising ends.
|
||||
//
|
||||
// result_cb - to access the status of the operation when available.
|
||||
void StopAdvertisingV3(ResultCallback result_cb);
|
||||
|
||||
void DisconnectFromDeviceV2(const NearbyDevice& device,
|
||||
ResultCallback callback);
|
||||
// Starts discovery for remote endpoints with the specified service ID.
|
||||
//
|
||||
// service_id - The ID for the service to be discovered, as specified in
|
||||
// the corresponding call to StartAdvertising.
|
||||
// discovery_options - The options for discovery.
|
||||
// listener_cb - A callback notified when a remote endpoint is discovered.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if discovery started successfully.
|
||||
// Status::STATUS_ALREADY_DISCOVERING if the app is already
|
||||
// discovering the specified service.
|
||||
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
|
||||
// connected to remote endpoints; call StopAllEndpoints first.
|
||||
void StartDiscoveryV3(absl::string_view service_id,
|
||||
const DiscoveryOptions& discovery_options,
|
||||
v3::DiscoveryListener listener_cb,
|
||||
ResultCallback callback);
|
||||
|
||||
void InitiateBandwidthUpgradeV2(const NearbyDevice& device,
|
||||
ResultCallback callback);
|
||||
// Stops discovery for remote endpoints, after a previous call to
|
||||
// StartDiscovery, when the client no longer needs to discover endpoints or
|
||||
// goes inactive. Payloads can still be sent to connected endpoints after
|
||||
// discovery ends.
|
||||
//
|
||||
// result_cb - to access the status of the operation when available.
|
||||
void StopDiscoveryV3(ResultCallback result_cb);
|
||||
|
||||
void RegisterDeviceProvider(const NearbyDeviceProvider& provider);
|
||||
// Starts listening for incoming connections.
|
||||
//
|
||||
// listener_cb - The connection listener to broadcast any updates.
|
||||
// options - The options for listening for a connection.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if listening started successfully.
|
||||
// Status::STATUS_ALREADY_LISTENING if the app is already listening.
|
||||
// Status::STATUS_ALREADY_ADVERTISING if the app is already advertising.
|
||||
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently connected
|
||||
// to remote endpoints; call StopAllEndpoints first.
|
||||
void StartListeningForIncomingConnections(
|
||||
const v3::ConnectionListeningOptions& options,
|
||||
v3::ConnectionListener listener_cb, ResultCallback result_cb);
|
||||
|
||||
// Stops listening for incoming connections. Should be called after
|
||||
// calling StartListeningForIncomingConnections.
|
||||
void StopListeningForIncomingConnections();
|
||||
|
||||
// Sends a request to connect to a remote endpoint.
|
||||
//
|
||||
// local_device - The local device information which will be shown on the
|
||||
// remote endpoint. Used only when a DeviceProvider is not
|
||||
// registered.
|
||||
// remote_device - The remote device to which a connection request will be
|
||||
// sent. Should match the value provided in a call to
|
||||
// DiscoveryListener::endpoint_found_cb()
|
||||
// connection_options - Connection options for the new connection if both
|
||||
// sides accept.
|
||||
// connection_cb - The callback to be notified on connection events.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if the connection request was sent.
|
||||
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT if the app already
|
||||
// has a connection to the specified endpoint.
|
||||
// Status::STATUS_RADIO_ERROR if we failed to connect because of an
|
||||
// issue with Bluetooth/WiFi.
|
||||
// Status::STATUS_ERROR if we failed to connect for any other reason.
|
||||
void RequestConnectionV3(const NearbyDevice& local_device,
|
||||
const NearbyDevice& remote_device,
|
||||
const ConnectionOptions& connection_options,
|
||||
v3::ConnectionListener connection_cb,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Sends a request to connect to a remote endpoint.
|
||||
//
|
||||
// remote_device - The remote device to which a connection request will be
|
||||
// sent. Should match the value provided in a call to
|
||||
// DiscoveryListener::endpoint_found_cb()
|
||||
// connection_options - Connection options for the new connection if both
|
||||
// sides accept.
|
||||
// connection_cb - The callback to be notified on connection events.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if the connection request was sent.
|
||||
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT if the app already
|
||||
// has a connection to the specified endpoint.
|
||||
// Status::STATUS_RADIO_ERROR if we failed to connect because of an
|
||||
// issue with Bluetooth/WiFi.
|
||||
// Status::STATUS_ERROR if we failed to connect for any other reason.
|
||||
void RequestConnectionV3(const NearbyDevice& remote_device,
|
||||
const ConnectionOptions& connection_options,
|
||||
v3::ConnectionListener connection_cb,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Accepts a connection to a remote endpoint. This method must be called
|
||||
// before Payloads can be exchanged with the remote endpoint.
|
||||
//
|
||||
// remote_device - The remote device. Should match the value provided in a
|
||||
// call to ConnectionListener::OnConnectionInitiated.
|
||||
//
|
||||
// listener_cb - A callback for payloads exchanged with the remote endpoint.
|
||||
//
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if the connection request was accepted.
|
||||
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT if the app already.
|
||||
// has a connection to the specified endpoint.
|
||||
// Status::STATUS_ENDPOINT_UNKNOWN if the app doesn't currently have a
|
||||
// pending connection to the remote device.
|
||||
void AcceptConnectionV3(const NearbyDevice& remote_device,
|
||||
v3::PayloadListener listener_cb,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Rejects a connection to a remote endpoint.
|
||||
//
|
||||
// remote_device - The device for the remote endpoint. Should match the
|
||||
// value provided in a call to
|
||||
// v3::ConnectionListener::OnConnectionInitiated().
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK} if the connection request was rejected.
|
||||
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT} if the app already
|
||||
// has a connection to the specified endpoint.
|
||||
void RejectConnectionV3(const NearbyDevice& remote_device,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Sends a Payload to a remote device. Payloads can only be sent to remote
|
||||
// devices once a notice of connection acceptance has been delivered via
|
||||
// v3::ConnectionListener::OnConnectionResult().
|
||||
//
|
||||
// remote_device - The remote device to which the payload should be sent.
|
||||
// payload - The Payload to be sent.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OUT_OF_ORDER_API_CALL if the device has not first
|
||||
// performed advertisement or discovery (to set the Strategy.
|
||||
// Status::STATUS_ENDPOINT_UNKNOWN if there's no active (or pending)
|
||||
// connection to the remote endpoint.
|
||||
// Status::STATUS_OK if none of the above errors occurred. Note that this
|
||||
// indicates that Nearby Connections will attempt to send the Payload,
|
||||
// but not that the send has successfully completed yet. Errors might
|
||||
// still occur during transmission (and at different times for
|
||||
// different endpoints), and will be delivered via
|
||||
// PayloadCallback#onPayloadTransferUpdate.
|
||||
void SendPayloadV3(const NearbyDevice& remote_device, const Payload& payload,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Cancels a Payload currently in-flight to or from remote endpoint(s).
|
||||
//
|
||||
// remote_device - The remote device with which the payload is being
|
||||
// exchanged.
|
||||
// payload_id - The identifier for the Payload to be canceled.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK if none of the above errors occurred.
|
||||
void CancelPayloadV3(const NearbyDevice& remote_device, int64_t payload_id,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Disconnects from a remote endpoint. {@link Payload}s can no longer be sent
|
||||
// to or received from the endpoint after this method is called.
|
||||
//
|
||||
// remote_device - The remote device to disconnect from.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK - finished successfully.
|
||||
void DisconnectFromDeviceV3(const NearbyDevice& remote_device,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Disconnects from, and removes all traces, of all connected and/or
|
||||
// discovered endpoints. This call is expected to be preceded by a call to
|
||||
// StopAdvertising() or StopDiscovery() as needed. After calling
|
||||
// StopAllDevices(), no further operations with remote endpoints will be
|
||||
// possible until a new call to one of StartAdvertising() or StartDiscovery().
|
||||
//
|
||||
// result_cb - To access the status of the operation when available.
|
||||
void StopAllDevicesV3(ResultCallback result_cb);
|
||||
|
||||
// Sends a request to initiate connection bandwidth upgrade.
|
||||
//
|
||||
// remote_device - The identifier for the remote device which will be
|
||||
// switching to a higher connection data rate and possibly
|
||||
// different wireless protocol. On success, calls
|
||||
// ConnectionListener::bandwidth_changed_cb().
|
||||
// result_cb - to access the status of the operation when available.
|
||||
// Possible status codes include:
|
||||
// Status::STATUS_OK - finished successfully.
|
||||
void InitiateBandwidthUpgradeV3(const NearbyDevice& remote_device,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Updates AdvertisingOptions. It compares the old AdvertisingOptions and the
|
||||
// new AdvertisingOptions to start/stop each advertising medium.
|
||||
//
|
||||
// advertising_options - The new advertising options a client wishes to use.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
void UpdateAdvertisingOptionsV3(const AdvertisingOptions& advertising_options,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Updates DiscoveryOptions. It compares the old DiscoveryOptions and the new
|
||||
// DiscoveryOptions to start/stop each discovery medium.
|
||||
//
|
||||
// discovery_options - The new discovery options a client wishes to use.
|
||||
// result_cb - to access the status of the operation when available.
|
||||
void UpdateDiscoveryOptionsV3(const DiscoveryOptions& discovery_options,
|
||||
ResultCallback result_cb);
|
||||
|
||||
// Registers a DeviceProvider to provide functionality for Nearby Connections
|
||||
// to interact with the DeviceProvider for retrieving the local device.
|
||||
void RegisterDeviceProvider(NearbyDeviceProvider&& provider);
|
||||
|
||||
private:
|
||||
ClientProxy client_;
|
||||
|
||||
@@ -137,9 +137,9 @@ cc_library(
|
||||
"//connections/implementation/mediums:utils",
|
||||
"//connections/implementation/mediums/webrtc",
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//internal:device",
|
||||
"//internal/analytics:event_logger",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/interop:device",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:cancellation_flag",
|
||||
"//internal/platform:comm",
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "connections/status.h"
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/device.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
cc_library(
|
||||
name = "v3_types",
|
||||
hdrs = [
|
||||
"bandwidth_info.h",
|
||||
"connection_listening_options.h",
|
||||
"connection_resolution.h",
|
||||
"listeners.h",
|
||||
],
|
||||
visibility = [
|
||||
"//connections:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//connections:core_types",
|
||||
"//internal/interop:device",
|
||||
"//proto:connections_enums_cc_proto",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 2023 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_V3_BANDWIDTH_INFO_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_V3_BANDWIDTH_INFO_H_
|
||||
|
||||
#include "proto/connections_enums.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace v3 {
|
||||
|
||||
// Represents the connection quality.
|
||||
enum class Quality {
|
||||
// Unknown connection quality. Recommended to wait for one of kMedium or
|
||||
// kHigh.
|
||||
kUnknown = 0,
|
||||
// The connection quality is poor (5KBps) and is not suitable for
|
||||
// sending files. It's recommended you wait until the connection
|
||||
// quality improves.
|
||||
kLow = 1,
|
||||
// The connection quality is ok (60~200KBps) and is suitable for
|
||||
// sending small files. For large files, it's recommended you wait
|
||||
// until the connection quality improves.
|
||||
kMedium = 2,
|
||||
// The connection quality is good or great (1MBps~60MBps) and files
|
||||
// can readily be sent. The connection quality cannot improve further
|
||||
// but may still be impacted by environment or hardware limitations.
|
||||
kHigh = 3,
|
||||
};
|
||||
|
||||
// Used to indicate the new connection quality when upgrading to a new medium
|
||||
// e.g. BT -> WiFi direct.
|
||||
struct BandwidthInfo {
|
||||
Quality quality;
|
||||
::location::nearby::proto::connections::Medium medium;
|
||||
};
|
||||
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_V3_BANDWIDTH_INFO_H_
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2023 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_V3_CONNECTION_LISTENING_OPTIONS_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTION_LISTENING_OPTIONS_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "proto/connections_enums.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace v3 {
|
||||
|
||||
struct ConnectionListeningOptions {
|
||||
Strategy strategy;
|
||||
bool allow_bluetooth_radio_toggling = true;
|
||||
bool allow_wifi_radio_toggling = true;
|
||||
bool enable_ble_listening = false;
|
||||
bool enable_bluetooth_listening = true;
|
||||
bool enable_wlan_listening = true;
|
||||
bool auto_upgrade_bandwidth = true;
|
||||
bool enforce_topology_constraints = true;
|
||||
std::vector<location::nearby::proto::connections::Medium> upgrade_mediums;
|
||||
std::vector<::location::nearby::proto::connections::Medium> listening_mediums;
|
||||
nearby::NearbyDevice::Type listening_endpoint_type =
|
||||
NearbyDevice::Type::kConnectionsDevice;
|
||||
};
|
||||
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTION_LISTENING_OPTIONS_H_
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2023 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_V3_CONNECTION_RESOLUTION_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTION_RESOLUTION_H_
|
||||
|
||||
#include "connections/status.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace v3 {
|
||||
|
||||
struct ConnectionResult {
|
||||
nearby::connections::Status status;
|
||||
};
|
||||
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_V3_CONNECTION_RESOLUTION_H_
|
||||
@@ -0,0 +1,133 @@
|
||||
// Copyright 2023 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_V3_LISTENERS_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_V3_LISTENERS_H_
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "connections/listeners.h"
|
||||
#include "connections/v3/bandwidth_info.h"
|
||||
#include "connections/v3/connection_resolution.h"
|
||||
#include "internal/interop/device.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
namespace v3 {
|
||||
|
||||
struct ConnectionListener {
|
||||
// A basic encrypted channel has been created between you and the endpoint.
|
||||
// Both sides are now asked if they wish to accept or reject the connection
|
||||
// before any data can be sent over this channel.
|
||||
//
|
||||
// This is your chance, before you accept the connection, to confirm that you
|
||||
// connected to the correct device. Both devices are given an identical token;
|
||||
// it's up to you to decide how to verify it before proceeding. Typically this
|
||||
// involves showing the token on both devices and having the users manually
|
||||
// compare and confirm; however, this is only required if you desire a secure
|
||||
// connection between the devices.
|
||||
//
|
||||
// Whichever route you decide to take (including not authenticating the other
|
||||
// device), call Core::AcceptConnection() when you're ready to talk, or
|
||||
// Core::RejectConnection() to close the connection.
|
||||
//
|
||||
// remote_device - The identifier for the remote endpoint.
|
||||
// info - Other relevant information about the connection.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device,
|
||||
const ConnectionResponseInfo& info)>
|
||||
initiated_cb = [](const NearbyDevice&, const ConnectionResponseInfo&) {};
|
||||
|
||||
// Called when both sides have accepted or either side has rejected the
|
||||
// connection. If the {@link ConnectionResolution}'s status is {@link
|
||||
// ConnectionsStatusCodes#SUCCESS}, both sides have accepted the
|
||||
// connection and may now send {@link Payload}s to each other.
|
||||
// Otherwise, the connection was rejected.
|
||||
|
||||
// remote_device - The identifier for the remote endpoint.
|
||||
// resolution - The resolution of the connection (accepted or rejected).
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device,
|
||||
ConnectionResult resolution)>
|
||||
result_cb = [](const NearbyDevice&, ConnectionResult) {};
|
||||
|
||||
// Called when a remote endpoint is disconnected or has become unreachable.
|
||||
// At this point service (re-)discovery may start again.
|
||||
//
|
||||
// remote_device - The identifier for the remote endpoint.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device)> disconnected_cb =
|
||||
[](const NearbyDevice&) {};
|
||||
|
||||
// Called when the connection's available bandwidth has changed.
|
||||
//
|
||||
// remote_device - The identifier for the remote endpoint.
|
||||
// bandwidth_info - Bandwidth info about the new medium that was upgraded to.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device,
|
||||
BandwidthInfo bandwidth_info)>
|
||||
bandwidth_changed_cb = [](const NearbyDevice&, BandwidthInfo) {};
|
||||
};
|
||||
|
||||
struct DiscoveryListener {
|
||||
// Called when a remote endpoint is discovered.
|
||||
//
|
||||
// remote_device - The remote device that was discovered.
|
||||
// service_id - The ID of the service advertised by the remote endpoint.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device,
|
||||
const absl::string_view service_id)>
|
||||
endpoint_found_cb = [](const NearbyDevice&, const absl::string_view) {};
|
||||
|
||||
// Called when a remote endpoint is no longer discoverable; only called for
|
||||
// endpoints that previously had been passed to {@link
|
||||
// #onEndpointFound(String, DiscoveredEndpointInfo)}.
|
||||
//
|
||||
// remote_device - The ID of the remote endpoint that was lost.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device)> endpoint_lost_cb =
|
||||
[](const NearbyDevice&) {};
|
||||
|
||||
// Called when a remote endpoint is found with an updated distance.
|
||||
//
|
||||
// arguments:
|
||||
// remote_device - The ID of the remote endpoint that was lost.
|
||||
// info - The distance info, encoded as enum value.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device, DistanceInfo info)>
|
||||
endpoint_distance_changed_cb = [](const NearbyDevice&, DistanceInfo) {};
|
||||
};
|
||||
|
||||
struct PayloadListener {
|
||||
// Called when a Payload is received from a remote endpoint. Depending
|
||||
// on the type of the Payload, all of the data may or may not have been
|
||||
// received at the time of this call. Use OnPayloadProgress() to
|
||||
// get updates on the status of the data received.
|
||||
//
|
||||
// remote_device - The identifier for the remote endpoint that sent the
|
||||
// payload.
|
||||
// payload - The Payload object received.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device, Payload payload)>
|
||||
payload_received_cb = [](const NearbyDevice&, Payload) {};
|
||||
|
||||
// Called with progress information about an active Payload transfer, either
|
||||
// incoming or outgoing.
|
||||
//
|
||||
// remote_device - The identifier for the remote endpoint that is sending or
|
||||
// receiving this payload.
|
||||
// info - The PayloadProgressInfo structure describing the status of
|
||||
// the transfer.
|
||||
absl::AnyInvocable<void(const NearbyDevice& remote_device,
|
||||
const PayloadProgressInfo& info)>
|
||||
payload_progress_cb =
|
||||
[](const NearbyDevice&, const PayloadProgressInfo&) {};
|
||||
};
|
||||
|
||||
} // namespace v3
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_V3_LISTENERS_H_
|
||||
+1
-1
@@ -12,7 +12,7 @@ cc_library(
|
||||
],
|
||||
visibility = [
|
||||
"//fastpair:__subpackages__",
|
||||
"//internal:__pkg__",
|
||||
"//internal/interop:__pkg__",
|
||||
"//internal/platform:__pkg__",
|
||||
"//location/nearby/cpp/sharing:__subpackages__",
|
||||
],
|
||||
|
||||
@@ -2,6 +2,7 @@ cc_library(
|
||||
name = "device",
|
||||
hdrs = [
|
||||
"device.h",
|
||||
"device_provider.h",
|
||||
],
|
||||
visibility = [
|
||||
"//connections:__subpackages__",
|
||||
@@ -15,22 +15,18 @@
|
||||
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "internal/device.h"
|
||||
#include "internal/interop/device.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
using ::nearby::NearbyDevice;
|
||||
|
||||
// The base device provider class for use with the Nearby Connections V3 APIs.
|
||||
// This class currently provides a function to get the local device for whatever
|
||||
// client implements it.
|
||||
class NearbyDeviceProvider {
|
||||
virtual ~NearbyDeviceProvider() = default;
|
||||
virtual NearbyDevice* GetLocalDevice() = 0;
|
||||
virtual std::string GetServiceId() = 0;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
virtual NearbyDevice* GetLocalDevice() = 0;
|
||||
};
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_DEVICE_PROVIDER_H_
|
||||
@@ -46,8 +46,8 @@ cc_library(
|
||||
visibility = [
|
||||
"//connections:__subpackages__",
|
||||
"//fastpair:__subpackages__",
|
||||
"//internal:__pkg__",
|
||||
"//internal/auth:__subpackages__",
|
||||
"//internal/interop:__pkg__",
|
||||
"//internal/platform:__subpackages__",
|
||||
"//internal/platform/implementation:__subpackages__",
|
||||
"//internal/preferences:__subpackages__",
|
||||
@@ -101,7 +101,7 @@ cc_library(
|
||||
visibility = [
|
||||
"//connections:__subpackages__",
|
||||
"//fastpair:__subpackages__",
|
||||
"//internal:__pkg__",
|
||||
"//internal/interop:__pkg__",
|
||||
"//internal/network:__subpackages__",
|
||||
"//internal/platform:__subpackages__",
|
||||
"//internal/proto/analytics:__subpackages__",
|
||||
@@ -151,7 +151,7 @@ cc_library(
|
||||
"wifi_lan_connection_info.h",
|
||||
],
|
||||
visibility = [
|
||||
"//internal:__pkg__",
|
||||
"//internal/interop:__pkg__",
|
||||
"//presence:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
|
||||
+1
-1
@@ -60,8 +60,8 @@ cc_library(
|
||||
"scan_request_builder.h",
|
||||
],
|
||||
deps = [
|
||||
"//internal:device",
|
||||
"//internal/crypto",
|
||||
"//internal/interop:device",
|
||||
"//internal/platform:connection_info",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform/implementation:types",
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "internal/platform/implementation/crypto.h"
|
||||
#include "internal/device.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "internal/platform/ble_connection_info.h"
|
||||
#include "internal/platform/implementation/system_clock.h"
|
||||
#include "presence/device_motion.h"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/variant.h"
|
||||
#include "internal/device.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "internal/proto/metadata.pb.h"
|
||||
#include "presence/data_element.h"
|
||||
#include "presence/device_motion.h"
|
||||
|
||||
Reference in New Issue
Block a user