blob: d44641978f4f185f1b5d2d3077cd30bebb65ebb8 [file] [log] [blame]
Yu-Han Yangc06b5362019-10-25 14:14:35 -07001/*
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
26namespace android {
27namespace hardware {
28namespace gnss {
29namespace V2_1 {
30namespace implementation {
31
32using GnssDataV2_1 = V2_1::IGnssMeasurementCallback::GnssData;
Sasha Kuznetsov7fd5cc32019-12-09 17:11:08 -080033using GnssDataV2_0 = V2_0::IGnssMeasurementCallback::GnssData;
Yu-Han Yangc06b5362019-10-25 14:14:35 -070034
35using ::android::sp;
36using ::android::hardware::hidl_array;
37using ::android::hardware::hidl_memory;
38using ::android::hardware::hidl_string;
39using ::android::hardware::hidl_vec;
40using ::android::hardware::Return;
41using ::android::hardware::Void;
42
43struct 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 Kuznetsov7fd5cc32019-12-09 17:11:08 -080066 void reportMeasurement(const GnssDataV2_0&);
Yu-Han Yangc06b5362019-10-25 14:14:35 -070067 void reportMeasurement(const GnssDataV2_1&);
68
Yu-Han Yangf3cb5562020-03-05 22:41:23 -080069 // Guarded by mMutex
Sasha Kuznetsov7fd5cc32019-12-09 17:11:08 -080070 static sp<V2_1::IGnssMeasurementCallback> sCallback_2_1;
Yu-Han Yangf3cb5562020-03-05 22:41:23 -080071
72 // Guarded by mMutex
Sasha Kuznetsov7fd5cc32019-12-09 17:11:08 -080073 static sp<V2_0::IGnssMeasurementCallback> sCallback_2_0;
Yu-Han Yangf3cb5562020-03-05 22:41:23 -080074
Yu-Han Yangc06b5362019-10-25 14:14:35 -070075 std::atomic<long> mMinIntervalMillis;
76 std::atomic<bool> mIsActive;
77 std::thread mThread;
Yu-Han Yangf3cb5562020-03-05 22:41:23 -080078
79 // Synchronization lock for sCallback_2_1 and sCallback_2_0
Yu-Han Yangc06b5362019-10-25 14:14:35 -070080 mutable std::mutex mMutex;
81};
82
83} // namespace implementation
84} // namespace V2_1
85} // namespace gnss
86} // namespace hardware
87} // namespace android