diff --git a/windows/BUILD b/windows/BUILD index 1fe8ad6d..f7906412 100644 --- a/windows/BUILD +++ b/windows/BUILD @@ -25,6 +25,31 @@ cc_windows_dll( tags = ["windows-dll"], deps = [ "//absl/strings", + "//third_party/dart_lang/v2:dart_api_dl", + "//core", + "//platform/impl/windows", + "//webrtc/api:create_peerconnection_factory", + ], +) + +# Build with --config=lexan +# TODO(b/203019344) Move this configuration under dart folder and create a BUILD there. +cc_windows_dll( + name = "core_adapter_dart", + srcs = [ + "core_adapter.cc", + "dart/core_adapter_dart.cc", + ], + hdrs = [ + "core_adapter.h", + "dart/core_adapter_dart.h", + ], + copts = ["-DCORE_ADAPTER_DART_BUILD_DLL -DCORE_ADAPTER_DLL -DCOMPILING_CORE"], + defines = ["CORE_ADAPTER_DART_DLL"], + tags = ["windows-dll"], + deps = [ + "//absl/strings", + "//third_party/dart_lang/v2:dart_api_dl", "//core", "//platform/impl/windows", "//webrtc/api:create_peerconnection_factory", diff --git a/windows/core_adapter.cc b/windows/core_adapter.cc index c2c8d154..272b97ba 100644 --- a/windows/core_adapter.cc +++ b/windows/core_adapter.cc @@ -20,11 +20,11 @@ namespace location { namespace nearby { namespace connections { -DLL_API Core* InitCore(ServiceControllerRouter* router) { +Core* InitCore(ServiceControllerRouter* router) { return new Core(router); } -DLL_API void CloseCore(Core* pCore) { +void CloseCore(Core* pCore) { if (pCore) { pCore->StopAllEndpoints( {.result_cb = @@ -34,7 +34,7 @@ DLL_API void CloseCore(Core* pCore) { } } -DLL_API void StartAdvertising(Core* pCore, const char* service_id, +void StartAdvertising(Core* pCore, const char* service_id, ConnectionOptions options, ConnectionRequestInfo info, ResultCallback callback) { @@ -43,13 +43,13 @@ DLL_API void StartAdvertising(Core* pCore, const char* service_id, } } -DLL_API void StopAdvertising(Core* pCore, ResultCallback callback) { +void StopAdvertising(Core* pCore, ResultCallback callback) { if (pCore) { pCore->StopAdvertising(callback); } } -DLL_API void StartDiscovery(Core* pCore, const char* service_id, +void StartDiscovery(Core* pCore, const char* service_id, ConnectionOptions options, DiscoveryListener listener, ResultCallback callback) { @@ -58,13 +58,13 @@ DLL_API void StartDiscovery(Core* pCore, const char* service_id, } } -DLL_API void StopDiscovery(Core* pCore, ResultCallback callback) { +void StopDiscovery(Core* pCore, ResultCallback callback) { if (pCore) { pCore->StopDiscovery(callback); } } -DLL_API void InjectEndpoint(Core* pCore, char* service_id, +void InjectEndpoint(Core* pCore, char* service_id, OutOfBandConnectionMetadata metadata, ResultCallback callback) { if (pCore) { @@ -72,7 +72,7 @@ DLL_API void InjectEndpoint(Core* pCore, char* service_id, } } -DLL_API void RequestConnection(Core* pCore, const char* endpoint_id, +void RequestConnection(Core* pCore, const char* endpoint_id, ConnectionRequestInfo info, ConnectionOptions options, ResultCallback callback) { @@ -81,7 +81,7 @@ DLL_API void RequestConnection(Core* pCore, const char* endpoint_id, } } -DLL_API void AcceptConnection(Core* pCore, const char* endpoint_id, +void AcceptConnection(Core* pCore, const char* endpoint_id, PayloadListener listener, ResultCallback callback) { if (pCore) { @@ -89,14 +89,14 @@ DLL_API void AcceptConnection(Core* pCore, const char* endpoint_id, } } -DLL_API void RejectConnection(Core* pCore, const char* endpoint_id, +void RejectConnection(Core* pCore, const char* endpoint_id, ResultCallback callback) { if (pCore) { pCore->RejectConnection(endpoint_id, callback); } } -DLL_API void SendPayload(Core* pCore, +void SendPayload(Core* pCore, // todo(jfcarroll) this is being exported, needs to be // refactored to return a plain old c type absl::Span endpoint_ids, @@ -106,34 +106,34 @@ DLL_API void SendPayload(Core* pCore, } } -DLL_API void CancelPayload(Core* pCore, std::int64_t payload_id, +void CancelPayload(Core* pCore, std::int64_t payload_id, ResultCallback callback) { if (pCore) { pCore->CancelPayload(payload_id, callback); } } -DLL_API void DisconnectFromEndpoint(Core* pCore, char* endpoint_id, +void DisconnectFromEndpoint(Core* pCore, char* endpoint_id, ResultCallback callback) { if (pCore) { pCore->DisconnectFromEndpoint(endpoint_id, callback); } } -DLL_API void StopAllEndpoints(Core* pCore, ResultCallback callback) { +void StopAllEndpoints(Core* pCore, ResultCallback callback) { if (pCore) { pCore->StopAllEndpoints(callback); } } -DLL_API void InitiateBandwidthUpgrade(Core* pCore, char* endpoint_id, +void InitiateBandwidthUpgrade(Core* pCore, char* endpoint_id, ResultCallback callback) { if (pCore) { pCore->InitiateBandwidthUpgrade(endpoint_id, callback); } } -DLL_API const char* GetLocalEndpointId(Core* pCore) { +const char* GetLocalEndpointId(Core* pCore) { if (pCore) { std::string endpoint_id = pCore->GetLocalEndpointId(); char* result = new char[endpoint_id.length() + 1]; @@ -143,11 +143,11 @@ DLL_API const char* GetLocalEndpointId(Core* pCore) { return "Null-Core"; } -DLL_API ServiceControllerRouter* InitServiceControllerRouter() { +ServiceControllerRouter* InitServiceControllerRouter() { return new ServiceControllerRouter(); } -DLL_API void CloseServiceControllerRouter(ServiceControllerRouter* pRouter) { +void CloseServiceControllerRouter(ServiceControllerRouter* pRouter) { if (pRouter) { delete pRouter; } diff --git a/windows/core_adapter.h b/windows/core_adapter.h index ff1175b5..26f89af0 100644 --- a/windows/core_adapter.h +++ b/windows/core_adapter.h @@ -18,8 +18,10 @@ #include "absl/types/span.h" // todo(jfcarroll) This cannot remain. It exposes stuff the client doesn't need. -#include "core/internal/offline_service_controller.h" +#include \ +"third_party/nearby_connections/cpp/core/internal/offline_service_controller.h" +#define DLL_EXPORT extern "C" __declspec(dllexport) namespace location { namespace nearby { namespace connections { @@ -31,17 +33,17 @@ class ServiceControllerRouter; // app side. If no factory is provided, it will initialize a new // factory creating OffilineServiceController. // Returns the instance handle to c# client. -DLL_API Core* __stdcall InitCoreWithServiceControllerFactory( +DLL_EXPORT Core* __stdcall InitCoreWithServiceControllerFactory( std::function factory = []() { return new OfflineServiceController; }); // Initializes a default Core instance. // Returns the instance handle to c# client. -DLL_API Core* __stdcall InitCore(ServiceControllerRouter* router); +DLL_EXPORT Core* __stdcall InitCore(ServiceControllerRouter* router); // Closes the core with stopping all endpoints, then free the memory. -DLL_API void __stdcall CloseCore(Core* pCore); +DLL_EXPORT void __stdcall CloseCore(Core* pCore); // Starts advertising an endpoint for a local app. // @@ -61,7 +63,7 @@ DLL_API void __stdcall CloseCore(Core* pCore); // 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* pCore, const char* service_id, +DLL_EXPORT void __stdcall StartAdvertising(Core* pCore, const char* service_id, ConnectionOptions options, ConnectionRequestInfo info, ResultCallback callback); @@ -74,7 +76,7 @@ DLL_API void __stdcall StartAdvertising(Core* pCore, const char* service_id, // 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* pCore, ResultCallback callback); +DLL_EXPORT void __stdcall StopAdvertising(Core* pCore, ResultCallback callback); // Starts discovery for remote endpoints with the specified service ID. // @@ -89,7 +91,7 @@ DLL_API void __stdcall StopAdvertising(Core* pCore, ResultCallback callback); // 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* pCore, const char* service_id, +DLL_EXPORT void __stdcall StartDiscovery(Core* pCore, const char* service_id, ConnectionOptions options, DiscoveryListener listener, ResultCallback callback); @@ -102,7 +104,7 @@ DLL_API void __stdcall StartDiscovery(Core* pCore, const char* service_id, // 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* pCore, ResultCallback callback); +DLL_EXPORT void __stdcall StopDiscovery(Core* pCore, ResultCallback callback); // Invokes the discovery callback from a previous call to StartDiscovery() // with the given endpoint info. The previous call to StartDiscovery() must @@ -119,7 +121,7 @@ DLL_API void __stdcall StopDiscovery(Core* pCore, ResultCallback callback); // 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* pCore, char* service_id, +DLL_EXPORT void __stdcall InjectEndpoint(Core* pCore, char* service_id, OutOfBandConnectionMetadata metadata, ResultCallback callback); @@ -142,10 +144,11 @@ DLL_API void __stdcall InjectEndpoint(Core* pCore, char* service_id, // 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* pCore, const char* endpoint_id, - ConnectionRequestInfo info, - ConnectionOptions options, - ResultCallback callback); +DLL_EXPORT void __stdcall RequestConnection(Core* pCore, + const char* endpoint_id, + ConnectionRequestInfo info, + ConnectionOptions options, + ResultCallback callback); // Accepts a connection to a remote endpoint. This method must be called // before Payloads can be exchanged with the remote endpoint. @@ -159,9 +162,10 @@ DLL_API void __stdcall RequestConnection(Core* pCore, const char* endpoint_id, // 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* pCore, const char* endpoint_id, - PayloadListener listener, - ResultCallback callback); +DLL_EXPORT void __stdcall AcceptConnection(Core* pCore, + const char* endpoint_id, + PayloadListener listener, + ResultCallback callback); // Rejects a connection to a remote endpoint. // @@ -173,7 +177,7 @@ DLL_API void __stdcall AcceptConnection(Core* pCore, const char* endpoint_id, // 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* pCore, const char* endpoint_id, +DLL_EXPORT void __stdcall RejectConnection(Core* pCore, const char* endpoint_id, ResultCallback callback); // Sends a Payload to a remote endpoint. Payloads can only be sent to remote @@ -195,7 +199,7 @@ DLL_API void __stdcall RejectConnection(Core* pCore, const char* endpoint_id, // still occur during transmission (and at different times for // different endpoints), and will be delivered via // PayloadCallback#onPayloadTransferUpdate. -DLL_API void __stdcall SendPayload(Core* pCore, +DLL_EXPORT void __stdcall SendPayload(Core* pCore, absl::Span endpoint_ids, Payload payload, ResultCallback callback); @@ -205,7 +209,7 @@ DLL_API void __stdcall SendPayload(Core* pCore, // 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* pCore, int64_t payload_id, +DLL_EXPORT void __stdcall CancelPayload(Core* pCore, int64_t payload_id, ResultCallback callback); // Disconnects from a remote endpoint. {@link Payload}s can no longer be sent @@ -215,7 +219,7 @@ DLL_API void __stdcall CancelPayload(Core* pCore, int64_t payload_id, // 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* pCore, char* endpoint_id, +DLL_EXPORT void __stdcall DisconnectFromEndpoint(Core* pCore, char* endpoint_id, ResultCallback callback); // Disconnects from, and removes all traces of, all connected and/or @@ -227,7 +231,8 @@ DLL_API void __stdcall DisconnectFromEndpoint(Core* pCore, char* endpoint_id, // 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* pCore, ResultCallback callback); +DLL_EXPORT void __stdcall StopAllEndpoints(Core* pCore, + ResultCallback callback); // Sends a request to initiate connection bandwidth upgrade. // @@ -238,19 +243,20 @@ DLL_API void __stdcall StopAllEndpoints(Core* pCore, ResultCallback callback); // 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* pCore, char* endpoint_id, - ResultCallback callback); +DLL_EXPORT void __stdcall InitiateBandwidthUpgrade(Core* pCore, + char* endpoint_id, + ResultCallback callback); // Gets the local endpoint generated by Nearby Connections. // DLL_API std::string __stdcall GetLocalEndpointId(Core* pCore); -DLL_API const char* __stdcall GetLocalEndpointId(Core* pCore); +DLL_EXPORT const char* __stdcall GetLocalEndpointId(Core* pCore); // Initializes a default ServiceControllerRouter instance. // Returns the instance handle to c# client. -DLL_API ServiceControllerRouter* __stdcall InitServiceControllerRouter(); +DLL_EXPORT ServiceControllerRouter* __stdcall InitServiceControllerRouter(); // Close a ServiceControllerRouter instance. -DLL_API void __stdcall CloseServiceControllerRouter( +DLL_EXPORT void __stdcall CloseServiceControllerRouter( ServiceControllerRouter* pRouter); } // namespace connections diff --git a/windows/dart/core_adapter_dart.cc b/windows/dart/core_adapter_dart.cc new file mode 100644 index 00000000..b76bb446 --- /dev/null +++ b/windows/dart/core_adapter_dart.cc @@ -0,0 +1,245 @@ +// Copyright 2021 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 "third_party/dart_lang/v2/runtime/include/dart_api_dl.h" +#include "third_party/nearby_connections/windows/dart/core_adapter_dart.h" + +namespace location { +namespace nearby { +namespace connections { + +ConnectionOptions g_discovery_connection_options; +ConnectionOptions g_advertising_connection_options; +ABSL_CONST_INIT absl::Mutex callback_mutex(absl::kConstInit); +std::queue callback_queue; + +Strategy GetStrategy(StrategyDart strategy) { + switch (strategy) { + case StrategyDart::P2P_CLUSTER: + return Strategy::kP2pCluster; + case StrategyDart::P2P_POINT_TO_POINT: + return Strategy::kP2pPointToPoint; + case StrategyDart::P2P_STAR: + return Strategy::kP2pStar; + } + return Strategy::kNone; +} + +ByteArray ConvertBluetoothMacAddress(absl::string_view address) { + return ByteArray(); +} + +void StartAdvertisingDart(Core* pCore, + const char* service_id, + StrategyDart strategy, + ByteArray endpoint_info, + int auto_upgrade_bandwidth, + int enforce_topology_constraints, + int enable_bluetooth, + int enable_ble, + int advertise_nearby_notifications_beacon, + int use_low_power_mode, + int discover_fast_advertisements, + int enable_wifi_lan, + int enable_nfc, + int enable_wifi_aware, + int enable_web_rtc, + Dart_Port initiated_cb, + Dart_Port accepted_cb, + Dart_Port rejected_cb, + Dart_Port disconnected_cb, + Dart_Port bandwidth_changed_cb, + Dart_Port result_cb) +{ + if (pCore) { + ConnectionOptions options; + options.strategy = GetStrategy(strategy); + options.auto_upgrade_bandwidth = + auto_upgrade_bandwidth; + options.enforce_topology_constraints = + enforce_topology_constraints; + options.allowed.bluetooth = enable_bluetooth; + options.allowed.ble = enable_ble; + // options.nearby_notificatios_beacon ?? + options.low_power = use_low_power_mode; + options.fast_advertisement_service_uuid = + discover_fast_advertisements ? "0000FE2C-0000-1000-8000-00805F9B34FB" : ""; + options.allowed.wifi_lan = enable_wifi_lan; + // options.allowed.nfc > no nfc + // options.allowed.wifi_aware = enable_wifi_aware; + options.allowed.web_rtc = enable_web_rtc; + + ConnectionRequestInfo info; + info.endpoint_info = endpoint_info; + + ResultCallback callback; + callback.result_cb = [result_cb](Status status) { + NEARBY_LOG(INFO, "Result callback called. %d.", status.value); + 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(result_cb, + &dart_object_result_callback); + if (!result) { + NEARBY_LOG(INFO, "Posting message to port failed."); + } + }; + + StartAdvertising(pCore, service_id, options, info, callback); + } +} + +void StopAdvertisingDart(Core* pCore, Dart_Port result_cb) { + if (pCore) { + ResultCallback callback; + callback.result_cb = [result_cb](Status status) { + NEARBY_LOG(INFO, "Result callback called. %d.", status.value); + 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(result_cb, + &dart_object_result_callback); + if (!result) { + NEARBY_LOG(INFO, "Posting message to port failed."); + } + }; + StopAdvertising(pCore, callback); + } +} + +void StartDiscoveryDart(Core* pCore, + const char* service_id, + StrategyDart strategy, + int forward_unrecognized_bluetooth_devices, + int enable_bluetooth, + int enable_ble, + int use_low_power_mode, + int discover_fast_advertisements, + int enable_wifi_lan, + int enable_nfc, + int enable_wifi_aware, + Dart_Port found_cb, + Dart_Port lost_cb, + Dart_Port distance_changed_cb, + Dart_Port result_cb) { + if (pCore) { + ConnectionOptions options; + options.strategy = GetStrategy(strategy); + options.allowed.bluetooth = enable_bluetooth; + options.allowed.ble = enable_ble; + options.allowed.wifi_lan = enable_wifi_lan; + options.allowed.web_rtc = false; + options.low_power = use_low_power_mode; + options.enable_bluetooth_listening = + enable_bluetooth; + options.enforce_topology_constraints = true; + options.fast_advertisement_service_uuid = + discover_fast_advertisements ? "0000FE2C-0000-1000-8000-00805F9B34FB" : ""; + + DiscoveryListener listener; + listener.endpoint_found_cb = + [found_cb](const std::string& endpoint_id, + const ByteArray& endpoint_info, + const std::string& str_service_id) { + NEARBY_LOG(INFO, "Device discovered: id=%s", + endpoint_id.c_str()); + NEARBY_LOG(INFO, "Device discovered: service_id=%s", + str_service_id.c_str()); + NEARBY_LOG(INFO, "Device discovered: info=%s", + ((string)endpoint_info).c_str()); + Dart_CObject dart_object_found; + dart_object_found.type = Dart_CObject_kString; + dart_object_found.value.as_string = + (char *)endpoint_info.data(); + const bool result = + Dart_PostCObject_DL(found_cb, + &dart_object_found); + if (!result) { + NEARBY_LOG(INFO, + "Posting message to port failed."); + } + }; + listener.endpoint_lost_cb = + [lost_cb](const std::string& endpoint_id) { + NEARBY_LOG(INFO, "Device lost: id=%s", + endpoint_id.c_str()); + Dart_CObject dart_object_lost; + dart_object_lost.type = Dart_CObject_kString; + dart_object_lost.value.as_string = + (char *)endpoint_id.c_str(); + const bool result = + Dart_PostCObject_DL(lost_cb, &dart_object_lost); + if (!result) { + NEARBY_LOG(INFO, + "Posting message to port failed."); + } + }; + listener.endpoint_distance_changed_cb = + [distance_changed_cb](const std::string& endpoint_id, + DistanceInfo info) { + NEARBY_LOG(INFO, "Device distance changed: id=%s", + endpoint_id.c_str()); + Dart_CObject dart_object_distance_changed; + dart_object_distance_changed.type = + Dart_CObject_kString; + dart_object_distance_changed.value.as_string = + (char *)(endpoint_id.c_str()); + const bool result = + Dart_PostCObject_DL(distance_changed_cb, + &dart_object_distance_changed); + if (!result) { + NEARBY_LOG(INFO, + "Posting message to port failed."); + } + }; + + ResultCallback callback; + callback.result_cb = [result_cb](Status status) { + NEARBY_LOG(INFO, "Result callback called. %d.", status.value); + 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(result_cb, + &dart_object_result_callback); + if (!result) { + NEARBY_LOG(INFO, "Posting message to port failed."); + } + }; + + StartDiscovery(pCore, service_id, options, + listener, callback); + } +} + +void StopDiscoveryDart(Core* pCore, Dart_Port result_cb) { + if (pCore) { + ResultCallback callback; + callback.result_cb = [result_cb](Status status) { + NEARBY_LOG(INFO, "Result callback called. %d.", status.value); + 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(result_cb, + &dart_object_result_callback); + if (!result) { + NEARBY_LOG(INFO, "Posting message to port failed."); + } + }; + StopDiscovery(pCore, callback); + } +} + +} // namespace connections +} // namespace nearby +} // namespace location diff --git a/windows/dart/core_adapter_dart.h b/windows/dart/core_adapter_dart.h new file mode 100644 index 00000000..f47a80fd --- /dev/null +++ b/windows/dart/core_adapter_dart.h @@ -0,0 +1,123 @@ +// Copyright 2021 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_WINDOWS_DART_CORE_ADAPTER_DART_H_ +#define LOCATION_NEARBY_CONNECTIONS_WINDOWS_DART_CORE_ADAPTER_DART_H_ + +#include "third_party/nearby_connections/windows/core_adapter.h" + +namespace location { +namespace nearby { +namespace connections { + +enum StrategyDart { + P2P_CLUSTER = 0, + P2P_STAR, + P2P_POINT_TO_POINT, +}; + +// 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. +// endpoint_info - A human readable name for this endpoint, to appear on +// other devices. +// initiated_cb, accepted_cb, rejected_cb, disconnected_cb, +// bandwidth_changed_cb - A callback 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_EXPORT void __stdcall StartAdvertisingDart(Core* pCore, + const char* service_id, + StrategyDart strategy, + ByteArray endpoint_info, + int auto_upgrade_bandwidth, + int enforce_topology_constraints, + int enable_bluetooth, + int enable_ble, + int advertise_nearby_notifications_beacon, + int use_low_power_mode, + int discover_fast_advertisements, + int enable_wifi_lan, + int enable_nfc, + int enable_wifi_aware, + int enable_web_rtc, + Dart_Port initiated_cb, + Dart_Port accepted_cb, + Dart_Port rejected_cb, + Dart_Port disconnected_cb, + Dart_Port bandwidth_changed_cb, + 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_EXPORT 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. +// found_cb, lost_cb, distance_changed_cb - A callback notified when a remote +// endpoint is discovered. +// result_cb - to access the status of the operation when available. +// Possible status codes include: +// Status::STATUS_OK if discovery started successfully. +// Status::STATUS_ALREADY_DISCOVERING if the app is already +// discovering the specified service. +// Status::STATUS_OUT_OF_ORDER_API_CALL if the app is currently +// connected to remote endpoints; call StopAllEndpoints first. +DLL_EXPORT void __stdcall StartDiscoveryDart(Core* pCore, + const char* service_id, + StrategyDart strategy, + int forward_unrecognized_bluetooth_devices, + int enable_bluetooth, + int enable_ble, + int use_low_power_mode, + int discover_fast_advertisements, + int enable_wifi_lan, + int enable_nfc, + int enable_wifi_aware, + Dart_Port found_cb, + Dart_Port lost_cb, + Dart_Port distance_changed_cb, + 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_EXPORT void __stdcall StopDiscoveryDart(Core* pCore, + Dart_Port result_cb); +} // namespace connections +} // namespace nearby +} // namespace location + +#endif // LOCATION_NEARBY_CONNECTIONS_WINDOWS_CORE_ADAPTER_DART_H_