1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "GnssClient.h" 18 #include <android-base/logging.h> 19 #include <host/libs/config/logging.h> 20 #include <cassert> 21 #include <string> 22 23 using gnss_grpc_proxy::GnssGrpcProxy; 24 using gnss_grpc_proxy::GpsCoordinates; 25 using gnss_grpc_proxy::SendGpsCoordinatesReply; 26 using gnss_grpc_proxy::SendGpsCoordinatesRequest; 27 using grpc::ClientContext; 28 29 namespace cuttlefish { 30 GnssClient(const std::shared_ptr<grpc::Channel> & channel)31GnssClient::GnssClient(const std::shared_ptr<grpc::Channel>& channel) 32 : stub_(GnssGrpcProxy::NewStub(channel)) {} 33 SendGpsLocations(int delay,const GpsFixArray & coordinates)34Result<grpc::Status> GnssClient::SendGpsLocations( 35 int delay, const GpsFixArray& coordinates) { 36 // Data we are sending to the server. 37 SendGpsCoordinatesRequest request; 38 request.set_delay(delay); 39 for (const auto& loc : coordinates) { 40 GpsCoordinates* curr = request.add_coordinates(); 41 curr->set_longitude(loc.longitude); 42 curr->set_latitude(loc.latitude); 43 curr->set_elevation(loc.elevation); 44 } 45 46 // Container for the data we expect from the server. 47 SendGpsCoordinatesReply reply; 48 // Context for the client. It could be used to convey extra information to 49 // the server and/or tweak certain RPC behaviors. 50 ClientContext context; 51 // The actual RPC. 52 grpc::Status status = stub_->SendGpsVector(&context, request, &reply); 53 // Act upon its status. 54 CF_EXPECT(status.ok(), "GPS data sending failed" << status.error_code() 55 << ": " 56 << status.error_message()); 57 58 LOG(DEBUG) << reply.status(); 59 60 return status; 61 } 62 63 } // namespace cuttlefish 64