mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Roll forward to cl/314549634
Change-Id: I4d1e7eacd5fa4078a094571ad6d5f51e422535ff
This commit is contained in:
committed by
Alexey Polyudov
parent
ae1c427b99
commit
cffbc04508
+42
-11
@@ -1,12 +1,8 @@
|
||||
cc_library(
|
||||
name = "api",
|
||||
name = "types",
|
||||
hdrs = [
|
||||
"atomic_boolean.h",
|
||||
"atomic_reference.h",
|
||||
"ble.h",
|
||||
"ble_v2.h",
|
||||
"bluetooth_adapter.h",
|
||||
"bluetooth_classic.h",
|
||||
"cancelable.h",
|
||||
"condition_variable.h",
|
||||
"count_down_latch.h",
|
||||
@@ -17,12 +13,32 @@ cc_library(
|
||||
"listenable_future.h",
|
||||
"mutex.h",
|
||||
"output_file.h",
|
||||
"platform.h",
|
||||
"scheduled_executor.h",
|
||||
"server_sync.h",
|
||||
"settable_future.h",
|
||||
"submittable_executor.h",
|
||||
"system_clock.h",
|
||||
],
|
||||
visibility = [
|
||||
"//platform_v2/base:__pkg__",
|
||||
"//platform_v2/impl:__subpackages__",
|
||||
"//platform_v2/public:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//platform_v2/base",
|
||||
"//absl/base:core_headers",
|
||||
"//absl/strings",
|
||||
"//absl/time",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "comm",
|
||||
hdrs = [
|
||||
"ble.h",
|
||||
"ble_v2.h",
|
||||
"bluetooth_adapter.h",
|
||||
"bluetooth_classic.h",
|
||||
"server_sync.h",
|
||||
"webrtc.h",
|
||||
"wifi.h",
|
||||
"wifi_lan.h",
|
||||
@@ -30,14 +46,29 @@ cc_library(
|
||||
visibility = [
|
||||
"//platform_v2/base:__pkg__",
|
||||
"//platform_v2/impl:__subpackages__",
|
||||
"//platform_v2/public:__subpackages__",
|
||||
"//platform_v2/public:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//platform_v2/base",
|
||||
"//absl/base:core_headers",
|
||||
"//absl/strings",
|
||||
"//absl/time",
|
||||
"//absl/types:optional",
|
||||
"//webrtc/api:libjingle_peerconnection_api",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "platform",
|
||||
hdrs = [
|
||||
"platform.h",
|
||||
],
|
||||
visibility = [
|
||||
"//platform_v2/impl:__subpackages__",
|
||||
"//platform_v2/public:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
":comm",
|
||||
":types",
|
||||
"//absl/strings",
|
||||
"//absl/types:any",
|
||||
"//webrtc/files/stable/webrtc/api:libjingle_peerconnection_api",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
#include "platform_v2/base/exception.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -119,7 +119,7 @@ class ClientGattConnection {
|
||||
//
|
||||
// It is okay for duplicate services to exist, as long as the specified
|
||||
// characteristic UUID is unique among all services of the same UUID.
|
||||
virtual std::optional<GattCharacteristic> GetCharacteristic(
|
||||
virtual absl::optional<GattCharacteristic> GetCharacteristic(
|
||||
absl::string_view service_uuid,
|
||||
absl::string_view characteristic_uuid) = 0;
|
||||
|
||||
@@ -127,7 +127,7 @@ class ClientGattConnection {
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html#getValue()
|
||||
//
|
||||
// Reads a GATT characteristic. No value is returned upon error.
|
||||
virtual std::optional<ByteArray> ReadCharacteristic(
|
||||
virtual absl::optional<ByteArray> ReadCharacteristic(
|
||||
const GattCharacteristic& characteristic) = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html#setValue(byte[])
|
||||
@@ -209,7 +209,7 @@ class GattServer {
|
||||
// descriptor and subscribe for characteristic changes. For more information
|
||||
// about this descriptor, please go to:
|
||||
// https://www.bluetooth.com/specifications/Gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.Gatt.client_characteristic_configuration.xml
|
||||
virtual std::optional<GattCharacteristic> CreateCharacteristic(
|
||||
virtual absl::optional<GattCharacteristic> CreateCharacteristic(
|
||||
absl::string_view service_uuid, absl::string_view characteristic_uuid,
|
||||
const std::set<GattCharacteristic::Permission>& permissions,
|
||||
const std::set<GattCharacteristic::Property>& properties) = 0;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
#include "platform_v2/base/exception.h"
|
||||
#include "platform_v2/base/input_stream.h"
|
||||
#include "platform_v2/base/listeners.h"
|
||||
#include "platform_v2/base/output_stream.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -17,7 +17,7 @@ namespace api {
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html.
|
||||
class BluetoothDevice {
|
||||
public:
|
||||
virtual ~BluetoothDevice() {}
|
||||
virtual ~BluetoothDevice() = default;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName()
|
||||
virtual std::string GetName() const = 0;
|
||||
@@ -26,32 +26,45 @@ class BluetoothDevice {
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html.
|
||||
class BluetoothSocket {
|
||||
public:
|
||||
virtual ~BluetoothSocket() {}
|
||||
virtual ~BluetoothSocket() = default;
|
||||
|
||||
// Returns the InputStream of the BluetoothSocket.
|
||||
// NOTE:
|
||||
// It is an undefined behavior if GetInputStream() or GetOutputStream() is
|
||||
// called for a not-connected BluetoothSocket, i.e. any object that is not
|
||||
// returned by BluetoothClassicMedium::ConnectToService() for client side or
|
||||
// BluetoothServerSocket::Accept() for server side of connection.
|
||||
|
||||
// Returns the InputStream of this connected BluetoothSocket.
|
||||
virtual InputStream& GetInputStream() = 0;
|
||||
|
||||
// Returns the OutputStream of the BluetoothSocket.
|
||||
// Returns the OutputStream of this connected BluetoothSocket.
|
||||
virtual OutputStream& GetOutputStream() = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html#close()
|
||||
//
|
||||
// Closes both input and output streams, marks Socket as closed.
|
||||
// After this call object should be treated as not connected.
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
virtual Exception Close() = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html#getRemoteDevice()
|
||||
virtual BluetoothDevice& GetRemoteDevice() = 0;
|
||||
// Returns valid BluetoothDevice pointer if there is a connection, and
|
||||
// nullptr otherwise.
|
||||
virtual BluetoothDevice* GetRemoteDevice() = 0;
|
||||
};
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothServerSocket.html.
|
||||
class BluetoothServerSocket {
|
||||
public:
|
||||
virtual ~BluetoothServerSocket() {}
|
||||
virtual ~BluetoothServerSocket() = default;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothServerSocket.html#accept()
|
||||
//
|
||||
// returns Exception::kIo on error.
|
||||
virtual ExceptionOr<std::unique_ptr<BluetoothSocket>> Accept() = 0;
|
||||
// Blocks until either:
|
||||
// - at least one incoming connection request is available, or
|
||||
// - ServerSocket is closed.
|
||||
// On success, returns connected socket, ready to exchange data.
|
||||
// Returns nullptr on error.
|
||||
// Once error is reported, it is permanent, and ServerSocket has to be closed.
|
||||
virtual std::unique_ptr<BluetoothSocket> Accept() = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothServerSocket.html#close()
|
||||
//
|
||||
@@ -63,31 +76,33 @@ class BluetoothServerSocket {
|
||||
// medium.
|
||||
class BluetoothClassicMedium {
|
||||
public:
|
||||
virtual ~BluetoothClassicMedium() {}
|
||||
virtual ~BluetoothClassicMedium() = default;
|
||||
|
||||
class DiscoveryCallback {
|
||||
public:
|
||||
virtual ~DiscoveryCallback() {}
|
||||
|
||||
// BluetoothDevice* is not owned by callbacks.
|
||||
// Pointer is guaranteed to remain valid for the duration of a call.
|
||||
virtual void OnDeviceDiscovered(BluetoothDevice* device) = 0;
|
||||
virtual void OnDeviceNameChanged(BluetoothDevice* device) = 0;
|
||||
virtual void OnDeviceLost(BluetoothDevice* device) = 0;
|
||||
struct DiscoveryCallback {
|
||||
// BluetoothDevice is a proxy object created as a result of BT discovery.
|
||||
// Its lifetime spans between calls to device_discovered_cb and
|
||||
// device_lost_cb.
|
||||
// It is safe to use BluetoothDevice in device_discovered_cb() callback
|
||||
// and at any time afterwards, until device_lost_cb() is called.
|
||||
// It is not safe to use BluetoothDevice after returning from
|
||||
// device_lost_cb() callback.
|
||||
std::function<void(BluetoothDevice& device)> device_discovered_cb =
|
||||
DefaultCallback<BluetoothDevice&>();
|
||||
std::function<void(BluetoothDevice& device)> device_name_changed_cb =
|
||||
DefaultCallback<BluetoothDevice&>();
|
||||
std::function<void(BluetoothDevice& device)> device_lost_cb =
|
||||
DefaultCallback<BluetoothDevice&>();
|
||||
};
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#startDiscovery()
|
||||
//
|
||||
// Returns true once the process of discovery has been initiated.
|
||||
//
|
||||
// Does not take ownership of the passed-in discovery_callback -- destroying
|
||||
// that is up to the caller.
|
||||
virtual bool StartDiscovery(const DiscoveryCallback& discovery_callback) = 0;
|
||||
virtual bool StartDiscovery(DiscoveryCallback discovery_callback) = 0;
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#cancelDiscovery()
|
||||
//
|
||||
// Returns true once discovery is well and truly stopped; after this returns,
|
||||
// there must be no more invocations of the DiscoveryCallback passed in to
|
||||
// startDiscovery().
|
||||
// StartDiscovery().
|
||||
virtual bool StopDiscovery() = 0;
|
||||
|
||||
// A combination of
|
||||
@@ -101,10 +116,10 @@ class BluetoothClassicMedium {
|
||||
// (https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_(namespace_name-based))
|
||||
// UUID.
|
||||
//
|
||||
// On success, returns a new BluetoothSocket, wrapped in a ExceptionOr object.
|
||||
// On error, returns Exception object.
|
||||
virtual ExceptionOr<std::unique_ptr<BluetoothSocket>> ConnectToService(
|
||||
BluetoothDevice* remote_device, absl::string_view service_uuid) = 0;
|
||||
// On success, returns a new BluetoothSocket.
|
||||
// On error, returns nullptr.
|
||||
virtual std::unique_ptr<BluetoothSocket> ConnectToService(
|
||||
BluetoothDevice& remote_device, const std::string& service_uuid) = 0;
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#listenUsingInsecureRfcommWithServiceRecord
|
||||
//
|
||||
@@ -114,9 +129,9 @@ class BluetoothClassicMedium {
|
||||
// (https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_(namespace_name-based))
|
||||
// UUID.
|
||||
//
|
||||
// Returns Exception::kIo on error.
|
||||
virtual ExceptionOr<std::unique_ptr<BluetoothServerSocket>> ListenForService(
|
||||
absl::string_view service_name, absl::string_view service_uuid) = 0;
|
||||
// Returns nullptr error.
|
||||
virtual std::unique_ptr<BluetoothServerSocket> ListenForService(
|
||||
const std::string& service_name, const std::string& service_uuid) = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
#include "platform_v2/api/condition_variable.h"
|
||||
#include "platform_v2/api/count_down_latch.h"
|
||||
#include "platform_v2/api/crypto.h"
|
||||
#include "platform_v2/api/input_file.h"
|
||||
#include "platform_v2/api/mutex.h"
|
||||
#include "platform_v2/api/output_file.h"
|
||||
#include "platform_v2/api/scheduled_executor.h"
|
||||
#include "platform_v2/api/server_sync.h"
|
||||
#include "platform_v2/api/settable_future.h"
|
||||
@@ -41,6 +43,7 @@ class ImplementationPlatform {
|
||||
// - condition variable (must work with regular mutex only)
|
||||
// - Future<T> : to synchronize on Callable<T> schduled to execute.
|
||||
// - CountDownLatch : to ensure at least N threads are waiting.
|
||||
// - file I/O
|
||||
static std::unique_ptr<AtomicReference<absl::any>> CreateAtomicReferenceAny(
|
||||
absl::any initial_value);
|
||||
static std::unique_ptr<SettableFuture<absl::any>> CreateSettableFutureAny();
|
||||
@@ -50,6 +53,9 @@ class ImplementationPlatform {
|
||||
static std::unique_ptr<Mutex> CreateMutex(Mutex::Mode mode);
|
||||
static std::unique_ptr<ConditionVariable> CreateConditionVariable(
|
||||
Mutex* mutex);
|
||||
static std::unique_ptr<InputFile> CreateInputFile(std::int64_t payload_id,
|
||||
std::int64_t total_size);
|
||||
static std::unique_ptr<OutputFile> CreateOutputFile(std::int64_t payload_id);
|
||||
|
||||
// Java-like Executors
|
||||
static std::unique_ptr<SubmittableExecutor> CreateSingleThreadExecutor();
|
||||
@@ -65,10 +71,8 @@ class ImplementationPlatform {
|
||||
static std::unique_ptr<ServerSyncMedium> CreateServerSyncMedium();
|
||||
static std::unique_ptr<WifiMedium> CreateWifiMedium();
|
||||
static std::unique_ptr<WifiLanMedium> CreateWifiLanMedium();
|
||||
static std::unique_ptr<WebRtcSignalingMessenger>
|
||||
CreateWebRtcSignalingMessenger(absl::string_view self_id);
|
||||
static std::unique_ptr<WebRtcMedium> CreateWebRtcMedium();
|
||||
static std::string GetDeviceId();
|
||||
static std::string GetPayloadPath(std::int64_t payload_id);
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifndef PLATFORM_V2_API_WEBRTC_H_
|
||||
#define PLATFORM_V2_API_WEBRTC_H_
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
#include "webrtc/files/stable/webrtc/api/peer_connection_interface.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "webrtc/api/peer_connection_interface.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -12,33 +13,32 @@ namespace api {
|
||||
|
||||
class WebRtcSignalingMessenger {
|
||||
public:
|
||||
using OnSignalingMessageCallback = std::function<void(const ByteArray&)>;
|
||||
|
||||
virtual ~WebRtcSignalingMessenger() = default;
|
||||
|
||||
/** Called whenever we receive an inbox message from tachyon. */
|
||||
class SignalingMessageListener {
|
||||
public:
|
||||
virtual ~SignalingMessageListener() = default;
|
||||
|
||||
virtual void OnSignalingMessage(const ByteArray& message) = 0;
|
||||
};
|
||||
|
||||
class IceServersListener {
|
||||
public:
|
||||
virtual ~IceServersListener() = default;
|
||||
|
||||
virtual void OnIceServersFetched(
|
||||
std::vector<webrtc::PeerConnectionInterface::IceServer>
|
||||
ice_servers) = 0;
|
||||
};
|
||||
|
||||
virtual bool RegisterSignaling() = 0;
|
||||
virtual bool UnregisterSignaling() = 0;
|
||||
virtual bool SendMessage(std::string_view peer_id,
|
||||
virtual bool SendMessage(absl::string_view peer_id,
|
||||
const ByteArray& message) = 0;
|
||||
virtual bool StartReceivingMessages(
|
||||
const SignalingMessageListener& listener) = 0;
|
||||
virtual void GetIceServers(
|
||||
const IceServersListener& ice_servers_listener) = 0;
|
||||
|
||||
virtual bool StartReceivingMessages(OnSignalingMessageCallback listener) = 0;
|
||||
virtual void StopReceivingMessages() = 0;
|
||||
};
|
||||
|
||||
class WebRtcMedium {
|
||||
public:
|
||||
using PeerConnectionCallback =
|
||||
std::function<void(rtc::scoped_refptr<webrtc::PeerConnectionInterface>)>;
|
||||
|
||||
virtual ~WebRtcMedium() = default;
|
||||
|
||||
// Creates and returns a new webrtc::PeerConnectionInterface object via
|
||||
// |callback|.
|
||||
virtual void CreatePeerConnection(webrtc::PeerConnectionObserver* observer,
|
||||
PeerConnectionCallback callback) = 0;
|
||||
|
||||
// Returns a signaling messenger for sending WebRTC signaling messages.
|
||||
virtual std::unique_ptr<WebRtcSignalingMessenger> GetSignalingMessenger(
|
||||
absl::string_view self_id) = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
Reference in New Issue
Block a user