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 "host/frontend/webrtc/location_handler.h"
18
19 #include <unistd.h>
20
21 #include <android-base/logging.h>
22 #include <fmt/format.h>
23
24 #include "host/libs/config/cuttlefish_config.h"
25 #include "host/libs/location/GnssClient.h"
26
27 namespace cuttlefish::webrtc_streaming {
28
LocationHandler(std::function<void (const uint8_t *,size_t)> send_to_client)29 LocationHandler::LocationHandler(
30 std::function<void(const uint8_t *, size_t)> send_to_client) {}
31
~LocationHandler()32 LocationHandler::~LocationHandler() {}
33
HandleMessage(const float longitude,const float latitude,const float elevation)34 void LocationHandler::HandleMessage(const float longitude,
35 const float latitude,
36 const float elevation) {
37 auto config = CuttlefishConfig::Get();
38 if (!config) {
39 LOG(ERROR) << "Failed to obtain config object";
40 return;
41 }
42 auto instance = config->ForDefaultInstance();
43 std::string socket_name =
44 fmt::format("unix:{}.sock",
45 instance.PerInstanceGrpcSocketPath("GnssGrpcProxyServer"));
46 GnssClient gpsclient(
47 grpc::CreateChannel(socket_name, grpc::InsecureChannelCredentials()));
48
49 GpsFix location;
50 location.longitude = longitude;
51 location.latitude = latitude;
52 location.elevation = elevation;
53
54 GpsFixArray coordinates;
55 coordinates.push_back(location);
56
57 Result<void> reply = gpsclient.SendGpsLocations(1000, coordinates);
58 if (!reply.ok()) {
59 LOG(ERROR) << reply.error().FormatForEnv();
60 }
61 }
62
63 } // namespace cuttlefish::webrtc_streaming
64