1 /* 2 * Copyright (C) 2020 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 #include <condition_variable> 19 #include <deque> 20 #include <mutex> 21 #include <thread> 22 #include <aidl/android/hardware/gnss/BnGnssBatching.h> 23 24 namespace aidl { 25 namespace android { 26 namespace hardware { 27 namespace gnss { 28 namespace implementation { 29 30 struct GnssBatching : public BnGnssBatching { 31 ~GnssBatching(); 32 33 ndk::ScopedAStatus init(const std::shared_ptr<IGnssBatchingCallback>& callback) override; 34 ndk::ScopedAStatus getBatchSize(int* size) override; 35 ndk::ScopedAStatus start(const Options& options) override; 36 ndk::ScopedAStatus flush() override; 37 ndk::ScopedAStatus stop() override; 38 ndk::ScopedAStatus cleanup() override; 39 40 void onGnssLocationCb(GnssLocation location); 41 42 private: 43 void stopImpl(); 44 void batchLocationLocked(GnssLocation location, bool wakeUpOnFifoFull); 45 bool flushLocked(); 46 47 std::shared_ptr<IGnssBatchingCallback> mCallback; 48 std::deque<GnssLocation> mBatchedLocations; 49 std::optional<GnssLocation> mLocation; 50 std::condition_variable mThreadNotification; 51 bool mRunning = false; 52 std::thread mThread; 53 mutable std::mutex mMtx; 54 }; 55 56 } // namespace implementation 57 } // namespace gnss 58 } // namespace hardware 59 } // namespace android 60 } // namespace aidl 61