blob: ee329039d9858bb6aa4b10c8f0bbda0a36567bb7 [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;
33
34using ::android::sp;
35using ::android::hardware::hidl_array;
36using ::android::hardware::hidl_memory;
37using ::android::hardware::hidl_string;
38using ::android::hardware::hidl_vec;
39using ::android::hardware::Return;
40using ::android::hardware::Void;
41
42struct GnssMeasurement : public IGnssMeasurement {
43 GnssMeasurement();
44 ~GnssMeasurement();
45 // Methods from V1_0::IGnssMeasurement follow.
46 Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback(
47 const sp<V1_0::IGnssMeasurementCallback>& callback) override;
48 Return<void> close() override;
49
50 // Methods from V1_1::IGnssMeasurement follow.
51 Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_1_1(
52 const sp<V1_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
53
54 // Methods from V2_0::IGnssMeasurement follow.
55 Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_0(
56 const sp<V2_0::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
57
58 // Methods from V2_1::IGnssMeasurement follow.
59 Return<V1_0::IGnssMeasurement::GnssMeasurementStatus> setCallback_2_1(
60 const sp<V2_1::IGnssMeasurementCallback>& callback, bool enableFullTracking) override;
61
62 private:
63 void start();
64 void stop();
65 void reportMeasurement(const GnssDataV2_1&);
66
67 static sp<IGnssMeasurementCallback> sCallback;
68 std::atomic<long> mMinIntervalMillis;
69 std::atomic<bool> mIsActive;
70 std::thread mThread;
71 mutable std::mutex mMutex;
72};
73
74} // namespace implementation
75} // namespace V2_1
76} // namespace gnss
77} // namespace hardware
78} // namespace android