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