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/kml_locations_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 #include "host/libs/location/KmlParser.h"
23 #include "string.h"
24
25 #include <chrono>
26 #include <iostream>
27 #include <sstream>
28 #include <thread>
29 #include <vector>
30
31 namespace cuttlefish {
32 namespace webrtc_streaming {
33
KmlLocationsHandler(std::function<void (const uint8_t *,size_t)> send_to_client)34 KmlLocationsHandler::KmlLocationsHandler(
35 std::function<void(const uint8_t *, size_t)> send_to_client) {}
36
~KmlLocationsHandler()37 KmlLocationsHandler::~KmlLocationsHandler() {}
38
HandleMessage(const uint8_t * msg,size_t len)39 void KmlLocationsHandler::HandleMessage(const uint8_t *msg, size_t len) {
40 LOG(DEBUG) << "ENTER KmlLocationsHandler handleMessage , size: " << len;
41 std::string error;
42 GpsFixArray coordinates;
43 if (!KmlParser::parseString((const char *)&msg[0], len, &coordinates,
44 &error)) {
45 LOG(ERROR) << " Parsing Error: " << error << std::endl;
46 return;
47 }
48
49 LOG(DEBUG) << "Number of parsed points: " << coordinates.size() << std::endl;
50 auto config = CuttlefishConfig::Get();
51 if (!config) {
52 LOG(ERROR) << "Failed to obtain config object";
53 return;
54 }
55 auto instance = config->ForDefaultInstance();
56 auto server_port = instance.gnss_grpc_proxy_server_port();
57 std::string socket_name =
58 std::string("localhost:") + std::to_string(server_port);
59 LOG(DEBUG) << "Server port: " << server_port << " socket: " << socket_name
60 << std::endl;
61
62
63 GnssClient gpsclient(
64 grpc::CreateChannel(socket_name, grpc::InsecureChannelCredentials()));
65
66
67 auto reply = gpsclient.SendGpsLocations(1000,coordinates);
68 }
69
70 } // namespace webrtc_streaming
71 } // namespace cuttlefish
72