1 /* 2 * Copyright (C) 2020 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 <log/log.h> 18 #include "data_sink.h" 19 20 namespace goldfish { 21 gnssLocation(const ahg20::GnssLocation & loc) const22void DataSink::gnssLocation(const ahg20::GnssLocation& loc) const { 23 std::unique_lock<std::mutex> lock(mtx); 24 if (cb20 && isWarmedUd()) { 25 cb20->gnssLocationCb_2_0(loc); 26 } 27 } 28 gnssSvStatus(const hidl_vec<ahg20::IGnssCallback::GnssSvInfo> & svInfoList20) const29void DataSink::gnssSvStatus(const hidl_vec<ahg20::IGnssCallback::GnssSvInfo>& svInfoList20) const { 30 std::unique_lock<std::mutex> lock(mtx); 31 if (cb20) { 32 cb20->gnssSvStatusCb_2_0(svInfoList20); 33 } 34 } 35 gnssStatus(const ahg10::IGnssCallback::GnssStatusValue status) const36void DataSink::gnssStatus(const ahg10::IGnssCallback::GnssStatusValue status) const { 37 std::unique_lock<std::mutex> lock(mtx); 38 if (cb20) { 39 cb20->gnssStatusCb(status); 40 } 41 } 42 gnssNmea(const ahg10::GnssUtcTime t,const hidl_string & nmea) const43void DataSink::gnssNmea(const ahg10::GnssUtcTime t, 44 const hidl_string& nmea) const { 45 std::unique_lock<std::mutex> lock(mtx); 46 if (cb20 && isWarmedUd()) { 47 cb20->gnssNmeaCb(t, nmea); 48 } 49 } 50 setCallback20(sp<ahg20::IGnssCallback> cb)51void DataSink::setCallback20(sp<ahg20::IGnssCallback> cb) { 52 std::unique_lock<std::mutex> lock(mtx); 53 cb20 = std::move(cb); 54 } 55 cleanup()56void DataSink::cleanup() { 57 std::unique_lock<std::mutex> lock(mtx); 58 cb20 = nullptr; 59 } 60 start()61void DataSink::start() { 62 std::unique_lock<std::mutex> lock(mtx); 63 warmedUpTime = std::chrono::steady_clock::now() + std::chrono::seconds(5); 64 } 65 isWarmedUd() const66bool DataSink::isWarmedUd() const { 67 return std::chrono::steady_clock::now() >= warmedUpTime; 68 } 69 70 } // namespace goldfish 71