nearby: snapshot of cl/304428753

Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I0023ac6e40456fc4a8169c3173bcbff3b5ccc476
This commit is contained in:
Alexey Polyudov
2020-04-04 12:54:05 -07:00
parent 204f76077d
commit d455926d89
87 changed files with 2869 additions and 631 deletions
+5
View File
@@ -20,23 +20,28 @@ cc_library(
"hash_utils.h",
"input_file.h",
"input_stream.h",
"listenable_future.h",
"lock.h",
"multi_thread_executor.h",
"output_file.h",
"output_stream.h",
"scheduled_executor.h",
"server_sync.h",
"settable_future.h",
"single_thread_executor.h",
"socket.h",
"submittable_executor.h",
"system_clock.h",
"thread_utils.h",
"webrtc.h",
"wifi.h",
"wifi_lan.h",
],
deps = [
"//platform:types",
"//platform/port:down_cast",
"//platform/port:string",
"//webrtc/files/stable/webrtc/api:libjingle_peerconnection_api",
],
)
+6 -3
View File
@@ -39,7 +39,7 @@ struct BLEAdvertisementData {
std::set<std::string> service_uuids;
// Maps service UUIDs to their service data.
// Ownership of the map values is tied to ownership of BLEAdvertisementData.
std::map<std::string, ConstPtr<ByteArray> > service_data;
std::map<std::string, ConstPtr<ByteArray>> service_data;
};
// Opaque wrapper over a BLE peripheral. Must be able to uniquely identify a
@@ -217,7 +217,8 @@ class GATTServer {
// about this descriptor, please go to:
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
virtual Ptr<GATTCharacteristic> createCharacteristic(
const std::string& service_uuid, const std::string& characteristic_uuid,
const std::string& service_uuid,
const std::string& characteristic_uuid,
const std::set<GATTCharacteristic::Permission::Value>& permissions,
const std::set<GATTCharacteristic::Property::Value>& properties) = 0;
@@ -384,7 +385,9 @@ class BLEMediumV2 {
// HIGH:
// - Connection interval = ~100ms - 125ms
virtual Ptr<ClientGATTConnection> connectToGATTServer(
Ptr<BLEPeripheralV2> peripheral, MTU mtu, PowerMode::Value power_mode,
Ptr<BLEPeripheralV2> peripheral,
MTU mtu,
PowerMode::Value power_mode,
Ptr<ClientGATTConnectionLifecycleCallback>
connection_lifecycle_callback) = 0;
+7 -5
View File
@@ -60,7 +60,7 @@ class BluetoothServerSocket {
//
// The returned Ptr will be owned (and destroyed) by the caller. Returns
// Exception::IO on error.
virtual ExceptionOr<Ptr<BluetoothSocket> > accept() = 0;
virtual ExceptionOr<Ptr<BluetoothSocket>> accept() = 0;
// https://developer.android.com/reference/android/bluetooth/BluetoothServerSocket.html#close()
//
@@ -116,8 +116,9 @@ class BluetoothClassicMedium {
//
// The returned Ptr will be owned (and destroyed) by the caller. Returns
// Exception::IO on error.
virtual ExceptionOr<Ptr<BluetoothSocket> > connectToService(
Ptr<BluetoothDevice> remote_device, const std::string& service_uuid) = 0;
virtual ExceptionOr<Ptr<BluetoothSocket>> connectToService(
Ptr<BluetoothDevice> remote_device,
const std::string& service_uuid) = 0;
// https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#listenUsingInsecureRfcommWithServiceRecord
//
@@ -129,8 +130,9 @@ class BluetoothClassicMedium {
//
// The returned Ptr will be owned (and destroyed) by the caller. Returns
// Exception::IO on error.
virtual ExceptionOr<Ptr<BluetoothServerSocket> > listenForService(
const std::string& service_name, const std::string& service_uuid) = 0;
virtual ExceptionOr<Ptr<BluetoothServerSocket>> listenForService(
const std::string& service_name,
const std::string& service_uuid) = 0;
};
} // namespace nearby
+6
View File
@@ -1,6 +1,9 @@
#ifndef PLATFORM_API_EXECUTOR_H_
#define PLATFORM_API_EXECUTOR_H_
#include "platform/ptr.h"
#include "platform/runnable.h"
namespace location {
namespace nearby {
@@ -12,6 +15,9 @@ class Executor {
// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html#shutdown--
virtual void shutdown() = 0;
// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html#execute-java.lang.Runnable-
virtual void execute(Ptr<Runnable> runnable) = 0;
};
} // namespace nearby
+7
View File
@@ -1,6 +1,8 @@
#ifndef PLATFORM_API_FUTURE_H_
#define PLATFORM_API_FUTURE_H_
#include <cstdint>
#include "platform/exception.h"
namespace location {
@@ -16,6 +18,11 @@ class Future {
virtual ExceptionOr<T>
get() = 0; // throws Exception::INTERRUPTED, Exception::EXECUTION
// throws Exception::INTERRUPTED, Exception::EXECUTION
// throws Exception::TIMEOUT if |timeout_ms| is exceeded while waiting for
// result.
virtual ExceptionOr<T> get(std::int64_t timeout_ms) = 0;
};
} // namespace nearby
+1 -1
View File
@@ -16,7 +16,7 @@ class InputFile {
// The returned ConstPtr will be owned (and destroyed) by the caller.
// When we have exhausted reading the file and no bytes remain, read will
// always return an empty ConstPtr for which isNull() is true.
virtual ExceptionOr<ConstPtr<ByteArray> > read(
virtual ExceptionOr<ConstPtr<ByteArray>> read(
std::int64_t size) = 0; // throws Exception::IO when the file cannot be
// opened or read.
virtual std::string getFilePath() const = 0;
+2 -2
View File
@@ -18,9 +18,9 @@ class InputStream {
virtual ~InputStream() {}
// The returned ConstPtr will be owned (and destroyed) by the caller.
virtual ExceptionOr<ConstPtr<ByteArray> > read() = 0; // throws Exception::IO
virtual ExceptionOr<ConstPtr<ByteArray>> read() = 0; // throws Exception::IO
// The returned ConstPtr will be owned (and destroyed) by the caller.
virtual ExceptionOr<ConstPtr<ByteArray> > read(
virtual ExceptionOr<ConstPtr<ByteArray>> read(
std::int64_t size) = 0; // throws Exception::IO
virtual Exception::Value close() = 0; // throws Exception::IO
};
+28
View File
@@ -0,0 +1,28 @@
#ifndef PLATFORM_API_LISTENABLE_FUTURE_H_
#define PLATFORM_API_LISTENABLE_FUTURE_H_
#include "platform/api/executor.h"
#include "platform/api/future.h"
#include "platform/exception.h"
#include "platform/ptr.h"
#include "platform/runnable.h"
namespace location {
namespace nearby {
// A Future that accepts completion listeners.
//
// https://guava.dev/releases/20.0/api/docs/com/google/common/util/concurrent/ListenableFuture.html
template <typename T>
class ListenableFuture : public Future<T> {
public:
~ListenableFuture() override {}
// Executor is shared among multiple runnables. It is not owned by any future.
virtual void addListener(Ptr<Runnable> runnable, Executor* executor) = 0;
};
} // namespace nearby
} // namespace location
#endif // PLATFORM_API_LISTENABLE_FUTURE_H_
+2 -2
View File
@@ -11,8 +11,8 @@ namespace nearby {
//
// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool-int-
template <typename ConcreteSubmittableExecutor>
class MultiThreadExecutor :
public SubmittableExecutor<ConcreteSubmittableExecutor> {
class MultiThreadExecutor
: public SubmittableExecutor<ConcreteSubmittableExecutor> {
public:
~MultiThreadExecutor() override {}
};
+64
View File
@@ -0,0 +1,64 @@
#ifndef PLATFORM_API_SERVER_SYNC_H_
#define PLATFORM_API_SERVER_SYNC_H_
#include <string>
#include "platform/byte_array.h"
#include "platform/ptr.h"
namespace location {
namespace nearby {
// Abstraction that represents a Nearby endpoint exchanging data through
// ServerSync Medium.
class ServerSyncDevice {
public:
virtual ~ServerSyncDevice() {}
virtual std::string getName() = 0;
virtual std::string getGuid() = 0;
virtual std::string getOwnGuid() = 0;
};
// Container of operations that can be performed over the Chrome Sync medium.
class ServerSyncMedium {
public:
virtual ~ServerSyncMedium() {}
// Takes ownership of (and is responsible for destroying) the passed-in
// 'endpoint_info'.
virtual bool startAdvertising(const std::string& service_id,
const std::string& endpoint_id,
ConstPtr<ByteArray> endpoint_info) = 0;
virtual void stopAdvertising(const std::string& service_id) = 0;
class DiscoveredDeviceCallback {
public:
virtual ~DiscoveredDeviceCallback() {}
// Called on a new ServerSyncDevice discovery.
virtual void onDeviceDiscovered(Ptr<ServerSyncDevice> device,
const std::string& service_id,
const std::string& endpoint_id,
ConstPtr<ByteArray> endpoint_info) = 0;
// Called when ServerSyncDevice is no longer reachable.
virtual void onDeviceLost(Ptr<ServerSyncDevice> device,
const std::string& service_id) = 0;
};
// Returns true once the Chrome Sync scan has been initiated.
virtual bool startDiscovery(
const std::string& service_id,
Ptr<DiscoveredDeviceCallback> discovered_device_callback) = 0;
// Returns true once Chrome Sync scan for service_id is well and truly
// stopped; after this returns, there must be no more invocations of the
// DiscoveredDeviceCallback passed in to startScanning() for service_id.
virtual void stopDiscovery(const std::string& service_id) = 0;
};
} // namespace nearby
} // namespace location
#endif // PLATFORM_API_SERVER_SYNC_H_
+4 -2
View File
@@ -1,7 +1,7 @@
#ifndef PLATFORM_API_SETTABLE_FUTURE_H_
#define PLATFORM_API_SETTABLE_FUTURE_H_
#include "platform/api/future.h"
#include "platform/api/listenable_future.h"
namespace location {
namespace nearby {
@@ -10,11 +10,13 @@ namespace nearby {
//
// https://google.github.io/guava/releases/20.0/api/docs/com/google/common/util/concurrent/SettableFuture.html
template <typename T>
class SettableFuture : public Future<T> {
class SettableFuture : public ListenableFuture<T> {
public:
~SettableFuture() override {}
virtual bool set(T value) = 0;
virtual bool setException(Exception exception) = 0;
};
} // namespace nearby
+2 -2
View File
@@ -11,8 +11,8 @@ namespace nearby {
//
// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executors.html#newSingleThreadExecutor--
template <typename ConcreteSubmittableExecutor>
class SingleThreadExecutor :
public SubmittableExecutor<ConcreteSubmittableExecutor> {
class SingleThreadExecutor
: public SubmittableExecutor<ConcreteSubmittableExecutor> {
public:
~SingleThreadExecutor() override {}
};
+1 -5
View File
@@ -6,7 +6,6 @@
#include "platform/callable.h"
#include "platform/port/down_cast.h"
#include "platform/ptr.h"
#include "platform/runnable.h"
namespace location {
namespace nearby {
@@ -29,12 +28,9 @@ class SubmittableExecutor : public Executor {
~SubmittableExecutor() override {}
template <typename T>
Ptr<Future<T> > submit(Ptr<Callable<T> > callable) {
Ptr<Future<T>> submit(Ptr<Callable<T>> callable) {
return DOWN_CAST<ConcreteSubmittableExecutor*>(this)->submit(callable);
}
// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html#execute-java.lang.Runnable-
virtual void execute(Ptr<Runnable> runnable) = 0;
};
} // namespace nearby
+46
View File
@@ -0,0 +1,46 @@
#ifndef PLATFORM_API_WEBRTC_H_
#define PLATFORM_API_WEBRTC_H_
#include <vector>
#include "platform/byte_array.h"
#include "platform/ptr.h"
#include "webrtc/files/stable/webrtc/api/peer_connection_interface.h"
namespace location {
namespace nearby {
class WebRtcSignalingMessenger {
public:
virtual ~WebRtcSignalingMessenger() = default;
/** Called whenever we receive an inbox message from tachyon. */
class SignalingMessageListener {
public:
virtual ~SignalingMessageListener() = default;
virtual void onSignalingMessage(ConstPtr<ByteArray> message) = 0;
};
class IceServersListener {
public:
virtual ~IceServersListener() = default;
virtual void OnIceServersFetched(
std::vector<Ptr<webrtc::PeerConnectionInterface::IceServer>>
ice_servers) = 0;
};
virtual bool registerSignaling() = 0;
virtual bool unregisterSignaling() = 0;
virtual bool sendMessage(const string& peer_id,
ConstPtr<ByteArray> message) = 0;
virtual bool startReceivingMessages(
Ptr<SignalingMessageListener> listener) = 0;
virtual void getIceServers(Ptr<IceServersListener> ice_servers_listener) = 0;
};
} // namespace nearby
} // namespace location
#endif // PLATFORM_API_WEBRTC_H_
+3 -2
View File
@@ -58,7 +58,7 @@ class WifiMedium {
// owned (and destroyed) by the recipient of the callback methods (i.e. the
// creator of the concrete ScanResultCallback object).
virtual void onScanResults(
const std::vector<ConstPtr<WifiScanResult> >& scan_results) = 0;
const std::vector<ConstPtr<WifiScanResult>>& scan_results) = 0;
};
// Does not take ownership of the passed-in scan_result_callback -- destroying
@@ -69,7 +69,8 @@ class WifiMedium {
// WifiConnectionStatus::CONNECTED on success, or the appropriate failure code
// otherwise.
virtual WifiConnectionStatus::Value connectToNetwork(
const std::string& ssid, const std::string& password,
const std::string& ssid,
const std::string& password,
WifiAuthType::Value auth_type) = 0;
// Blocks until it's certain of there being a connection to the internet, or
+94
View File
@@ -0,0 +1,94 @@
#ifndef PLATFORM_API_WIFI_LAN_H_
#define PLATFORM_API_WIFI_LAN_H_
#include "platform/api/input_stream.h"
#include "platform/api/output_stream.h"
#include "platform/byte_array.h"
#include "platform/exception.h"
#include "platform/port/string.h"
#include "platform/ptr.h"
namespace location {
namespace nearby {
// Opaque wrapper over a WifiLan service which contains encoded service name.
class WifiLanService {
public:
virtual ~WifiLanService() = default;
virtual std::string GetName() = 0;
};
class WifiLanSocket {
public:
virtual ~WifiLanSocket() = default;
// Returns the InputStream of the WifiLanSocket, or a null Ptr<InputStream>
// on error.
//
// The returned Ptr is not owned by the caller, and can be invalidated once
// the WifiLanSocket object is destroyed.
virtual Ptr<InputStream> GetInputStream() = 0;
// Returns the OutputStream of the WifiLanSocket, or a null
// Ptr<OutputStream> on error.
//
// The returned Ptr is not owned by the caller, and can be invalidated once
// the WifiLanSocket object is destroyed.
virtual Ptr<OutputStream> GetOutputStream() = 0;
// Returns Exception::IO on error, Exception::NONE otherwise.
virtual Exception::Value Close() = 0;
// The returned Ptr is not owned by the caller, and can be invalidated once
// the WifiLanSocket object is destroyed.
virtual Ptr<WifiLanService> GetRemoteWifiLanService() = 0;
};
// Container of operations that can be performed over the WifiLan medium.
class WifiLanMedium {
public:
virtual ~WifiLanMedium() = default;
virtual bool StartAdvertising(const std::string& service_id,
const string& wifi_lan_service_info_name) = 0;
virtual void StopAdvertising(const std::string& service_id) = 0;
// Callback for WifiLan discover results.
class DiscoveredServiceCallback {
public:
virtual ~DiscoveredServiceCallback() = default;
virtual void OnServiceDiscovered(Ptr<WifiLanService> wifi_lan_service) = 0;
virtual void OnServiceLost(Ptr<WifiLanService> wifi_lan_service) = 0;
};
virtual bool StartDiscovery(
const std::string& service_id,
Ptr<DiscoveredServiceCallback> discovered_service_callback) = 0;
virtual void StopDiscovery(const std::string& service_id) = 0;
class AcceptedConnectionCallback {
public:
virtual ~AcceptedConnectionCallback() = default;
// The Ptr provided in this callback method will be owned (and
// destroyed) by the recipient of the callback methods (i.e. the creator of
// the concrete AcceptedConnectionCallback object).
virtual void OnConnectionAccepted(Ptr<WifiLanSocket> socket,
const string& service_id) = 0;
};
virtual bool StartAcceptingConnections(
const std::string& service_id,
Ptr<AcceptedConnectionCallback> accepted_connection_callback) = 0;
virtual void StopAcceptingConnections(const std::string& service_id) = 0;
virtual Ptr<WifiLanSocket> Connect(Ptr<WifiLanService> wifi_lan_service,
const std::string& service_id) = 0;
};
} // namespace nearby
} // namespace location
#endif // PLATFORM_API_WIFI_LAN_H_