Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
| 19 | #include <android/hardware/gnss/2.1/IGnssMeasurement.h> |
| 20 | #include <hidl/MQDescriptor.h> |
| 21 | #include <hidl/Status.h> |
| 22 | #include <atomic> |
| 23 | #include <mutex> |
| 24 | #include <thread> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace gnss { |
| 29 | namespace V2_1 { |
| 30 | namespace implementation { |
| 31 | |
| 32 | using GnssDataV2_1 = V2_1::IGnssMeasurementCallback::GnssData; |
Sasha Kuznetsov | 7fd5cc3 | 2019-12-09 17:11:08 -0800 | [diff] [blame] | 33 | using GnssDataV2_0 = V2_0::IGnssMeasurementCallback::GnssData; |
Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 34 | |
| 35 | using ::android::sp; |
| 36 | using ::android::hardware::hidl_array; |
| 37 | using ::android::hardware::hidl_memory; |
| 38 | using ::android::hardware::hidl_string; |
| 39 | using ::android::hardware::hidl_vec; |
| 40 | using ::android::hardware::Return; |
| 41 | using ::android::hardware::Void; |
| 42 | |
| 43 | struct GnssMeasurement : public IGnssMeasurement { |
| 44 | GnssMeasurement(); |
| 45 | ~GnssMeasurement(); |
| 46 | // Methods from V1_0::IGnssMeasurement follow. |
| 47 | Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback( |
| 48 | const sp<V1_0::IGnssMeasurementCallback>& callback) override; |
| 49 | Return<void> close() override; |
| 50 | |
| 51 | // Methods from V1_1::IGnssMeasurement follow. |
| 52 | Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_1_1( |
| 53 | const sp<V1_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override; |
| 54 | |
| 55 | // Methods from V2_0::IGnssMeasurement follow. |
| 56 | Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_0( |
| 57 | const sp<V2_0::IGnssMeasurementCallback>& callback, bool enableFullTracking) override; |
| 58 | |
| 59 | // Methods from V2_1::IGnssMeasurement follow. |
| 60 | Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_1( |
| 61 | const sp<V2_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override; |
| 62 | |
| 63 | private: |
| 64 | void start(); |
| 65 | void stop(); |
Sasha Kuznetsov | 7fd5cc3 | 2019-12-09 17:11:08 -0800 | [diff] [blame] | 66 | void reportMeasurement(const GnssDataV2_0&); |
Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 67 | void reportMeasurement(const GnssDataV2_1&); |
| 68 | |
Sasha Kuznetsov | 7fd5cc3 | 2019-12-09 17:11:08 -0800 | [diff] [blame] | 69 | static sp<V2_1::IGnssMeasurementCallback> sCallback_2_1; |
| 70 | static sp<V2_0::IGnssMeasurementCallback> sCallback_2_0; |
Yu-Han Yang | c06b536 | 2019-10-25 14:14:35 -0700 | [diff] [blame] | 71 | std::atomic<long> mMinIntervalMillis; |
| 72 | std::atomic<bool> mIsActive; |
| 73 | std::thread mThread; |
| 74 | mutable std::mutex mMutex; |
| 75 | }; |
| 76 | |
| 77 | } // namespace implementation |
| 78 | } // namespace V2_1 |
| 79 | } // namespace gnss |
| 80 | } // namespace hardware |
| 81 | } // namespace android |