blob: 8611ae61c402ab970bd83dff2db28df5945fd5b7 [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,
Darren Hsud4cab2b2022-06-17 20:10:29 +080042 const uint64_t timeoutMillis,
43 const uint64_t aocClock);
Darren Hsu391f6012022-04-27 01:10:12 +080044 ~AocTimedStateResidencyDataProvider() = default;
45
46 bool getStateResidencies(
47 std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override;
48
49 private:
50 void getStateResidenciesAsync();
51
52 uint64_t mTimeoutMillis;
53 std::thread mAsyncThread;
54 std::mutex mStatusMutex;
55 std::condition_variable mRunCond;
56 std::condition_variable mCompletedCond;
57 std::unordered_map<std::string, std::vector<StateResidency>> mStateResidencies;
58 AsyncStatus mAsyncStatus;
59};
60
61} // namespace stats
62} // namespace power
63} // namespace hardware
64} // namespace android
65} // namespace aidl