1 #ifndef ANDROID_HARDWARE_POWERSTATS_RAILDATAPROVIDER_H
2 #define ANDROID_HARDWARE_POWERSTATS_RAILDATAPROVIDER_H
3 
4 #include <fmq/MessageQueue.h>
5 #include <pixelpowerstats/PowerStats.h>
6 
7 namespace android {
8 namespace hardware {
9 namespace google {
10 namespace pixel {
11 namespace powerstats {
12 
13 typedef MessageQueue<EnergyData, kSynchronizedReadWrite> MessageQueueSync;
14 struct RailData {
15     std::string devicePath;
16     uint32_t index;
17     std::string subsysName;
18     uint32_t samplingRate;
19 };
20 
21 struct OnDeviceMmt {
22     std::mutex mLock;
23     bool hwEnabled;
24     std::vector<std::string> devicePaths;
25     std::map<std::string, RailData> railsInfo;
26     std::vector<EnergyData> reading;
27     std::unique_ptr<MessageQueueSync> fmqSynchronized;
28 };
29 
30 class RailDataProvider : public IRailDataProvider {
31 public:
32     RailDataProvider();
33     // Methods from ::android::hardware::power::stats::V1_0::IPowerStats follow.
34     Return<void> getRailInfo(IPowerStats::getRailInfo_cb _hidl_cb) override;
35     Return<void> getEnergyData(const hidl_vec<uint32_t>& railIndices,
36                         IPowerStats::getEnergyData_cb _hidl_cb) override;
37     Return<void> streamEnergyData(uint32_t timeMs, uint32_t samplingRate,
38                         IPowerStats::streamEnergyData_cb _hidl_cb) override;
39  private:
40      OnDeviceMmt mOdpm;
41      void findIioPowerMonitorNodes();
42      size_t parsePowerRails();
43      int parseIioEnergyNode(std::string devName);
44      Status parseIioEnergyNodes();
45 };
46 
47 }  // namespace powerstats
48 }  // namespace pixel
49 }  // namespace google
50 }  // namespace hardware
51 }  // namespace android
52 
53 #endif  // ANDROID_HARDWARE_POWERSTATS_RAILDATAPROVIDER_H
54