Clean up unused files

PiperOrigin-RevId: 605360366
This commit is contained in:
Guogang Li
2024-02-08 10:36:20 -08:00
committed by Copybara-Service
parent 7b8436c289
commit c477809ed0
3 changed files with 0 additions and 1041 deletions
-19
View File
@@ -19,25 +19,6 @@ package(default_visibility = ["//location/nearby:__subpackages__"])
licenses(["notice"])
# Build with --config=lexan
lexan.cc_windows_dll(
name = "nearby_connections_dart",
srcs = [
"core_adapter_dart.cc",
],
hdrs = [
"core_adapter_dart.h",
],
tags = ["windows-dll"],
deps = [
"//connections:core",
"//connections/c",
"//connections/implementation/flags:connections_flags",
"//internal/flags:nearby_flags",
"//internal/platform/implementation/windows",
"//third_party/dart_lang/v2:dart_api_dl",
],
)
lexan.cc_windows_dll(
name = "nc_windows_dart",
srcs = [
-711
View File
@@ -1,711 +0,0 @@
// 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.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/dart/core_adapter_dart.h"
#include <cstddef>
#include <cstdint>
#include <string>
#include "connections/core.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/payload.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/logging.h"
namespace nearby::windows {
static CountDownLatch *adapter_finished;
StrategyW GetStrategy(StrategyDart strategy) {
switch (strategy) {
case StrategyDart::P2P_CLUSTER:
return StrategyW::kP2pCluster;
case StrategyDart::P2P_POINT_TO_POINT:
return StrategyW::kP2pPointToPoint;
case StrategyDart::P2P_STAR:
return StrategyW::kP2pStar;
}
return StrategyW::kNone;
}
ByteArray ConvertBluetoothMacAddress(absl::string_view address) {
return ByteArray(address.data());
}
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);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
adapter_finished->CountDown();
}
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;
dart_object_endpoint_id.type = Dart_CObject_kString;
dart_object_endpoint_id.value.as_string = const_cast<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_response_info.remote_endpoint_info);
Dart_CObject *elements[2];
elements[0] = &dart_object_endpoint_id;
elements[1] = &dart_object_endpoint_info;
Dart_CObject dart_object_initiated;
dart_object_initiated.type = Dart_CObject_kArray;
dart_object_initiated.value.as_array.length = 2;
dart_object_initiated.value.as_array.values = elements;
const bool result =
Dart_PostCObject_DL(current_connection_listener_dart.initiated_dart_port,
&dart_object_initiated);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerAcceptedCB(const char *endpoint_id) {
NEARBY_LOG(INFO, "Advertising accepted: id=%s", endpoint_id);
Dart_CObject dart_object_accepted;
dart_object_accepted.type = Dart_CObject_kString;
dart_object_accepted.value.as_string = const_cast<char *>(endpoint_id);
const bool result =
Dart_PostCObject_DL(current_connection_listener_dart.accepted_dart_port,
&dart_object_accepted);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerRejectedCB(const char *endpoint_id, connections::Status status) {
NEARBY_LOG(INFO, "Advertising rejected: id=%s", endpoint_id);
Dart_CObject dart_object_rejected;
dart_object_rejected.type = Dart_CObject_kString;
dart_object_rejected.value.as_string = const_cast<char *>(endpoint_id);
const bool result =
Dart_PostCObject_DL(current_connection_listener_dart.rejected_dart_port,
&dart_object_rejected);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerDisconnectedCB(const char *endpoint_id) {
NEARBY_LOG(INFO, "Advertising disconnected: id=%s", 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(
current_connection_listener_dart.disconnected_dart_port,
&dart_object_disconnected);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerBandwidthChangedCB(const char *endpoint_id, MediumW medium) {
NEARBY_LOG(INFO, "Advertising bandwidth changed: id=%s", endpoint_id);
Dart_CObject dart_object_bandwidth_changed;
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(
current_connection_listener_dart.bandwidth_changed_dart_port,
&dart_object_bandwidth_changed);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerEndpointFoundCB(const char *endpoint_id, const char *endpoint_info,
size_t endpoint_info_size,
const char *str_service_id) {
NEARBY_LOG(INFO, "Device discovered: id=%s", endpoint_id);
NEARBY_LOG(INFO, "Device discovered: service_id=%s", str_service_id);
NEARBY_LOG(INFO, "Device discovered: info=%s", endpoint_info);
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_endpoint_info;
dart_object_endpoint_info.type = Dart_CObject_kString;
dart_object_endpoint_info.value.as_string = const_cast<char *>(endpoint_info);
Dart_CObject *elements[2];
elements[0] = &dart_object_endpoint_id;
elements[1] = &dart_object_endpoint_info;
Dart_CObject dart_object_found;
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(
current_discovery_listener_dart.found_dart_port, &dart_object_found);
if (!result) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
}
void ListenerEndpointLostCB(const char *endpoint_id) {
NEARBY_LOG(INFO, "Device lost: id=%s", 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(
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 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(
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) {
NEARBY_LOG(INFO,
"Payload callback called. id: %s, "
"payload_id: %d, type: %d, offset: %d",
endpoint_id, payload.GetId(), payload.GetType(),
payload.GetOffset());
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 = payload.GetId();
switch (payload.GetType()) {
case nearby::connections::PayloadType::kBytes: {
const char *bytes = nullptr;
size_t bytes_size;
if (!payload.AsBytes(bytes, bytes_size)) {
NEARBY_LOG(INFO, "Failed to get the payload as bytes.");
return;
}
Dart_CObject dart_object_bytes;
dart_object_bytes.type = Dart_CObject_kTypedData;
dart_object_bytes.value.as_typed_data = {
.type = Dart_TypedData_kUint8,
.length = static_cast<intptr_t>(bytes_size),
.values = reinterpret_cast<const uint8_t *>(bytes),
};
Dart_CObject *elements[] = {
&dart_object_endpoint_id,
&dart_object_payload_id,
&dart_object_bytes,
};
Dart_CObject dart_object_payload;
dart_object_payload.type = Dart_CObject_kArray;
dart_object_payload.value.as_array.length = 3;
dart_object_payload.value.as_array.values = elements;
if (!Dart_PostCObject_DL(
current_payload_listener_dart.initial_byte_info_port,
&dart_object_payload)) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
return;
}
case nearby::connections::PayloadType::kStream: {
Dart_CObject *elements[] = {
&dart_object_endpoint_id,
&dart_object_payload_id,
};
Dart_CObject dart_object_payload;
dart_object_payload.type = Dart_CObject_kArray;
dart_object_payload.value.as_array.length = 2;
dart_object_payload.value.as_array.values = elements;
if (!Dart_PostCObject_DL(
current_payload_listener_dart.initial_stream_info_port,
&dart_object_payload)) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
return;
}
case nearby::connections::PayloadType::kFile: {
Dart_CObject dart_object_offset;
dart_object_offset.type = Dart_CObject_kInt64;
dart_object_offset.value.as_int64 = payload.GetOffset();
std::string path = payload.AsFile()->GetFilePath();
Dart_CObject dart_object_path;
dart_object_path.type = Dart_CObject_kString;
dart_object_path.value.as_string = const_cast<char *>(path.c_str());
Dart_CObject *elements[] = {
&dart_object_endpoint_id,
&dart_object_payload_id,
&dart_object_offset,
&dart_object_path,
};
Dart_CObject dart_object_payload;
dart_object_payload.type = Dart_CObject_kArray;
dart_object_payload.value.as_array.length = 4;
dart_object_payload.value.as_array.values = elements;
if (!Dart_PostCObject_DL(
current_payload_listener_dart.initial_file_info_port,
&dart_object_payload)) {
NEARBY_LOG(INFO, "Posting message to port failed.");
}
return;
}
default:
NEARBY_LOG(INFO, "Invalid payload type.");
return;
}
}
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, 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 = 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 =
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 = 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)payload_progress_info.status;
Dart_CObject *elements[5];
elements[0] = &dart_object_endpoint_id;
elements[1] = &dart_object_payload_id;
elements[2] = &dart_object_bytes_transferred;
elements[3] = &dart_object_total_bytes;
elements[4] = &dart_object_status;
Dart_CObject dart_object_payload_progress;
dart_object_payload_progress.type = Dart_CObject_kArray;
dart_object_payload_progress.value.as_array.length = 5;
dart_object_payload_progress.value.as_array.values = elements;
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 &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;
Dart_CObject dart_object_result_callback;
dart_object_result_callback.type = Dart_CObject_kInt64;
dart_object_result_callback.value.as_int64 = value;
const bool result =
Dart_PostCObject_DL(result_cb, &dart_object_result_callback);
if (!result) {
NEARBY_LOG(INFO, "Returning error to port failed.");
}
}
void EnableBleV2Dart(Core *pCore, int64_t enable, Dart_Port result_cb) {
if (!pCore) {
PostResult(result_cb, Status::Value::kError);
return;
}
port = result_cb;
NearbyFlags::GetInstance().OverrideBoolFlagValue(
connections::config_package_nearby::nearby_connections_feature::
kEnableBleV2,
enable);
PostResult(result_cb, Status::kSuccess);
}
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(connection_options_dart.strategy);
advertising_options.auto_upgrade_bandwidth =
connection_options_dart.auto_upgrade_bandwidth;
advertising_options.enforce_topology_constraints =
connection_options_dart.enforce_topology_constraints;
advertising_options.low_power = connection_options_dart.low_power;
advertising_options.fast_advertisement_service_uuid =
connection_options_dart.fast_advertisement_service_uuid;
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;
ConnectionListenerW listener(ListenerInitiatedCB, ListenerAcceptedCB,
ListenerRejectedCB, ListenerDisconnectedCB,
ListenerBandwidthChangedCB);
ConnectionRequestInfoW info{
connection_request_info_dart.endpoint_info,
static_cast<size_t>(connection_request_info_dart.endpoint_info_size),
listener};
ResultCallbackW callback;
SetResultCallback(callback, result_cb);
CountDownLatch finished(1);
adapter_finished = &finished;
StartAdvertising(pCore, service_id, advertising_options, info, callback);
finished.Await();
}
void StopAdvertisingDart(Core *pCore, Dart_Port dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
ResultCallbackW callback;
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
StopAdvertising(pCore, callback);
finished.Await();
}
void StartDiscoveryDart(Core *pCore, const char *service_id,
DiscoveryOptionsDart discovery_options_dart,
DiscoveryListenerDart discovery_listener_dart,
Dart_Port dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
current_discovery_listener_dart = discovery_listener_dart;
DiscoveryOptionsW discovery_options;
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 =
discovery_options_dart.fast_advertisement_service_uuid;
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);
ResultCallbackW 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 dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
ResultCallbackW callback;
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 connection_options_dart,
ConnectionRequestInfoDart connection_request_info_dart,
Dart_Port dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
current_connection_listener_dart =
connection_request_info_dart.connection_listener;
ConnectionOptionsW connection_options;
connection_options.enforce_topology_constraints = false;
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(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, 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 payload_listener_dart,
Dart_Port dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
current_payload_listener_dart = payload_listener_dart;
PayloadListenerW listener(ListenerPayloadCB, ListenerPayloadProgressCB);
ResultCallbackW callback;
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
AcceptConnection(pCore, endpoint_id, listener, callback);
finished.Await();
}
void RejectConnectionDart(Core *pCore, const char *endpoint_id,
Dart_Port dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
ResultCallbackW callback;
SetResultCallback(callback, dart_port);
CountDownLatch finished(1);
adapter_finished = &finished;
RejectConnection(pCore, endpoint_id, callback);
finished.Await();
}
void DisconnectFromEndpointDart(Core *pCore, char *endpoint_id,
Dart_Port dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
ResultCallbackW callback;
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 dart_port) {
if (!pCore) {
PostResult(dart_port, Status::Value::kError);
return;
}
port = dart_port;
ResultCallbackW callback;
std::vector<std::string> endpoint_ids = {std::string(endpoint_id)};
NEARBY_LOG(INFO, "Payload type: %d", payload_dart.type);
switch (payload_dart.type) {
case UNKNOWN:
case STREAM:
NEARBY_LOG(INFO, "Payload type not supported yet");
PostResult(dart_port, Status::Value::kPayloadUnknown);
break;
case BYTE: {
PayloadW payload(PayloadW::GenerateId(), payload_dart.data,
payload_dart.size);
std::vector<const 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;
case FILE:
NEARBY_LOG(INFO, "File name: %s, size %d", payload_dart.data,
payload_dart.size);
std::string file_name_str(payload_dart.data);
InputFileW input_file(file_name_str.c_str(), payload_dart.size);
PayloadW payload(input_file);
std::vector<const 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 nearby::windows
-311
View File
@@ -1,311 +0,0 @@
// 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.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOCATION_NEARBY_CONNECTIONS_DART_CORE_ADAPTER_DART_H_
#define LOCATION_NEARBY_CONNECTIONS_DART_CORE_ADAPTER_DART_H_
#include "third_party/dart_lang/v2/runtime/include/dart_api_dl.h"
#include "third_party/dart_lang/v2/runtime/include/dart_native_api.h"
#include "connections/c/core_adapter.h"
namespace nearby::windows {
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/plugins/nearby_connections/platform/lib/types/payload.dart)
};
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/plugins/nearby_connections/platform/lib/types/mediums.dart)
};
extern "C" {
struct AdvertisingOptionsDart {
// LINT.IfChange
StrategyDart strategy;
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;
const char *fast_advertisement_service_uuid;
// The information about this device (eg. name, device type),
// to appear on the remote device.
// Defined by client/application.
const char *device_info;
Mediums mediums;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/plugins/nearby_connections/platform/lib/types/advertising_options.dart)
};
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/plugins/nearby_connections/platform/lib/types/connection_options.dart)
};
struct DiscoveryOptionsDart {
// LINT.IfChange
StrategyDart strategy;
int64_t auto_upgrade_bandwidth;
int64_t enforce_topology_constraints;
// 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/plugins/nearby_connections/platform/lib/types/discovery_options.dart)
};
struct DiscoveryListenerDart {
// 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/plugins/nearby_connections/platform/lib/types/discovery_listener.dart)
};
struct PayloadListenerDart {
// LINT.IfChange
int64_t initial_byte_info_port;
int64_t initial_stream_info_port;
int64_t initial_file_info_port;
int64_t payload_progress_dart_port;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/plugins/nearby_connections/platform/lib/types/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/plugins/nearby_connections/platform/lib/types/connection_listener.dart)
};
struct ConnectionRequestInfoDart {
// LINT.IfChange
int endpoint_info_size;
char *endpoint_info;
ConnectionListenerDart connection_listener;
// LINT.ThenChange(//depot/google3/location/nearby/apps/helloconnections/plugins/nearby_connections/platform/lib/types/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/plugins/nearby_connections/platform/lib/types/payload.dart)
};
static void ResultCB(Status status);
static void ListenerInitiatedCB(const char *endpoint_id,
const ConnectionResponseInfoW &connection_info);
static void ListenerAcceptedCB(const char *endpoint_id);
static void ListenerRejectedCB(const char *endpoint_id,
connections::Status status);
static void ListenerDisconnectedCB(const char *endpoint_id);
static void ListenerBandwidthChangedCB(const char *endpoint_id, MediumW medium);
static void ListenerEndpointFoundCB(const char *endpoint_id,
const char *endpoint_info,
size_t endpoint_info_size,
const char *str_service_id);
static void ListenerEndpointLostCB(const char *endpoint_id);
static void ListenerEndpointDistanceChangedCB(const char *endpoint_id,
DistanceInfoW info);
static void ListenerPayloadCB(const char *endpoint_id, PayloadW &payload);
static void ListenerPayloadProgressCB(const char *endpoint_id,
const PayloadProgressInfoW &info);
DLL_API void __stdcall EnableBleV2Dart(Core *pCore, int64_t enable,
Dart_Port result_cb);
// Starts advertising an endpoint for a local app.
//
// service_id - An identifier to advertise your app to other endpoints.
// This can be an arbitrary string, so long as it uniquely
// identifies your service. A good default is to use your
// app's package name.
// options_dart - options for advertising
// info_dart - Including callbacks notified when remote
// endpoints request a connection to this endpoint.
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if advertising started successfully.
// Status::STATUS_ALREADY_ADVERTISING if the app is already advertising.
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartAdvertisingDart(Core *pCore, const char *service_id,
AdvertisingOptionsDart options_dart,
ConnectionRequestInfoDart info_dart,
Dart_Port result_cb);
// Stops advertising a local endpoint. Should be called after calling
// StartAdvertising, as soon as the application no longer needs to advertise
// itself or goes inactive. Payloads can still be sent to connected
// endpoints after advertising ends.
//
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall StopAdvertisingDart(Core *pCore, Dart_Port result_cb);
// Starts discovery for remote endpoints with the specified service ID.
//
// service_id - The ID for the service to be discovered, as specified in
// the corresponding call to StartAdvertising.
// options - The options for discovery.
// listener - Callbacks notified when a remote endpoint is discovered.
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if discovery started successfully.
// Status::STATUS_ALREADY_DISCOVERING if the app is already
// discovering the specified service.
// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently
// connected to remote endpoints; call StopAllEndpoints first.
DLL_API void __stdcall StartDiscoveryDart(Core *pCore, const char *service_id,
DiscoveryOptionsDart options_dart,
DiscoveryListenerDart listener_dart,
Dart_Port result_cb);
// Stops discovery for remote endpoints, after a previous call to
// StartDiscovery, when the client no longer needs to discover endpoints or
// goes inactive. Payloads can still be sent to connected endpoints after
// discovery ends.
//
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if none of the above errors occurred.
DLL_API void __stdcall StopDiscoveryDart(Core *pCore, Dart_Port result_cb);
// Sends a request to connect to a remote endpoint.
//
// endpoint_id - The identifier for the remote endpoint to which a
// connection request will be sent. Should match the value
// provided in a call to
// DiscoveryListener::endpoint_found_cb()
// options_dart - The options for connection.
// info_dart - Connection parameters:
// > name - A human readable name for the local endpoint, to appear on
// the remote endpoint.
// > listener - Callbacks notified when the remote endpoint sends a
// response to the connection request.
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if the connection request was sent.
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT if the app already
// has a connection to the specified endpoint.
// Status::STATUS_RADIO_ERROR if we failed to connect because of an
// issue with Bluetooth/WiFi.
// Status::STATUS_ERROR if we failed to connect for any other reason.
DLL_API void __stdcall RequestConnectionDart(
Core *pCore, const char *endpoint_id, ConnectionOptionsDart options_dart,
ConnectionRequestInfoDart info_dart, Dart_Port result_cb);
// Accepts a connection to a remote endpoint. This method must be called
// before Payloads can be exchanged with the remote endpoint.
//
// endpoint_id - The identifier for the remote endpoint. Should match the
// value provided in a call to
// ConnectionListener::onConnectionInitiated.
// listener_dart - A callback for payloads exchanged with the remote endpoint.
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK if the connection request was accepted.
// Status::STATUS_ALREADY_CONNECTED_TO_ENDPOINT if the app already.
// has a connection to the specified endpoint.
DLL_API void __stdcall AcceptConnectionDart(Core *pCore,
const char *endpoint_id,
PayloadListenerDart listener_dart,
Dart_Port result_cb);
DLL_API void __stdcall RejectConnectionDart(Core *pCore,
const char *endpoint_id,
Dart_Port result_cb);
// Disconnects from a remote endpoint. {@link Payload}s can no longer be sent
// to or received from the endpoint after this method is called.
// endpoint_id - The identifier for the remote endpoint to disconnect from.
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OK - finished successfully.
DLL_API void __stdcall DisconnectFromEndpointDart(Core *pCore,
char *endpoint_id,
Dart_Port result_cb);
// 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
// ConnectionListener::onConnectionResult().
//
// endpoint_id - Remote endpoint identifier for the to which the
// payload should be sent.
// payload - The Payload to be sent.
// result_cb - to access the status of the operation when available.
// Possible status codes include:
// Status::STATUS_OUT_OF_ORDER_API_CALL if the device has not first
// performed advertisement or discovery (to set the Strategy.)
// Status::STATUS_ENDPOINT_UNKNOWN if there's no active (or pending)
// connection to the remote endpoint.
// Status::STATUS_OK if none of the above errors occurred. Note that this
// indicates that Nearby Connections will attempt to send the Payload,
// but not that the send has successfully completed yet. Errors might
// still occur during transmission (and at different times for
// different endpoints), and will be delivered via
// PayloadCallback#onPayloadTransferUpdate.
DLL_API void __stdcall SendPayloadDart(Core *pCore, const char *endpoint_id,
PayloadDart payload_dart,
Dart_Port result_cb);
} // extern "C"
} // namespace nearby::windows
#endif // LOCATION_NEARBY_CONNECTIONS_DART_CORE_ADAPTER_DART_H_