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 
30 using ::android::sp;
31 using ::android::hardware::Return;
32 
33 struct GnssMeasurement20 : public ahg20::IGnssMeasurement {
34     ~GnssMeasurement20();
35 
36     // Methods from V2_0::IGnssMeasurement follow.
37     Return<GnssMeasurementStatus10> setCallback_2_0(const sp<ahg20::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
38 
39     // Methods from V1_1::IGnssMeasurement follow.
40     Return<GnssMeasurementStatus10> setCallback_1_1(const sp<ahg11::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
41 
42     // Methods from V1_0::IGnssMeasurement follow.
43     Return<GnssMeasurementStatus10> setCallback(const sp<ahg10::IGnssMeasurementCallback>& callback) override;
44     Return<void> close() override;
45 
46 private:
47     void startLocked();
48     void stopLocked();
49     void update();
50 
51     sp<ahg20::IGnssMeasurementCallback> m_callback;
52     std::thread                         m_thread;
53     std::atomic<bool>                   m_isRunning;
54     mutable std::mutex                  m_mtx;
55 };
56 
57 }  // namespace goldfish
58