blob: 3ed7bc597de64430efe9cf18292d56e064b6d575 [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
Sasha Kuznetsov7fd5cc32019-12-09 17:11:08 -080069 static sp<V2_1::IGnssMeasurementCallback> sCallback_2_1;
70 static sp<V2_0::IGnssMeasurementCallback> sCallback_2_0;
Yu-Han Yangc06b5362019-10-25 14:14:35 -070071 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