Files
nearby/windows/core_adapter.cc
T
hais a192cd3e32 Patch recent cls from nearby_connections;
Sync github to replace nearby_connections with nearby.

PiperOrigin-RevId: 411609608
2021-11-22 11:38:39 -08:00

153 lines
4.3 KiB
C++

// Copyright 2020 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/nearby/windows/core_adapter.h"
#include "absl/strings/str_format.h"
#include "core/core.h"
namespace location {
namespace nearby {
namespace connections {
namespace windows {
Core *InitCore(ServiceControllerRouter *router) { return new Core(router); }
void CloseCore(Core *pCore) {
if (pCore) {
pCore->StopAllEndpoints(
{.result_cb = std::function<void(Status)>{[](Status) {}}});
delete pCore;
}
}
void StartAdvertising(Core *pCore, const char *service_id,
AdvertisingOptions options, ConnectionRequestInfo info,
ResultCallback callback) {
if (pCore) {
pCore->StartAdvertising(service_id, options, info, callback);
}
}
void StopAdvertising(Core *pCore, ResultCallback callback) {
if (pCore) {
pCore->StopAdvertising(callback);
}
}
void StartDiscovery(Core *pCore, const char *service_id,
DiscoveryOptions options, DiscoveryListener listener,
ResultCallback callback) {
if (pCore) {
pCore->StartDiscovery(service_id, options, listener, callback);
}
}
void StopDiscovery(Core *pCore, ResultCallback callback) {
if (pCore) {
pCore->StopDiscovery(callback);
}
}
void InjectEndpoint(Core *pCore, char *service_id,
OutOfBandConnectionMetadata metadata,
ResultCallback callback) {
if (pCore) {
pCore->InjectEndpoint(service_id, metadata, callback);
}
}
void RequestConnection(Core *pCore, const char *endpoint_id,
ConnectionRequestInfo info, ConnectionOptions options,
ResultCallback callback) {
if (pCore) {
pCore->RequestConnection(endpoint_id, info, options, callback);
}
}
void AcceptConnection(Core *pCore, const char *endpoint_id,
PayloadListener listener, ResultCallback callback) {
if (pCore) {
pCore->AcceptConnection(endpoint_id, listener, callback);
}
}
void RejectConnection(Core *pCore, const char *endpoint_id,
ResultCallback callback) {
if (pCore) {
pCore->RejectConnection(endpoint_id, callback);
}
}
void SendPayload(Core *pCore,
// todo(jfcarroll) this is being exported, needs to be
// refactored to return a plain old c type
absl::Span<const std::string> endpoint_ids, Payload payload,
ResultCallback callback) {
if (pCore) {
pCore->SendPayload(endpoint_ids, std::move(payload), callback);
}
}
void CancelPayload(Core *pCore, std::int64_t payload_id,
ResultCallback callback) {
if (pCore) {
pCore->CancelPayload(payload_id, callback);
}
}
void DisconnectFromEndpoint(Core *pCore, char *endpoint_id,
ResultCallback callback) {
if (pCore) {
pCore->DisconnectFromEndpoint(endpoint_id, callback);
}
}
void StopAllEndpoints(Core *pCore, ResultCallback callback) {
if (pCore) {
pCore->StopAllEndpoints(callback);
}
}
void InitiateBandwidthUpgrade(Core *pCore, char *endpoint_id,
ResultCallback callback) {
if (pCore) {
pCore->InitiateBandwidthUpgrade(endpoint_id, callback);
}
}
const char *GetLocalEndpointId(Core *pCore) {
if (pCore) {
std::string endpoint_id = pCore->GetLocalEndpointId();
char *result = new char[endpoint_id.length() + 1];
absl::SNPrintF(result, endpoint_id.length() + 1, "%s", endpoint_id);
return result;
}
return "Null-Core";
}
ServiceControllerRouter *InitServiceControllerRouter() {
return new ServiceControllerRouter();
}
void CloseServiceControllerRouter(ServiceControllerRouter *pRouter) {
if (pRouter) {
delete pRouter;
}
}
} // namespace windows
} // namespace connections
} // namespace nearby
} // namespace location