blob: 98724b2f773fb2ebede24767956adad3f0bb5c84 [file] [log] [blame]
Darren Hsu391f6012022-04-27 01:10:12 +08001/*
2 * Copyright (C) 2022 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#pragma once
17
18#include "AocStateResidencyDataProvider.h"
19
20#include <condition_variable>
21#include <mutex>
22#include <thread>
23#include <PowerStatsAidl.h>
24
25namespace aidl {
26namespace android {
27namespace hardware {
28namespace power {
29namespace stats {
30
31enum AsyncStatus {
32 COMPLETED,
33 RUN,
34 RUNNING
35};
36
37class AocTimedStateResidencyDataProvider : public AocStateResidencyDataProvider {
38 public:
39 AocTimedStateResidencyDataProvider(
40 std::vector<std::pair<std::string, std::string>> ids,
41 std::vector<std::pair<std::string, std::string>> states,
42 const uint64_t timeoutMillis);
43 ~AocTimedStateResidencyDataProvider() = default;
44
45 bool getStateResidencies(
46 std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override;
47
48 private:
49 void getStateResidenciesAsync();
50
51 uint64_t mTimeoutMillis;
52 std::thread mAsyncThread;
53 std::mutex mStatusMutex;
54 std::condition_variable mRunCond;
55 std::condition_variable mCompletedCond;
56 std::unordered_map<std::string, std::vector<StateResidency>> mStateResidencies;
57 AsyncStatus mAsyncStatus;
58};
59
60} // namespace stats
61} // namespace power
62} // namespace hardware
63} // namespace android
64} // namespace aidl