• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #ifndef ANDROID_HARDWARE_GNSS_V2_0_GNSSMEASUREMENT_H
18 #define ANDROID_HARDWARE_GNSS_V2_0_GNSSMEASUREMENT_H
19 
20 #include <android/hardware/gnss/2.0/IGnssMeasurement.h>
21 #include <hidl/MQDescriptor.h>
22 #include <hidl/Status.h>
23 #include <atomic>
24 #include <mutex>
25 #include <thread>
26 
27 namespace android {
28 namespace hardware {
29 namespace gnss {
30 namespace V2_0 {
31 namespace implementation {
32 
33 using ::android::sp;
34 using ::android::hardware::hidl_array;
35 using ::android::hardware::hidl_memory;
36 using ::android::hardware::hidl_string;
37 using ::android::hardware::hidl_vec;
38 using ::android::hardware::Return;
39 using ::android::hardware::Void;
40 
41 using GnssData = V2_0::IGnssMeasurementCallback::GnssData;
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    private:
60     void start();
61     void stop();
62     void reportMeasurement(const GnssData&);
63 
64     // Guarded by mMutex
65     static sp<IGnssMeasurementCallback> sCallback;
66 
67     std::atomic<long> mMinIntervalMillis;
68     std::atomic<bool> mIsActive;
69     std::thread mThread;
70 
71     // Synchronization lock for sCallback
72     mutable std::mutex mMutex;
73 };
74 
75 }  // namespace implementation
76 }  // namespace V2_0
77 }  // namespace gnss
78 }  // namespace hardware
79 }  // namespace android
80 
81 #endif  // ANDROID_HARDWARE_GNSS_V2_0_GNSSMEASUREMENT_H
82