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 #pragma once 18 #include <atomic> 19 #include <mutex> 20 #include <thread> 21 #include <android/hardware/gnss/2.0/IGnssMeasurement.h> 22 23 namespace goldfish { 24 namespace ahg = ::android::hardware::gnss; 25 namespace ahg20 = ahg::V2_0; 26 namespace ahg11 = ahg::V1_1; 27 namespace ahg10 = ahg::V1_0; 28 using GnssMeasurementStatus10 = ahg10::IGnssMeasurement::GnssMeasurementStatus; 29 using GnssData20 = ahg20::IGnssMeasurementCallback::GnssData; 30 31 using ::android::sp; 32 using ::android::hardware::Return; 33 34 struct GnssMeasurement20 : public ahg20::IGnssMeasurement { 35 GnssMeasurement20(); 36 ~GnssMeasurement20(); 37 38 // Methods from V2_0::IGnssMeasurement follow. 39 Return<GnssMeasurementStatus10> setCallback_2_0(const sp<ahg20::IGnssMeasurementCallback>& callback, bool enableFullTracking) override; 40 41 // Methods from V1_1::IGnssMeasurement follow. 42 Return<GnssMeasurementStatus10> setCallback_1_1(const sp<ahg11::IGnssMeasurementCallback>& callback, bool enableFullTracking) override; 43 44 // Methods from V1_0::IGnssMeasurement follow. 45 Return<GnssMeasurementStatus10> setCallback(const sp<ahg10::IGnssMeasurementCallback>& callback) override; 46 Return<void> close() override; 47 48 private: 49 void startLocked(); 50 void stopLocked(); 51 void update(); 52 53 sp<ahg20::IGnssMeasurementCallback> m_callback; 54 std::thread m_thread; 55 std::atomic<bool> m_isRunning; 56 int m_gnssDataIndex = 0; 57 mutable std::mutex m_mtx; 58 59 std::vector<GnssData20> m_gnssData; 60 }; 61 62 } // namespace goldfish 63