|
| 1 | +/** |
| 2 | + * Copyright (c) 2023 Boston Dynamics, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Downloading, reproducing, distributing or otherwise using the SDK Software |
| 5 | + * is subject to the terms and conditions of the Boston Dynamics Software |
| 6 | + * Development Kit License (20191101-BDSDK-SL). |
| 7 | + */ |
| 8 | + |
| 9 | + |
| 10 | +#include "network_compute_bridge_client.h" |
| 11 | + |
| 12 | +using namespace std::placeholders; |
| 13 | + |
| 14 | +namespace bosdyn { |
| 15 | + |
| 16 | +namespace client { |
| 17 | + |
| 18 | +const char* NetworkComputeBridgeClient::s_default_service_name = "network-compute-bridge"; |
| 19 | + |
| 20 | +const char* NetworkComputeBridgeClient::s_service_type = "bosdyn.api.NetworkComputeBridge"; |
| 21 | + |
| 22 | +std::shared_future<NetworkComputeResultType> NetworkComputeBridgeClient::NetworkComputeAsync( |
| 23 | + ::bosdyn::api::NetworkComputeRequest& request, const RPCParameters& parameters) { |
| 24 | + std::promise<NetworkComputeResultType> response; |
| 25 | + std::shared_future<NetworkComputeResultType> future = response.get_future(); |
| 26 | + BOSDYN_ASSERT_PRECONDITION(m_stub != nullptr, "Stub for service is unset!"); |
| 27 | + |
| 28 | + MessagePumpCallBase* one_time = InitiateAsyncCall<::bosdyn::api::NetworkComputeRequest, |
| 29 | + ::bosdyn::api::NetworkComputeResponse, |
| 30 | + ::bosdyn::api::NetworkComputeResponse>( |
| 31 | + request, |
| 32 | + std::bind(&::bosdyn::api::NetworkComputeBridge::StubInterface::AsyncNetworkCompute, |
| 33 | + m_stub.get(), _1, _2, _3), |
| 34 | + std::bind(&NetworkComputeBridgeClient::OnNetworkComputeComplete, this, _1, _2, _3, _4, _5), |
| 35 | + std::move(response), parameters); |
| 36 | + return future; |
| 37 | +} |
| 38 | + |
| 39 | +void NetworkComputeBridgeClient::OnNetworkComputeComplete( |
| 40 | + MessagePumpCallBase* call, const ::bosdyn::api::NetworkComputeRequest& request, |
| 41 | + ::bosdyn::api::NetworkComputeResponse&& response, const grpc::Status& status, |
| 42 | + std::promise<NetworkComputeResultType> promise) { |
| 43 | + std::cout << "On network compute complete\n"; |
| 44 | + ::bosdyn::common::Status ret_status = |
| 45 | + ProcessResponseAndGetFinalStatus<::bosdyn::api::NetworkComputeResponse>(status, response, |
| 46 | + response.status()); |
| 47 | + std::cout << "Ret status: " << ret_status.DebugString() << std::endl; |
| 48 | + promise.set_value({ret_status, std::move(response)}); |
| 49 | +} |
| 50 | + |
| 51 | +NetworkComputeResultType NetworkComputeBridgeClient::NetworkCompute( |
| 52 | + ::bosdyn::api::NetworkComputeRequest& request, const RPCParameters& parameters) { |
| 53 | + return NetworkComputeAsync(request, parameters).get(); |
| 54 | +} |
| 55 | + |
| 56 | +std::shared_future<ListAvailableModelsResultType> |
| 57 | +NetworkComputeBridgeClient::ListAvailableModelsAsync( |
| 58 | + ::bosdyn::api::ListAvailableModelsRequest& request, const RPCParameters& parameters) { |
| 59 | + std::promise<ListAvailableModelsResultType> response; |
| 60 | + std::shared_future<ListAvailableModelsResultType> future = response.get_future(); |
| 61 | + BOSDYN_ASSERT_PRECONDITION(m_stub != nullptr, "Stub for service is unset!"); |
| 62 | + |
| 63 | + MessagePumpCallBase* one_time = InitiateAsyncCall<::bosdyn::api::ListAvailableModelsRequest, |
| 64 | + ::bosdyn::api::ListAvailableModelsResponse, |
| 65 | + ::bosdyn::api::ListAvailableModelsResponse>( |
| 66 | + request, |
| 67 | + std::bind(&::bosdyn::api::NetworkComputeBridge::StubInterface::AsyncListAvailableModels, |
| 68 | + m_stub.get(), _1, _2, _3), |
| 69 | + std::bind(&NetworkComputeBridgeClient::OnListAvailableModelsComplete, this, _1, _2, _3, _4, |
| 70 | + _5), |
| 71 | + std::move(response), parameters); |
| 72 | + return future; |
| 73 | +}; |
| 74 | + |
| 75 | +void NetworkComputeBridgeClient::OnListAvailableModelsComplete( |
| 76 | + MessagePumpCallBase* call, const ::bosdyn::api::ListAvailableModelsRequest& request, |
| 77 | + ::bosdyn::api::ListAvailableModelsResponse&& response, const grpc::Status& status, |
| 78 | + std::promise<ListAvailableModelsResultType> promise) { |
| 79 | + std::cout << "On list available models complete\n"; |
| 80 | + ::bosdyn::common::Status ret_status = |
| 81 | + ProcessResponseAndGetFinalStatus<::bosdyn::api::ListAvailableModelsResponse>( |
| 82 | + status, response, response.status()); |
| 83 | + std::cout << "Ret status: " << ret_status.DebugString() << std::endl; |
| 84 | + promise.set_value({ret_status, std::move(response)}); |
| 85 | +} |
| 86 | + |
| 87 | +ListAvailableModelsResultType NetworkComputeBridgeClient::ListAvailableModels( |
| 88 | + ::bosdyn::api::ListAvailableModelsRequest& request, const RPCParameters& parameters) { |
| 89 | + return ListAvailableModelsAsync(request, parameters).get(); |
| 90 | +} |
| 91 | + |
| 92 | +ServiceClient::QualityOfService NetworkComputeBridgeClient::GetQualityOfService() const { |
| 93 | + return QualityOfService::NORMAL; |
| 94 | +} |
| 95 | + |
| 96 | +void NetworkComputeBridgeClient::SetComms(const std::shared_ptr<grpc::ChannelInterface>& channel) { |
| 97 | + m_stub.reset(new ::bosdyn::api::NetworkComputeBridge::Stub(channel)); |
| 98 | +} |
| 99 | + |
| 100 | +} // namespace client |
| 101 | + |
| 102 | +} // namespace bosdyn |
0 commit comments