This correctly exports the dll functions needed by the flutter app (and any other app).

PiperOrigin-RevId: 449402726
This commit is contained in:
jfcarroll
2022-05-17 23:21:55 -07:00
committed by Copybara-Service
parent 4aee0b681c
commit d0a83cee39
20 changed files with 640 additions and 418 deletions
@@ -1,4 +1,4 @@
// Copyright 2021 Google LLC
// 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.
@@ -16,9 +16,7 @@
#include <string>
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
@@ -47,6 +45,4 @@ AdvertisingOptionsW AdvertisingOptionsW::CompatibleOptions() const {
return result;
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Google LLC
// 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.
@@ -18,14 +18,15 @@
namespace location::nearby::windows {
// Connection Options: used for both Advertising and Discovery.
extern "C" {
// Advertising Options: used for Advertising.
// All fields are mutable, to make the type copy-assignable.
struct DLL_API AdvertisingOptionsW : public OptionsBaseW {
StrategyW strategy;
bool auto_upgrade_bandwidth;
bool enforce_topology_constraints;
bool low_power;
bool enable_bluetooth_listening;
bool enable_webrtc_listening;
// Whether this is intended to be used in conjunction with InjectEndpoint().
bool is_out_of_band_connection = false;
@@ -38,6 +39,7 @@ struct DLL_API AdvertisingOptionsW : public OptionsBaseW {
AdvertisingOptionsW CompatibleOptions() const;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_ADVERTISING_OPTIONS_W_H_
@@ -1,4 +1,4 @@
// Copyright 2021 Google LLC
// Copyright 2021-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.
@@ -16,9 +16,7 @@
#include <string>
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
void ConnectionOptionsW::GetMediums(const MediumW* mediums,
size_t mediums_size) const {
@@ -34,6 +32,4 @@ void ConnectionOptionsW::GetMediums(const MediumW* mediums,
return;
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
@@ -20,6 +20,8 @@
namespace location::nearby::windows {
extern "C" {
#define MAX_MEDIUMS 5
// Feature On/Off switch for mediums.
@@ -28,11 +30,10 @@ using BooleanMediumSelector = MediumSelectorW<bool>;
// Connection Options: used for both Advertising and Discovery.
// All fields are mutable, to make the type copy-assignable.
struct DLL_API ConnectionOptionsW : public OptionsBaseW {
StrategyW strategy;
bool auto_upgrade_bandwidth;
bool enforce_topology_constraints;
bool low_power;
bool enable_bluetooth_listening;
bool enable_webrtc_listening;
// Whether this is intended to be used in conjunction with InjectEndpoint().
bool is_out_of_band_connection = false;
@@ -48,6 +49,7 @@ struct DLL_API ConnectionOptionsW : public OptionsBaseW {
size_t mediums_size;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONNECTION_OPTIONS_W_H_
+30 -37
View File
@@ -1,4 +1,4 @@
// Copyright 2021 Google LLC
// Copyright 2021-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.
@@ -17,9 +17,7 @@
#include "absl/strings/str_format.h"
#include "connections/core.h"
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
Core *InitCore(connections::ServiceControllerRouter *router) {
return new nearby::connections::Core(router);
@@ -47,17 +45,17 @@ void StartAdvertising(Core *pCore, const char *service_id,
connections::AdvertisingOptions advertising_options;
advertising_options.allowed.ble = advertising_options_w.allowed.ble;
advertising_options.allowed.bluetooth =
advertising_options_w.allowed.bluetooth;
advertising_options.allowed.web_rtc = advertising_options_w.allowed.web_rtc;
advertising_options.allowed.ble = advertising_options_w.allowed.ble;
advertising_options.allowed.wifi_lan = advertising_options_w.allowed.wifi_lan;
advertising_options.allowed.web_rtc = advertising_options_w.allowed.web_rtc;
advertising_options.allowed.wifi_hotspot =
advertising_options_w.allowed.wifi_hotspot;
advertising_options.enable_bluetooth_listening = false;
advertising_options.enable_webrtc_listening = false;
advertising_options.auto_upgrade_bandwidth =
advertising_options_w.auto_upgrade_bandwidth;
advertising_options.enable_bluetooth_listening =
advertising_options_w.enable_bluetooth_listening;
advertising_options.enable_webrtc_listening =
advertising_options_w.enable_webrtc_listening;
advertising_options.enforce_topology_constraints =
advertising_options_w.enforce_topology_constraints;
if (advertising_options_w.fast_advertisement_service_uuid != nullptr) {
@@ -98,24 +96,6 @@ void StartDiscovery(connections::Core *pCore, const char *service_id,
connections::DiscoveryOptions discovery_options;
discovery_options.allowed.ble = discovery_options_w.allowed.ble;
discovery_options.allowed.bluetooth = discovery_options_w.allowed.bluetooth;
discovery_options.allowed.web_rtc = discovery_options_w.allowed.web_rtc;
discovery_options.allowed.wifi_lan = discovery_options_w.allowed.wifi_lan;
discovery_options.auto_upgrade_bandwidth =
discovery_options_w.auto_upgrade_bandwidth;
discovery_options.enforce_topology_constraints =
discovery_options_w.enforce_topology_constraints;
if (discovery_options_w.fast_advertisement_service_uuid) {
discovery_options.fast_advertisement_service_uuid =
std::string(discovery_options_w.fast_advertisement_service_uuid);
}
discovery_options.is_out_of_band_connection =
discovery_options_w.is_out_of_band_connection;
discovery_options.keep_alive_interval_millis =
discovery_options_w.keep_alive_interval_millis;
discovery_options.keep_alive_timeout_millis =
discovery_options_w.keep_alive_timeout_millis;
if (discovery_options_w.strategy == StrategyW::kNone)
discovery_options.strategy = connections::Strategy::kNone;
if (discovery_options_w.strategy == StrategyW::kP2pCluster)
@@ -124,6 +104,26 @@ void StartDiscovery(connections::Core *pCore, const char *service_id,
discovery_options.strategy = connections::Strategy::kP2pPointToPoint;
if (discovery_options_w.strategy == StrategyW::kP2pStar)
discovery_options.strategy = connections::Strategy::kP2pStar;
discovery_options.auto_upgrade_bandwidth =
discovery_options_w.auto_upgrade_bandwidth;
discovery_options.enforce_topology_constraints =
discovery_options_w.enforce_topology_constraints;
discovery_options.keep_alive_interval_millis =
discovery_options_w.keep_alive_interval_millis;
discovery_options.keep_alive_timeout_millis =
discovery_options_w.keep_alive_timeout_millis;
discovery_options.is_out_of_band_connection =
discovery_options_w.is_out_of_band_connection;
if (discovery_options_w.fast_advertisement_service_uuid) {
discovery_options.fast_advertisement_service_uuid =
std::string(discovery_options_w.fast_advertisement_service_uuid);
}
discovery_options.allowed.bluetooth = discovery_options_w.allowed.bluetooth;
discovery_options.allowed.ble = discovery_options_w.allowed.ble;
discovery_options.allowed.wifi_lan = discovery_options_w.allowed.wifi_lan;
discovery_options.allowed.wifi_hotspot =
discovery_options_w.allowed.wifi_hotspot;
discovery_options.allowed.web_rtc = discovery_options_w.allowed.web_rtc;
pCore->StartDiscovery(service_id, discovery_options, discoveryListener,
std::move(*callback.GetImpl()));
@@ -174,10 +174,6 @@ void RequestConnection(connections::Core *pCore, const char *endpoint_id,
connection_options.allowed.wifi_lan = connection_options_w.allowed.wifi_lan;
connection_options.auto_upgrade_bandwidth =
connection_options_w.auto_upgrade_bandwidth;
connection_options.enable_bluetooth_listening =
connection_options_w.enable_bluetooth_listening;
connection_options.enable_webrtc_listening =
connection_options_w.enable_webrtc_listening;
connection_options.enforce_topology_constraints =
connection_options_w.enforce_topology_constraints;
if (connection_options_w.fast_advertisement_service_uuid) {
@@ -235,10 +231,9 @@ void SendPayload(connections::Core *pCore,
if (pCore == nullptr) {
return;
}
auto payload = payloadw.GetImpl();
std::string payloadData = std::string(*endpoint_ids);
absl::Span<const std::string> span{&payloadData, 1};
pCore->SendPayload(span, std::move(*payload), *callback.GetImpl());
pCore->SendPayload(span, std::move(*payloadw.GetImpl()), *callback.GetImpl());
}
void CancelPayload(connections::Core *pCore, std::int64_t payload_id,
@@ -293,6 +288,4 @@ void CloseServiceControllerRouter(
}
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
+25 -28
View File
@@ -24,15 +24,15 @@
#include "connections/clients/windows/params_w.h"
#include "connections/clients/windows/payload_w.h"
namespace location {
namespace nearby {
namespace connections {
namespace location::nearby::connections {
class Core;
class ServiceController;
class ServiceControllerRouter;
class OfflineServiceController;
} // namespace connections
namespace windows {
} // namespace location::nearby::connections
namespace location::nearby::windows {
extern "C" {
using Core = connections::Core;
using ServiceControllerRouter = connections::ServiceControllerRouter;
@@ -51,10 +51,10 @@ using ServiceControllerRouter = connections::ServiceControllerRouter;
// Initializes a default Core instance.
// Returns the instance handle to c# client.
DLL_API Core *__stdcall InitCore(ServiceControllerRouter *);
DLL_API Core* __stdcall InitCore(ServiceControllerRouter*);
// Closes the core with stopping all endpoints, then free the memory.
DLL_API void __stdcall CloseCore(Core *);
DLL_API void __stdcall CloseCore(Core*);
// Starts advertising an endpoint for a local app.
//
@@ -74,8 +74,7 @@ DLL_API void __stdcall CloseCore(Core *);
// 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.
DLL_API void __stdcall StartAdvertising(Core *, const char *,
AdvertisingOptionsW,
DLL_API void __stdcall StartAdvertising(Core*, const char*, AdvertisingOptionsW,
ConnectionRequestInfoW,
ResultCallbackW);
@@ -87,7 +86,7 @@ DLL_API void __stdcall StartAdvertising(Core *, const char *,
// 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.
DLL_API void __stdcall StopAdvertising(Core *, ResultCallbackW);
DLL_API void __stdcall StopAdvertising(Core*, ResultCallbackW);
// Starts discovery for remote endpoints with the specified service ID.
//
@@ -102,7 +101,7 @@ DLL_API void __stdcall StopAdvertising(Core *, ResultCallbackW);
// discovering the specified service.
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartDiscovery(Core *, const char *, DiscoveryOptionsW,
DLL_API void __stdcall StartDiscovery(Core*, const char*, DiscoveryOptionsW,
DiscoveryListenerW, ResultCallbackW);
// Stops discovery for remote endpoints, after a previous call to
@@ -113,7 +112,7 @@ DLL_API void __stdcall StartDiscovery(Core *, const char *, DiscoveryOptionsW,
// 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.
DLL_API void __stdcall StopDiscovery(Core *, ResultCallbackW);
DLL_API void __stdcall StopDiscovery(Core*, ResultCallbackW);
// Invokes the discovery callback from a previous call to StartDiscovery()
// with the given endpoint info. The previous call to StartDiscovery() must
@@ -130,7 +129,7 @@ DLL_API void __stdcall StopDiscovery(Core *, ResultCallbackW);
// Status::kError if endpoint_id, endpoint_info, or
// remote_bluetooth_mac_address are malformed.
// Status::kOutOfOrderApiCall if the app is not discovering.
DLL_API void __stdcall InjectEndpoint(Core *, char *,
DLL_API void __stdcall InjectEndpoint(Core*, char*,
OutOfBandConnectionMetadataW,
ResultCallbackW);
@@ -153,7 +152,7 @@ DLL_API void __stdcall InjectEndpoint(Core *, char *,
// 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.
DLL_API void __stdcall RequestConnection(Core *, const char *,
DLL_API void __stdcall RequestConnection(Core*, const char*,
ConnectionRequestInfoW,
ConnectionOptionsW, ResultCallbackW);
@@ -169,7 +168,7 @@ DLL_API void __stdcall RequestConnection(Core *, const char *,
// 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.
DLL_API void __stdcall AcceptConnection(Core *, const char *, PayloadListenerW,
DLL_API void __stdcall AcceptConnection(Core*, const char*, PayloadListenerW,
ResultCallbackW);
// Rejects a connection to a remote endpoint.
@@ -182,7 +181,7 @@ DLL_API void __stdcall AcceptConnection(Core *, const char *, PayloadListenerW,
// 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.
DLL_API void __stdcall RejectConnection(Core *, const char *, ResultCallbackW);
DLL_API void __stdcall RejectConnection(Core*, const char*, ResultCallbackW);
// Sends a Payload to a remote endpoint. Payloads can only be sent to remote
// endpoints once a notice of connection acceptance has been delivered via
@@ -203,7 +202,7 @@ DLL_API void __stdcall RejectConnection(Core *, const char *, ResultCallbackW);
// still occur during transmission (and at different times for
// different endpoints), and will be delivered via
// PayloadCallback#onPayloadTransferUpdate.
DLL_API void __stdcall SendPayload(Core *, char **, size_t, PayloadW,
DLL_API void __stdcall SendPayload(Core*, char**, size_t, PayloadW,
ResultCallbackW);
// Cancels a Payload currently in-flight to or from remote endpoint(s).
@@ -212,7 +211,7 @@ DLL_API void __stdcall SendPayload(Core *, char **, size_t, PayloadW,
// 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.
DLL_API void __stdcall CancelPayload(Core *, int64_t, ResultCallbackW);
DLL_API void __stdcall CancelPayload(Core*, int64_t, ResultCallbackW);
// Disconnects from a remote endpoint. {@link Payload}s can no longer be sent
// to or received from the endpoint after this method is called.
@@ -221,7 +220,7 @@ DLL_API void __stdcall CancelPayload(Core *, int64_t, ResultCallbackW);
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall DisconnectFromEndpoint(Core *, char *, ResultCallbackW);
DLL_API void __stdcall DisconnectFromEndpoint(Core*, char*, ResultCallbackW);
// Disconnects from, and removes all traces of, all connected and/or
// discovered endpoints. This call is expected to be preceded by a call to
@@ -232,7 +231,7 @@ DLL_API void __stdcall DisconnectFromEndpoint(Core *, char *, ResultCallbackW);
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall StopAllEndpoints(Core *, ResultCallbackW);
DLL_API void __stdcall StopAllEndpoints(Core*, ResultCallbackW);
// Sends a request to initiate connection bandwidth upgrade.
//
@@ -243,21 +242,19 @@ DLL_API void __stdcall StopAllEndpoints(Core *, ResultCallbackW);
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall InitiateBandwidthUpgrade(Core *, char *,
ResultCallbackW);
DLL_API void __stdcall InitiateBandwidthUpgrade(Core*, char*, ResultCallbackW);
// Gets the local endpoint generated by Nearby Connections.
DLL_API const char *__stdcall GetLocalEndpointId(Core *);
DLL_API const char* __stdcall GetLocalEndpointId(Core*);
// Initializes a default ServiceControllerRouter instance.
// Returns the instance handle to c# client.
DLL_API ServiceControllerRouter *__stdcall InitServiceControllerRouter();
DLL_API ServiceControllerRouter* __stdcall InitServiceControllerRouter();
// Close a ServiceControllerRouter instance.
DLL_API void __stdcall CloseServiceControllerRouter(ServiceControllerRouter *);
DLL_API void __stdcall CloseServiceControllerRouter(ServiceControllerRouter*);
} // namespace windows
} // namespace nearby
} // namespace location
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CORE_ADAPTER_H_
@@ -21,12 +21,13 @@
#include "connections/core.h"
#include "connections/payload.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/file.h"
#include "internal/platform/logging.h"
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
static CountDownLatch *adapter_finished;
StrategyW GetStrategy(StrategyDart strategy) {
switch (strategy) {
@@ -44,24 +45,26 @@ ByteArray ConvertBluetoothMacAddress(absl::string_view address) {
return ByteArray(address.data());
}
static Dart_Port *port;
static ConnectionRequestInfoDart *pinfo_dart;
static DiscoveryListenerDart *pdiscovery_listener_dart;
static PayloadListenerDart *ppayload_listener_dart;
static Dart_Port port;
static DiscoveryListenerDart current_discovery_listener_dart;
static ConnectionListenerDart current_connection_listener_dart;
static PayloadListenerDart current_payload_listener_dart;
void ResultCB(Status status) {
(void)status; // Avoid unused parameter warning
Dart_CObject dart_object_result_callback;
dart_object_result_callback.type = Dart_CObject_kInt64;
dart_object_result_callback.value.as_int64 = status.value;
const bool result = Dart_PostCObject_DL(*port, &dart_object_result_callback);
const bool result = Dart_PostCObject_DL(port, &dart_object_result_callback);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
adapter_finished->CountDown();
}
void ListenerInitiatedCB(const char *endpoint_id,
const ConnectionResponseInfoW &connection_info) {
void ListenerInitiatedCB(
const char *endpoint_id,
const ConnectionResponseInfoW &connection_response_info) {
NEARBY_LOG(INFO, "Advertising initiated: id=%s", endpoint_id);
Dart_CObject dart_object_endpoint_id;
@@ -71,7 +74,7 @@ void ListenerInitiatedCB(const char *endpoint_id,
Dart_CObject dart_object_endpoint_info;
dart_object_endpoint_info.type = Dart_CObject_kString;
dart_object_endpoint_info.value.as_string =
const_cast<char *>(connection_info.remote_endpoint_info);
const_cast<char *>(connection_response_info.remote_endpoint_info);
Dart_CObject *elements[2];
elements[0] = &dart_object_endpoint_id;
@@ -83,7 +86,8 @@ void ListenerInitiatedCB(const char *endpoint_id,
dart_object_initiated.value.as_array.values = elements;
const bool result =
Dart_PostCObject_DL(pinfo_dart->initiated_cb, &dart_object_initiated);
Dart_PostCObject_DL(current_connection_listener_dart.initiated_dart_port,
&dart_object_initiated);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
@@ -95,7 +99,8 @@ void ListenerAcceptedCB(const char *endpoint_id) {
dart_object_accepted.type = Dart_CObject_kString;
dart_object_accepted.value.as_string = const_cast<char *>(endpoint_id);
const bool result =
Dart_PostCObject_DL(pinfo_dart->accepted_cb, &dart_object_accepted);
Dart_PostCObject_DL(current_connection_listener_dart.accepted_dart_port,
&dart_object_accepted);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
@@ -107,7 +112,8 @@ void ListenerRejectedCB(const char *endpoint_id, connections::Status status) {
dart_object_rejected.type = Dart_CObject_kString;
dart_object_rejected.value.as_string = const_cast<char *>(endpoint_id);
const bool result =
Dart_PostCObject_DL(pinfo_dart->rejected_cb, &dart_object_rejected);
Dart_PostCObject_DL(current_connection_listener_dart.rejected_dart_port,
&dart_object_rejected);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
@@ -118,8 +124,9 @@ void ListenerDisconnectedCB(const char *endpoint_id) {
Dart_CObject dart_object_disconnected;
dart_object_disconnected.type = Dart_CObject_kString;
dart_object_disconnected.value.as_string = const_cast<char *>(endpoint_id);
const bool result = Dart_PostCObject_DL(pinfo_dart->disconnected_cb,
&dart_object_disconnected);
const bool result = Dart_PostCObject_DL(
current_connection_listener_dart.disconnected_dart_port,
&dart_object_disconnected);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
@@ -132,8 +139,9 @@ void ListenerBandwidthChangedCB(const char *endpoint_id, MediumW medium) {
dart_object_bandwidth_changed.type = Dart_CObject_kString;
dart_object_bandwidth_changed.value.as_string =
const_cast<char *>(endpoint_id);
const bool result = Dart_PostCObject_DL(pinfo_dart->bandwidth_changed_cb,
&dart_object_bandwidth_changed);
const bool result = Dart_PostCObject_DL(
current_connection_listener_dart.bandwidth_changed_dart_port,
&dart_object_bandwidth_changed);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
@@ -162,8 +170,8 @@ void ListenerEndpointFoundCB(const char *endpoint_id, const char *endpoint_info,
dart_object_found.type = Dart_CObject_kArray;
dart_object_found.value.as_array.length = 2;
dart_object_found.value.as_array.values = elements;
const bool result = Dart_PostCObject_DL(pdiscovery_listener_dart->found_cb,
&dart_object_found);
const bool result = Dart_PostCObject_DL(
current_discovery_listener_dart.found_dart_port, &dart_object_found);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
@@ -173,30 +181,30 @@ void ListenerEndpointLostCB(const char *endpoint_id) {
Dart_CObject dart_object_lost;
dart_object_lost.type = Dart_CObject_kString;
dart_object_lost.value.as_string = const_cast<char *>(endpoint_id);
const bool result =
Dart_PostCObject_DL(pdiscovery_listener_dart->lost_cb, &dart_object_lost);
const bool result = Dart_PostCObject_DL(
current_discovery_listener_dart.lost_dart_port, &dart_object_lost);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerEndpointDistanceChangedCB(const char *endpoint_id,
DistanceInfoW info) {
(void)info; // Avoid unused parameter warning
DistanceInfoW distance_info) {
(void)distance_info; // Avoid unused parameter warning
NEARBY_LOG(INFO, "Device distance changed: id=%s", endpoint_id);
Dart_CObject dart_object_distance_changed;
dart_object_distance_changed.type = Dart_CObject_kString;
dart_object_distance_changed.value.as_string =
const_cast<char *>(endpoint_id);
const bool result =
Dart_PostCObject_DL(pdiscovery_listener_dart->distance_changed_cb,
&dart_object_distance_changed);
const bool result = Dart_PostCObject_DL(
current_discovery_listener_dart.distance_changed_dart_port,
&dart_object_distance_changed);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerPayloadCB(const char *endpoint_id, PayloadW payload) {
void ListenerPayloadCB(const char *endpoint_id, PayloadW &payload) {
NEARBY_LOG(INFO,
"Payload callback called. id: %s, "
"payload_id: %d, type: %d, offset: %d",
@@ -252,38 +260,41 @@ void ListenerPayloadCB(const char *endpoint_id, PayloadW payload) {
dart_object_payload.value.as_array.length = 5;
dart_object_payload.value.as_array.values = elements;
if (!Dart_PostCObject_DL(ppayload_listener_dart->payload_cb,
if (!Dart_PostCObject_DL(current_payload_listener_dart.payload_dart_port,
&dart_object_payload)) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerPayloadProgressCB(const char *endpoint_id,
const PayloadProgressInfoW &info) {
void ListenerPayloadProgressCB(
const char *endpoint_id,
const PayloadProgressInfoW &payload_progress_info) {
NEARBY_LOG(INFO,
"Payload progress callback called. id: %s, "
"payload_id: %d, bytes transferred: %d, total: %d, status: %d",
endpoint_id, info.payload_id, info.bytes_transferred,
info.total_bytes, info.status);
endpoint_id, payload_progress_info.payload_id,
payload_progress_info.bytes_transferred,
payload_progress_info.total_bytes, payload_progress_info.status);
Dart_CObject dart_object_endpoint_id;
dart_object_endpoint_id.type = Dart_CObject_kString;
dart_object_endpoint_id.value.as_string = const_cast<char *>(endpoint_id);
Dart_CObject dart_object_payload_id;
dart_object_payload_id.type = Dart_CObject_kInt64;
dart_object_payload_id.value.as_int64 = info.payload_id;
dart_object_payload_id.value.as_int64 = payload_progress_info.payload_id;
Dart_CObject dart_object_bytes_transferred;
dart_object_bytes_transferred.type = Dart_CObject_kInt64;
dart_object_bytes_transferred.value.as_int64 = info.bytes_transferred;
dart_object_bytes_transferred.value.as_int64 =
payload_progress_info.bytes_transferred;
Dart_CObject dart_object_total_bytes;
dart_object_total_bytes.type = Dart_CObject_kInt64;
dart_object_total_bytes.value.as_int64 = info.total_bytes;
dart_object_total_bytes.value.as_int64 = payload_progress_info.total_bytes;
Dart_CObject dart_object_status;
dart_object_status.type = Dart_CObject_kInt64;
dart_object_status.value.as_int64 = (int64_t)info.status;
dart_object_status.value.as_int64 = (int64_t)payload_progress_info.status;
Dart_CObject *elements[5];
elements[0] = &dart_object_endpoint_id;
@@ -297,19 +308,20 @@ void ListenerPayloadProgressCB(const char *endpoint_id,
dart_object_payload_progress.value.as_array.length = 5;
dart_object_payload_progress.value.as_array.values = elements;
if (!Dart_PostCObject_DL(ppayload_listener_dart->payload_progress_cb,
&dart_object_payload_progress)) {
if (!Dart_PostCObject_DL(
current_payload_listener_dart.payload_progress_dart_port,
&dart_object_payload_progress)) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void SetResultCallback(ResultCallbackW &callback, Dart_Port &dart_port) {
port = &dart_port;
callback.result_cb = ResultCB;
void SetResultCallback(ResultCallbackW &result_callback, Dart_Port &dart_port) {
port = dart_port;
result_callback.result_cb = ResultCB;
}
void PostResult(Dart_Port &result_cb, Status::Value value) {
port = &result_cb;
port = result_cb;
Dart_CObject dart_object_result_callback;
dart_object_result_callback.type = Dart_CObject_kInt64;
dart_object_result_callback.value.as_int64 = value;
@@ -320,180 +332,245 @@ void PostResult(Dart_Port &result_cb, Status::Value value) {
}
}
void StartAdvertisingDart(Core *pCore, const char *service_id,
ConnectionOptionsDart options_dart,
ConnectionRequestInfoDart info_dart,
Dart_Port result_cb) {
port = &result_cb;
pinfo_dart = &info_dart;
void StartAdvertisingDart(
Core *pCore, const char *service_id,
AdvertisingOptionsDart connection_options_dart,
ConnectionRequestInfoDart connection_request_info_dart,
Dart_Port result_cb) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
return;
}
port = result_cb;
current_connection_listener_dart =
connection_request_info_dart.connection_listener;
AdvertisingOptionsW advertising_options;
advertising_options.strategy = GetStrategy(options_dart.strategy);
advertising_options.strategy = GetStrategy(connection_options_dart.strategy);
advertising_options.auto_upgrade_bandwidth =
options_dart.auto_upgrade_bandwidth;
connection_options_dart.auto_upgrade_bandwidth;
advertising_options.enforce_topology_constraints =
options_dart.enforce_topology_constraints;
advertising_options.allowed.bluetooth = options_dart.enable_bluetooth;
advertising_options.allowed.ble = options_dart.enable_ble;
advertising_options.low_power = options_dart.use_low_power_mode;
connection_options_dart.enforce_topology_constraints;
advertising_options.low_power = connection_options_dart.low_power;
advertising_options.fast_advertisement_service_uuid =
options_dart.discover_fast_advertisements
? "0000FE2C-0000-1000-8000-00805F9B34FB"
: "";
advertising_options.allowed.wifi_lan = options_dart.enable_wifi_lan;
advertising_options.allowed.wifi_hotspot = options_dart.enable_wifi_hotspot;
advertising_options.allowed.web_rtc = options_dart.enable_web_rtc;
connection_options_dart.fast_advertisement_service_uuid;
ConnectionListenerW listener;
ConnectionRequestInfoW info{info_dart.endpoint_info,
strlen(info_dart.endpoint_info), listener};
advertising_options.allowed.bluetooth =
connection_options_dart.mediums.bluetooth;
advertising_options.allowed.ble = connection_options_dart.mediums.ble;
advertising_options.allowed.wifi_lan =
connection_options_dart.mediums.wifi_lan;
advertising_options.allowed.wifi_hotspot =
connection_options_dart.mediums.wifi_hotspot;
advertising_options.allowed.web_rtc = connection_options_dart.mediums.web_rtc;
info.listener.initiated_cb = ListenerInitiatedCB;
info.listener.accepted_cb = ListenerAcceptedCB;
info.listener.rejected_cb = ListenerRejectedCB;
info.listener.disconnected_cb = ListenerDisconnectedCB;
info.listener.bandwidth_changed_cb = ListenerBandwidthChangedCB;
ConnectionListenerW listener(ListenerInitiatedCB, ListenerAcceptedCB,
ListenerRejectedCB, ListenerDisconnectedCB,
ListenerBandwidthChangedCB);
ConnectionRequestInfoW info{
connection_request_info_dart.endpoint_info,
strlen(connection_request_info_dart.endpoint_info), listener};
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
StartAdvertising(pCore, service_id, std::move(advertising_options), info,
callback);
CountDownLatch finished(1);
adapter_finished = &finished;
StartAdvertising(pCore, service_id, advertising_options, info, callback);
finished.Await();
}
void StopAdvertisingDart(Core *pCore, Dart_Port result_cb) {
void StopAdvertisingDart(Core *pCore, Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
port = dart_port;
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
StopAdvertising(pCore, callback);
finished.Await();
}
void StartDiscoveryDart(Core *pCore, const char *service_id,
ConnectionOptionsDart options_dart,
DiscoveryListenerDart listener_dart,
Dart_Port result_cb) {
DiscoveryOptionsDart discovery_options_dart,
DiscoveryListenerDart discovery_listener_dart,
Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
pdiscovery_listener_dart = &listener_dart;
port = dart_port;
current_discovery_listener_dart = discovery_listener_dart;
DiscoveryOptionsW discovery_options;
discovery_options.strategy = GetStrategy(options_dart.strategy);
discovery_options.allowed.bluetooth = options_dart.enable_bluetooth;
discovery_options.allowed.ble = options_dart.enable_ble;
discovery_options.allowed.wifi_lan = options_dart.enable_wifi_lan;
discovery_options.strategy = GetStrategy(discovery_options_dart.strategy);
discovery_options.allowed.web_rtc = false;
discovery_options.enforce_topology_constraints = true;
// This needs to be passed in by the UI. If it's null, then no
// fast_advertisement_service. Otherwise this interface will always
// and forever be locked into 0000FE2C-0000-1000-8000-00805F9B34FB
// whenever fast advertisement service is requested.
discovery_options.fast_advertisement_service_uuid =
options_dart.discover_fast_advertisements
? "0000FE2C-0000-1000-8000-00805F9B34FB"
: "";
discovery_options_dart.fast_advertisement_service_uuid;
DiscoveryListenerW listener;
listener.endpoint_found_cb = ListenerEndpointFoundCB;
listener.endpoint_lost_cb = ListenerEndpointLostCB;
listener.endpoint_distance_changed_cb = ListenerEndpointDistanceChangedCB;
discovery_options.allowed.bluetooth =
discovery_options_dart.mediums.bluetooth;
discovery_options.allowed.ble = discovery_options_dart.mediums.ble;
discovery_options.allowed.wifi_lan = discovery_options_dart.mediums.wifi_lan;
discovery_options.allowed.wifi_hotspot =
discovery_options_dart.mediums.wifi_hotspot;
discovery_options.allowed.web_rtc = discovery_options_dart.mediums.web_rtc;
DiscoveryListenerW listener(ListenerEndpointFoundCB, ListenerEndpointLostCB,
ListenerEndpointDistanceChangedCB);
Status request_result;
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
StartDiscovery(pCore, service_id, std::move(discovery_options), listener,
callback);
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
StartDiscovery(pCore, service_id, discovery_options, listener, callback);
finished.Await();
}
void StopDiscoveryDart(Core *pCore, Dart_Port result_cb) {
void StopDiscoveryDart(Core *pCore, Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
port = dart_port;
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
StopDiscovery(pCore, callback);
adapter_finished->Await();
}
void RequestConnectionDart(Core *pCore, const char *endpoint_id,
ConnectionOptionsDart options_dart,
ConnectionRequestInfoDart info_dart,
Dart_Port result_cb) {
void RequestConnectionDart(
Core *pCore, const char *endpoint_id,
ConnectionOptionsDart connection_options_dart,
ConnectionRequestInfoDart connection_request_info_dart,
Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
pinfo_dart = &info_dart;
port = dart_port;
current_connection_listener_dart =
connection_request_info_dart.connection_listener;
ConnectionOptionsW connection_options;
connection_options.enforce_topology_constraints = false;
connection_options.allowed.bluetooth = options_dart.enable_bluetooth;
connection_options.allowed.ble = options_dart.enable_ble;
connection_options.allowed.wifi_lan = options_dart.enable_wifi_lan;
connection_options.allowed.wifi_hotspot = options_dart.enable_wifi_hotspot;
connection_options.allowed.web_rtc = options_dart.enable_web_rtc;
connection_options.remote_bluetooth_mac_address =
connection_options_dart.remote_bluetooth_mac_address;
connection_options.fast_advertisement_service_uuid =
connection_options_dart.fast_advertisement_service_uuid;
connection_options.keep_alive_interval_millis =
connection_options_dart.keep_alive_interval_millis;
connection_options.keep_alive_timeout_millis =
connection_options_dart.keep_alive_timeout_millis;
connection_options.allowed.bluetooth =
connection_options_dart.mediums.bluetooth;
connection_options.allowed.ble = connection_options_dart.mediums.ble;
connection_options.allowed.wifi_lan =
connection_options_dart.mediums.wifi_lan;
connection_options.allowed.wifi_hotspot =
connection_options_dart.mediums.wifi_hotspot;
connection_options.allowed.web_rtc = connection_options_dart.mediums.web_rtc;
ConnectionListenerW listener;
ConnectionListenerW listener(ListenerInitiatedCB, ListenerAcceptedCB,
ListenerRejectedCB, ListenerDisconnectedCB,
ListenerBandwidthChangedCB);
ConnectionRequestInfoW info{info_dart.endpoint_info,
strlen(info_dart.endpoint_info), listener};
info.listener.initiated_cb = ListenerInitiatedCB;
info.listener.accepted_cb = ListenerAcceptedCB;
info.listener.rejected_cb = ListenerRejectedCB;
info.listener.disconnected_cb = ListenerDisconnectedCB;
info.listener.bandwidth_changed_cb = ListenerBandwidthChangedCB;
ConnectionRequestInfoW info{
connection_request_info_dart.endpoint_info,
strlen(connection_request_info_dart.endpoint_info), listener};
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
RequestConnection(pCore, endpoint_id, info, std::move(connection_options),
callback);
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
RequestConnection(pCore, endpoint_id, info, connection_options, callback);
adapter_finished->Await();
}
void AcceptConnectionDart(Core *pCore, const char *endpoint_id,
PayloadListenerDart listener_dart,
Dart_Port result_cb) {
PayloadListenerDart payload_listener_dart,
Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
ppayload_listener_dart = &listener_dart;
PayloadListenerW listener;
listener.payload_cb = ListenerPayloadCB;
listener.payload_progress_cb = ListenerPayloadProgressCB;
port = dart_port;
current_payload_listener_dart = payload_listener_dart;
PayloadListenerW listener(ListenerPayloadCB, ListenerPayloadProgressCB);
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
AcceptConnection(pCore, endpoint_id, listener, callback);
finished.Await();
}
void DisconnectFromEndpointDart(Core *pCore, char *endpoint_id,
Dart_Port result_cb) {
Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
port = dart_port;
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
DisconnectFromEndpoint(pCore, endpoint_id, callback);
finished.Await();
}
void SendPayloadDart(Core *pCore, const char *endpoint_id,
PayloadDart payload_dart, Dart_Port result_cb) {
PayloadDart payload_dart, Dart_Port dart_port) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
PostResult(dart_port, Status::Value::kError);
return;
}
port = &result_cb;
port = dart_port;
ResultCallbackW callback;
std::vector<std::string> endpoint_ids = {std::string(endpoint_id)};
@@ -502,48 +579,61 @@ void SendPayloadDart(Core *pCore, const char *endpoint_id,
case UNKNOWN:
case STREAM:
NEARBY_LOG(INFO, "Payload type not supported yet");
PostResult(result_cb, Status::Value::kPayloadUnknown);
PostResult(dart_port, Status::Value::kPayloadUnknown);
break;
case BYTE: {
PayloadW payload(PayloadW::GenerateId(), payload_dart.data,
payload_dart.size);
// TODO(jfcarroll): This code is untested and may break. We're trying
// to convert a vector<std::string> to an array of string pointers.
// Also, these will need to be freed somewhere, somehow, I haven't
// investigated how to do this at this time.
char **ids = new char *[endpoint_ids.size()];
int id_count;
std::vector<char *> c_string_array;
for (id_count = 0; id_count < endpoint_ids.size(); id_count++) {
ids[id_count] = new char[endpoint_ids[id_count].size()];
strncpy(ids[id_count], endpoint_ids[id_count].data(),
endpoint_ids[id_count].size());
}
SendPayload(pCore, ids, id_count, std::move(payload), callback);
}
SetResultCallback(callback, result_cb);
break;
std::transform(endpoint_ids.begin(), endpoint_ids.end(),
std::back_inserter(c_string_array),
[](const std::string &s) {
char *pc = new char[s.size() + 1];
strncpy(pc, s.c_str(), s.size() + 1);
return pc;
});
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
SendPayload(pCore, c_string_array.data(), c_string_array.size(),
std::move(payload), callback);
adapter_finished->Await();
} break;
case FILE:
NEARBY_LOG(INFO, "File name: %s, size %d", payload_dart.data,
payload_dart.size);
std::string file_name_str(payload_dart.data);
InputFile input_file(file_name_str, payload_dart.size);
PayloadW payload(input_file);
char **ids;
int id_count;
ids = new char *();
for (id_count = 0; id_count < endpoint_ids.size(); id_count++) {
ids[id_count] = new char[endpoint_ids[id_count].size()];
strncpy(ids[id_count], endpoint_ids[id_count].c_str(),
endpoint_ids[id_count].size());
}
SendPayload(pCore, ids, id_count, std::move(payload), callback);
SetResultCallback(callback, result_cb);
std::vector<char *> c_string_array;
std::transform(endpoint_ids.begin(), endpoint_ids.end(),
std::back_inserter(c_string_array),
[](const std::string &s) {
char *pc = new char[s.size() + 1];
strncpy(pc, s.c_str(), s.size() + 1);
return pc;
});
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
SendPayload(pCore, c_string_array.data(), c_string_array.size(),
std::move(payload), callback);
adapter_finished->Await();
break;
}
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
@@ -19,64 +19,125 @@
#include "third_party/dart_lang/v2/runtime/include/dart_native_api.h"
#include "connections/clients/windows/core_adapter.h"
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
enum StrategyDart {
enum class StrategyDart {
P2P_CLUSTER = 0,
P2P_STAR,
P2P_POINT_TO_POINT,
};
enum PayloadType {
// LINT.IfChange
UNKNOWN = 0,
BYTE,
STREAM,
FILE,
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/payload.dart)
};
struct ConnectionOptionsDart {
struct Mediums {
// LINT.IfChange
int64_t bluetooth;
int64_t ble;
int64_t wifi_lan;
int64_t wifi_hotspot;
int64_t web_rtc;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/mediums.dart)
};
extern "C" {
struct AdvertisingOptionsDart {
// LINT.IfChange
StrategyDart strategy;
int64_t auto_upgrade_bandwidth;
int64_t enforce_topology_constraints;
int64_t enable_bluetooth;
int64_t enable_ble;
int64_t advertise_nearby_notifications_beacon;
int64_t use_low_power_mode;
int64_t discover_fast_advertisements;
int64_t enable_wifi_lan;
int64_t enable_wifi_hotspot;
int64_t enable_nfc;
int64_t enable_wifi_aware;
int64_t enable_web_rtc;
int64_t low_power;
// Whether this is intended to be used in conjunction with InjectEndpoint().
int64_t is_out_of_band_connection = false;
const char *fast_advertisement_service_uuid;
Mediums mediums;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/advertising_options.dart)
};
struct ConnectionRequestInfoDart {
char *endpoint_info;
int64_t initiated_cb;
int64_t accepted_cb;
int64_t rejected_cb;
int64_t disconnected_cb;
int64_t bandwidth_changed_cb;
struct ConnectionOptionsDart {
// LINT.IfChange
StrategyDart strategy;
// Whether this is intended to be used in conjunction with InjectEndpoint().
int64_t auto_upgrade_bandwidth;
int64_t enforce_topology_constraints;
int64_t low_power;
// Whether this is intended to be used in conjunction with InjectEndpoint().
int64_t is_out_of_band_connection = false;
char *remote_bluetooth_mac_address;
char *fast_advertisement_service_uuid;
int64_t keep_alive_interval_millis;
int64_t keep_alive_timeout_millis;
Mediums mediums;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/connection_options.dart)
};
struct DiscoveryOptionsDart {
// LINT.IfChange
StrategyDart strategy;
int64_t auto_upgrade_bandwidth;
int64_t enforce_topology_constraints;
int64_t keep_alive_interval_millis = 0;
int64_t keep_alive_timeout_millis = 0;
// Whether this is intended to be used in conjunction with InjectEndpoint().
int64_t is_out_of_band_connection = false;
const char *fast_advertisement_service_uuid;
const char *remote_bluetooth_mac_address;
Mediums mediums;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/discovery_options.dart)
};
struct DiscoveryListenerDart {
int64_t found_cb;
int64_t lost_cb;
int64_t distance_changed_cb;
// LINT.IfChange
int64_t found_dart_port;
int64_t lost_dart_port;
int64_t distance_changed_dart_port;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/discovery_listener.dart)
};
struct PayloadListenerDart {
int64_t payload_cb;
int64_t payload_progress_cb;
// LINT.IfChange
int64_t payload_dart_port;
int64_t payload_progress_dart_port;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/payload_listener.dart)
};
struct ConnectionListenerDart {
// LINT.IfChange
int64_t initiated_dart_port;
int64_t accepted_dart_port;
int64_t rejected_dart_port;
int64_t disconnected_dart_port;
int64_t bandwidth_changed_dart_port;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/connection_listener.dart)
};
struct ConnectionRequestInfoDart {
// LINT.IfChange
char *endpoint_info;
ConnectionListenerDart connection_listener;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/connection_request_info.dart)
};
struct PayloadDart {
// LINT.IfChange
int64_t id;
PayloadType type;
int64_t size;
char *data;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/flutter/lib/payload.dart)
};
static void ResultCB(Status status);
@@ -115,7 +176,7 @@ static void ListenerPayloadProgressCB(const char *endpoint_id,
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartAdvertisingDart(Core *pCore, const char *service_id,
ConnectionOptionsDart options_dart,
AdvertisingOptionsDart options_dart,
ConnectionRequestInfoDart info_dart,
Dart_Port result_cb);
@@ -143,7 +204,7 @@ DLL_API void __stdcall StopAdvertisingDart(Core *pCore, Dart_Port result_cb);
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartDiscoveryDart(Core *pCore, const char *service_id,
ConnectionOptionsDart options_dart,
DiscoveryOptionsDart options_dart,
DiscoveryListenerDart listener_dart,
Dart_Port result_cb);
@@ -230,9 +291,7 @@ DLL_API void __stdcall DisconnectFromEndpointDart(Core *pCore,
DLL_API void __stdcall SendPayloadDart(Core *pCore, const char *endpoint_id,
PayloadDart payload_dart,
Dart_Port result_cb);
} // namespace windows
} // namespace nearby
} // namespace location
} // extern "C"
} // namespace location::nearby::windows
#endif // LOCATION_NEARBY_CONNECTIONS_WINDOWS_CORE_ADAPTER_DART_H_
@@ -1,4 +1,4 @@
// Copyright 2021 Google LLC
// 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.
@@ -16,9 +16,7 @@
#include <string>
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
@@ -47,6 +45,4 @@ DiscoveryOptionsW DiscoveryOptionsW::CompatibleOptions() const {
return result;
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Google LLC
// 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.
@@ -19,6 +19,8 @@
namespace location::nearby::windows {
extern "C" {
// Connection Options: used for both Advertising and Discovery.
// All fields are mutable, to make the type copy-assignable.
struct DLL_API DiscoveryOptionsW : public OptionsBaseW {
@@ -38,6 +40,7 @@ struct DLL_API DiscoveryOptionsW : public OptionsBaseW {
DiscoveryOptionsW CompatibleOptions() const;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_DISCOVERY_OPTIONS_W_H_
+3 -7
View File
@@ -1,4 +1,4 @@
// Copyright 2020-2022 Google LLC
// 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.
@@ -14,9 +14,7 @@
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONFIG_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONFIG_H_
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
#ifdef _WIN32 // These storage class specifiers only matter to win32 dll
// builds.
@@ -31,8 +29,6 @@ namespace windows {
#define DLL_API // We're not building a win32 dll, leave the source unchanged.
#endif // _WIN32
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_CONFIG_H_
+79 -61
View File
@@ -1,4 +1,4 @@
// Copyright 2021 Google LLC
// 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.
@@ -16,8 +16,7 @@
#include "connections/listeners.h"
namespace location {
namespace nearby {
namespace location::nearby {
// Must implement Deleters, since the connections classes weren't
// fully defined in the header
namespace connections {
@@ -59,17 +58,24 @@ ResultCallbackW::ResultCallbackW(ResultCallbackW &&other) noexcept {
impl_ = std::move(other.impl_);
}
ConnectionListenerW::ConnectionListenerW()
: impl_(std::unique_ptr<connections::ConnectionListener,
ConnectionListenerW::ConnectionListenerW(InitiatedCB initiatedCB,
AcceptedCB acceptedCB,
RejectedCB rejectedCB,
DisconnectedCB disconnectedCB,
BandwidthChangedCB bandwidthChangedCB)
: initiated_cb(initiatedCB),
accepted_cb(acceptedCB),
rejected_cb(rejectedCB),
disconnected_cb(disconnectedCB),
bandwidth_changed_cb(bandwidthChangedCB),
impl_(std::unique_ptr<connections::ConnectionListener,
connections::ConnectionListenerDeleter>(
new connections::ConnectionListener())) {
CHECK(initiated_cb != nullptr);
auto i = initiated_cb;
impl_->initiated_cb =
[this](
const std::string &endpoint_id,
[i](const std::string &endpoint_id,
const connections::ConnectionResponseInfo connection_response_info) {
if (this->initiated_cb == nullptr) {
return;
}
ConnectionResponseInfoW connection_response_info_w{
connection_response_info.remote_endpoint_info.data(),
connection_response_info.remote_endpoint_info.size(),
@@ -78,28 +84,32 @@ ConnectionListenerW::ConnectionListenerW()
connection_response_info.raw_authentication_token.size(),
connection_response_info.is_incoming_connection,
connection_response_info.is_connection_verified};
this->initiated_cb(endpoint_id.c_str(), connection_response_info_w);
i(endpoint_id.c_str(), connection_response_info_w);
};
impl_->accepted_cb = [this](const std::string &endpoint_id) {
if (this->accepted_cb != nullptr) {
this->accepted_cb(endpoint_id.c_str());
}
CHECK(accepted_cb != nullptr);
auto a = accepted_cb;
impl_->accepted_cb = [a](const std::string &endpoint_id) {
a(endpoint_id.c_str());
};
impl_->rejected_cb = [this](const std::string &endpoint_id, Status status) {
if (this->rejected_cb != nullptr) {
this->rejected_cb(endpoint_id.c_str(), status);
}
CHECK(rejected_cb != nullptr);
auto r = rejected_cb;
impl_->rejected_cb = [r](const std::string &endpoint_id, Status status) {
r(endpoint_id.c_str(), status);
};
impl_->disconnected_cb = [this](const std::string &endpoint_id) {
if (this->disconnected_cb != nullptr) {
this->disconnected_cb(endpoint_id.c_str());
}
CHECK(disconnected_cb != nullptr);
auto d = disconnected_cb;
impl_->disconnected_cb = [d](const std::string &endpoint_id) {
d(endpoint_id.c_str());
};
impl_->bandwidth_changed_cb = [this](const std::string &endpoint_id,
connections::Medium medium) {
if (this->bandwidth_changed_cb != nullptr) {
this->bandwidth_changed_cb(endpoint_id.c_str(), medium);
}
CHECK(bandwidth_changed_cb != nullptr);
auto bwc = bandwidth_changed_cb;
impl_->bandwidth_changed_cb = [bwc](const std::string &endpoint_id,
connections::Medium medium) {
bwc(endpoint_id.c_str(), medium);
};
}
@@ -115,14 +125,18 @@ ConnectionListenerW::ConnectionListenerW(ConnectionListenerW &other) {
ConnectionListenerW::ConnectionListenerW(ConnectionListenerW &&other) noexcept =
default;
DiscoveryListenerW::DiscoveryListenerW()
: impl_(new connections::DiscoveryListener()) {
DiscoveryListenerW::DiscoveryListenerW(
EndpointFoundCB endpointFoundCB, EndpointLostCB endpointLostCB,
EndpointDistanceChangedCB endpointDistanceChangedCB)
: endpoint_found_cb(endpointFoundCB),
endpoint_lost_cb(endpointLostCB),
endpoint_distance_changed_cb(endpointDistanceChangedCB),
impl_(new connections::DiscoveryListener()) {
CHECK(endpoint_distance_changed_cb != nullptr);
auto epdc = endpoint_distance_changed_cb;
impl_->endpoint_distance_changed_cb =
[this](const std::string &endpoint_id,
[epdc](const std::string &endpoint_id,
connections::DistanceInfo distance_info) {
if (this->endpoint_distance_changed_cb == nullptr) {
return;
}
DistanceInfoW distanceInfoW = DistanceInfoW::kUnknown;
switch (distance_info) {
case connections::DistanceInfo::kFar:
@@ -137,20 +151,22 @@ DiscoveryListenerW::DiscoveryListenerW()
case connections::DistanceInfo::kUnknown:
break;
}
endpoint_distance_changed_cb(endpoint_id.c_str(), distanceInfoW);
epdc(endpoint_id.c_str(), distanceInfoW);
};
impl_->endpoint_found_cb = [this](const std::string &endpoint_id,
ByteArray endpoint_info,
const std::string &service_id) {
if (endpoint_found_cb != nullptr) {
endpoint_found_cb(endpoint_id.c_str(), endpoint_info.data(),
endpoint_info.size(), service_id.c_str());
}
CHECK(endpoint_found_cb != nullptr);
auto epf = endpoint_found_cb;
impl_->endpoint_found_cb = [epf](const std::string &endpoint_id,
ByteArray endpoint_info,
const std::string &service_id) {
epf(endpoint_id.c_str(), endpoint_info.data(), endpoint_info.size(),
service_id.c_str());
};
impl_->endpoint_lost_cb = [this](const std::string &endpoint_id) {
if (this->endpoint_lost_cb != nullptr) {
this->endpoint_lost_cb(endpoint_id.c_str());
}
CHECK(endpoint_lost_cb != nullptr);
auto epl = endpoint_lost_cb;
impl_->endpoint_lost_cb = [epl](const std::string &endpoint_id) {
epl(endpoint_id.c_str());
};
}
@@ -168,17 +184,19 @@ DiscoveryListenerW::DiscoveryListenerW(DiscoveryListenerW &&other) noexcept {
impl_ = std::move(other.impl_);
}
PayloadListenerW::PayloadListenerW()
: impl_(std::unique_ptr<connections::PayloadListener,
PayloadListenerW::PayloadListenerW(PayloadCB payloadCB,
PayloadProgressCB payloadProgressCB)
: payload_cb(payloadCB),
payload_progress_cb(payloadProgressCB),
impl_(std::unique_ptr<connections::PayloadListener,
connections::PayloadListenerDeleter>(
new connections::PayloadListener())) {
impl_->payload_cb = [this](const std::string &endpoint_id,
connections::Payload payload) {
CHECK(payload_cb != nullptr);
auto pcb = payload_cb;
impl_->payload_cb = [pcb](const std::string &endpoint_id,
connections::Payload payload) {
PayloadW payloadW;
if (payload_cb == nullptr) {
return;
}
switch (payload.GetType()) {
case connections::PayloadType::kBytes: {
payloadW = PayloadW(payload.AsBytes().data(), payload.AsBytes().size());
@@ -188,6 +206,7 @@ PayloadListenerW::PayloadListenerW()
InputFile file(std::move(*payload.AsFile()));
payloadW = PayloadW(file);
} break;
// TODO(jfcarroll): Figure out how to capture type kStream.
// case connections::PayloadType::kStream: {
// payloadW = PayloadW(payload.AsStream());
@@ -201,14 +220,14 @@ PayloadListenerW::PayloadListenerW()
break;
}
}
payload_cb(endpoint_id.c_str(), std::move(payloadW));
pcb(endpoint_id.c_str(), payloadW);
};
CHECK(payload_progress_cb != nullptr);
auto ppcb = payload_progress_cb;
impl_->payload_progress_cb =
[this](const std::string &endpoint_id,
[ppcb](const std::string &endpoint_id,
connections::PayloadProgressInfo payload_progress_info) {
if (payload_progress_cb == nullptr) {
return;
}
PayloadProgressInfoW payload_progress_info_w;
payload_progress_info_w.payload_id = payload_progress_info.payload_id;
payload_progress_info_w.total_bytes = payload_progress_info.total_bytes;
@@ -234,7 +253,7 @@ PayloadListenerW::PayloadListenerW()
break;
}
payload_progress_cb(endpoint_id.c_str(), payload_progress_info_w);
ppcb(endpoint_id.c_str(), payload_progress_info_w);
};
}
@@ -247,5 +266,4 @@ PayloadListenerW::PayloadListenerW(PayloadListenerW &&other) noexcept {
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby
+58 -41
View File
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Google LLC
// 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.
@@ -26,6 +26,7 @@
// - a subset of listener callbacks may be overridden, while others may remain
// default-initialized.
// - callbacks may be initialized with lambdas; lambda definitions are concize.
#include "connections/clients/windows/medium_selector_w.h"
#include "connections/clients/windows/payload_w.h"
#include "connections/status.h"
@@ -36,22 +37,22 @@ namespace location::nearby {
namespace connections {
struct ConnectionListener;
struct ConnectionListenerDeleter {
void operator()(connections::ConnectionListener *p);
void operator()(connections::ConnectionListener* p);
};
struct DiscoveryListener;
struct DiscoveryListenerDeleter {
void operator()(connections::DiscoveryListener *p);
void operator()(connections::DiscoveryListener* p);
};
struct PayloadListener;
struct PayloadListenerDeleter {
void operator()(connections::PayloadListener *p);
void operator()(connections::PayloadListener* p);
};
struct ResultCallback;
struct ResultCallbackDeleter {
void operator()(connections::ResultCallback *p);
void operator()(connections::ResultCallback* p);
};
struct ConnectionResponseInfo;
@@ -73,6 +74,8 @@ void DefaultConstructor(T t, C c) {}
template <class T, class C, class D>
void DefaultConstructor(T t, C c, size_t size, D d) {}
extern "C" {
// Common callback for asynchronously invoked methods.
// Called after a job scheduled for execution is completed.
// This is not the same as completion of the associated process,
@@ -84,8 +87,8 @@ struct DLL_API ResultCallbackW {
// Status::kSuccess, if successful; anything else indicates failure.
ResultCallbackW();
~ResultCallbackW();
ResultCallbackW(ResultCallbackW &other);
ResultCallbackW(ResultCallbackW &&other) noexcept;
ResultCallbackW(ResultCallbackW& other);
ResultCallbackW(ResultCallbackW&& other) noexcept;
void (*result_cb)(Status status) = DefaultConstructor;
@@ -102,10 +105,10 @@ struct DLL_API ResultCallbackW {
};
struct DLL_API ConnectionResponseInfoW {
const char *remote_endpoint_info;
const char* remote_endpoint_info;
size_t remote_endpoint_info_size;
const char *authentication_token;
const char *raw_authentication_token;
const char* authentication_token;
const char* raw_authentication_token;
size_t raw_authentication_token_size;
bool is_incoming_connection = false;
bool is_connection_verified = false;
@@ -131,9 +134,19 @@ enum class DLL_API DistanceInfoW {
};
struct DLL_API ConnectionListenerW {
ConnectionListenerW();
ConnectionListenerW(ConnectionListenerW &other);
ConnectionListenerW(ConnectionListenerW &&other) noexcept;
typedef void (*InitiatedCB)(const char* endpoint_id,
const ConnectionResponseInfoW& info);
typedef void (*AcceptedCB)(const char* endpoint_id);
typedef void (*RejectedCB)(const char* endpoint_id, Status status);
typedef void (*DisconnectedCB)(const char* endpoint_id);
typedef void (*BandwidthChangedCB)(const char* endpoint_id, MediumW medium);
ConnectionListenerW(InitiatedCB, AcceptedCB, RejectedCB, DisconnectedCB,
BandwidthChangedCB);
ConnectionListenerW(ConnectionListenerW& other);
ConnectionListenerW(ConnectionListenerW&& other) noexcept;
// 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
@@ -152,37 +165,33 @@ struct DLL_API ConnectionListenerW {
//
// endpoint_id - The identifier for the remote endpoint.
// info - Other relevant information about the connection.
void (*initiated_cb)(const char *endpoint_id,
const ConnectionResponseInfoW &info) =
DefaultConstructor;
InitiatedCB initiated_cb = DefaultConstructor;
// Called after both sides have accepted the connection.
// Both sides may now send Payloads to each other.
// Call Core::SendPayload() or wait for incoming PayloadListener::OnPayload().
//
// endpoint_id - The identifier for the remote endpoint.
void (*accepted_cb)(const char *endpoint_id) = DefaultConstructor;
AcceptedCB accepted_cb = DefaultConstructor;
// Called when either side rejected the connection.
// Payloads can not be exchaged. Call Core::DisconnectFromEndpoint()
// to terminate connection.
//
// endpoint_id - The identifier for the remote endpoint.
void (*rejected_cb)(const char *endpoint_id,
Status status) = DefaultConstructor;
RejectedCB rejected_cb = DefaultConstructor;
// Called when a remote endpoint is disconnected or has become unreachable.
// At this point service (re-)discovery may start again.
//
// endpoint_id - The identifier for the remote endpoint.
void (*disconnected_cb)(const char *endpoint_id) = DefaultConstructor;
DisconnectedCB disconnected_cb = DefaultConstructor;
// Called when the connection's available bandwidth has changed.
//
// endpoint_id - The identifier for the remote endpoint.
// medium - Medium we upgraded to.
void (*bandwidth_changed_cb)(const char *endpoint_id,
MediumW medium) = DefaultConstructor;
BandwidthChangedCB bandwidth_changed_cb = DefaultConstructor;
std::unique_ptr<connections::ConnectionListener,
connections::ConnectionListenerDeleter>
@@ -197,33 +206,40 @@ struct DLL_API ConnectionListenerW {
};
struct DLL_API DiscoveryListenerW {
DiscoveryListenerW();
DiscoveryListenerW(DiscoveryListenerW &other);
DiscoveryListenerW(DiscoveryListenerW &&other) noexcept;
typedef void (*EndpointFoundCB)(const char* endpoint_id,
const char* endpoint_info,
size_t endpoint_info_size,
const char* service_id);
typedef void (*EndpointLostCB)(const char* endpoint_id);
typedef void (*EndpointDistanceChangedCB)(const char* endpoint_id,
DistanceInfoW info);
DiscoveryListenerW(EndpointFoundCB endpointFoundCB,
EndpointLostCB endpointLostCB,
EndpointDistanceChangedCB endpointDistanceChangedCB);
DiscoveryListenerW(DiscoveryListenerW& other);
DiscoveryListenerW(DiscoveryListenerW&& other) noexcept;
// Called when a remote endpoint is discovered.
//
// endpoint_id - The ID of the remote endpoint that was discovered.
// endpoint_info - The info of the remote endpoint representd by ByteArray.
// service_id - The ID of the service advertised by the remote endpoint.
void (*endpoint_found_cb)(const char *endpoint_id, const char *endpoint_info,
size_t endpoint_info_size,
const char *service_id) = DefaultConstructor;
EndpointFoundCB endpoint_found_cb = DefaultConstructor;
// Called when a remote endpoint is no longer discoverable; only called for
// endpoints that previously had been passed to {@link
// #onEndpointFound(String, DiscoveredEndpointInfo)}.
//
// endpoint_id - The ID of the remote endpoint that was lost.
void (*endpoint_lost_cb)(const char *endpoint_id) = DefaultConstructor;
EndpointLostCB endpoint_lost_cb = DefaultConstructor;
// Called when a remote endpoint is found with an updated distance.
//
// arguments:
// endpoint_id - The ID of the remote endpoint that was lost.
// info - The distance info, encoded as enum value.
void (*endpoint_distance_changed_cb)(const char *endpoint_id,
DistanceInfoW info) = DefaultConstructor;
EndpointDistanceChangedCB endpoint_distance_changed_cb = DefaultConstructor;
std::unique_ptr<connections::DiscoveryListener,
connections::DiscoveryListenerDeleter>
@@ -237,11 +253,14 @@ struct DLL_API DiscoveryListenerW {
impl_;
};
class DLL_API PayloadListenerW {
public:
PayloadListenerW();
PayloadListenerW(PayloadListenerW &other);
PayloadListenerW(PayloadListenerW &&other) noexcept;
struct DLL_API PayloadListenerW {
typedef void (*PayloadCB)(const char* endpoint_id, PayloadW& payload);
typedef void (*PayloadProgressCB)(const char* endpoint_id,
const PayloadProgressInfoW& info);
PayloadListenerW(PayloadCB, PayloadProgressCB);
PayloadListenerW(PayloadListenerW& other);
PayloadListenerW(PayloadListenerW&& other) noexcept;
// 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
@@ -251,8 +270,7 @@ class DLL_API PayloadListenerW {
// endpoint_id - The identifier for the remote endpoint that sent the
// payload.
// payload - The Payload object received.
void (*payload_cb)(const char *endpoint_id,
PayloadW payload) = DefaultConstructor;
PayloadCB payload_cb = DefaultConstructor;
// Called with progress information about an active Payload transfer, either
// incoming or outgoing.
@@ -261,9 +279,7 @@ class DLL_API PayloadListenerW {
// receiving this payload.
// info - The PayloadProgressInfo structure describing the status of
// the transfer.
void (*payload_progress_cb)(const char *endpoint_id,
const PayloadProgressInfoW &info) =
DefaultConstructor;
PayloadProgressCB payload_progress_cb = DefaultConstructor;
std::unique_ptr<connections::PayloadListener,
connections::PayloadListenerDeleter>
@@ -277,6 +293,7 @@ class DLL_API PayloadListenerW {
impl_;
};
} // extern "C"
} // namespace windows
} // namespace location::nearby
+4 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Google LLC
// 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.
@@ -19,6 +19,8 @@
namespace location::nearby::windows {
extern "C" {
// Connection Options: used for both Advertising and Discovery.
// All fields are mutable, to make the type copy-assignable.
struct OptionsBaseW {
@@ -26,6 +28,7 @@ struct OptionsBaseW {
BooleanMediumSelectorW allowed{BooleanMediumSelectorW().SetAll(true)};
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OPTIONS_BASE_W_H_
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Google LLC
// 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.
@@ -23,6 +23,8 @@
namespace location::nearby::windows {
extern "C" {
// Metadata injected to facilitate out-of-band connections. The medium field is
// required, and the other fields are only specified for a specific medium.
// Currently, Bluetooth is the only supported medium for out-of-band
@@ -50,6 +52,7 @@ struct DLL_API OutOfBandConnectionMetadataW {
size_t remote_bluetooth_mac_address_size;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_OUT_OF_BAND_CONNECTION_METADATA_H_
+3
View File
@@ -21,6 +21,8 @@
namespace location::nearby::windows {
extern "C" {
// Used by Discovery in Core::RequestConnection().
// Used by Advertising in Core::StartAdvertising().
struct DLL_API ConnectionRequestInfoW {
@@ -34,6 +36,7 @@ struct DLL_API ConnectionRequestInfoW {
ConnectionListenerW& listener;
};
} // extern "C"
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PARAMS_W_H_
+3 -5
View File
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// 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.
@@ -17,8 +17,7 @@
#include "internal/platform/byte_array.h"
#include "internal/platform/payload_id.h"
namespace location {
namespace nearby {
namespace location::nearby {
// Must implement Deleter since Payload wasn't fully defined in
// the header
namespace connections {
@@ -129,5 +128,4 @@ PayloadW::GetImpl() {
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby
+3
View File
@@ -36,6 +36,8 @@ class InputFile;
class InputStream;
namespace windows {
extern "C" {
// Payload is default-constructible, and moveable, but not copyable container
// that holds at most one instance of one of:
// ByteArray, InputStream, or InputFile.
@@ -94,6 +96,7 @@ class DLL_API PayloadW {
std::unique_ptr<connections::Payload, connections::PayloadDeleter> impl_;
};
} // extern "C"
} // namespace windows
} // namespace location::nearby
+3 -7
View File
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// 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.
@@ -14,9 +14,7 @@
#include "connections/clients/windows/strategy_w.h"
namespace location {
namespace nearby {
namespace windows {
namespace location::nearby::windows {
const StrategyW StrategyW::kNone = {StrategyW::ConnectionType::kNone,
StrategyW::TopologyType::kUnknown};
@@ -56,6 +54,4 @@ bool operator!=(const StrategyW& lhs, const StrategyW& rhs) {
return !(lhs == rhs);
}
} // namespace windows
} // namespace nearby
} // namespace location
} // namespace location::nearby::windows
+52 -1
View File
@@ -14,10 +14,57 @@
#include "connections/payload.h"
#include <string>
namespace location {
namespace nearby {
namespace connections {
namespace {
std::string SepFinder(std::string s, size_t index) {
std::string filename = s.substr(index + 1, s.length() - index);
size_t lastindex = filename.find_last_of('.');
std::string rawname = filename.substr(0, lastindex);
return rawname;
}
std::string getFileName(const std::string& s) {
char forwardSep = '/';
char backwardSep = '\\';
size_t lastForwardSepIndex = s.rfind(forwardSep, s.length());
size_t lastBackwardSepIndex = s.rfind(backwardSep, s.length());
if (lastForwardSepIndex == std::string::npos &&
lastBackwardSepIndex == std::string::npos) {
// no file name found
return ("");
}
// If we have a forward sep
if (lastForwardSepIndex != std::string::npos) {
// and if backward sep doesn't exist
if (lastBackwardSepIndex == std::string::npos) {
// Construct filename from forward sep
std::string rawname = SepFinder(s, lastForwardSepIndex);
return (rawname);
}
// backward sep also exists
if (lastForwardSepIndex > lastBackwardSepIndex) {
// the forward sep is the last
std::string rawname = SepFinder(s, lastForwardSepIndex);
return (rawname);
}
// The backward sep is the last
std::string rawname = SepFinder(s, lastBackwardSepIndex);
return (rawname);
}
std::string rawname = SepFinder(s, lastBackwardSepIndex);
return (rawname);
}
} // namespace
// Payload is default-constructible, and moveable, but not copyable container
// that holds at most one instance of one of:
// ByteArray, InputStream, or InputFile.
@@ -38,11 +85,15 @@ Payload::Payload(const ByteArray& bytes)
Payload::Payload(InputFile input_file)
: id_(std::hash<std::string>()(input_file.GetFilePath())),
file_name_(getFileName(input_file.GetFilePath())),
type_(PayloadType::kFile),
content_(std::move(input_file)) {}
Payload::Payload(Id id, InputFile input_file)
: id_(id), type_(PayloadType::kFile), content_(std::move(input_file)) {}
: id_(id),
file_name_(getFileName(input_file.GetFilePath())),
type_(PayloadType::kFile),
content_(std::move(input_file)) {}
Payload::Payload(std::string parent_folder, std::string file_name,
InputFile input_file)