1 /* 2 * Copyright (c) 2014 Google, Inc. All Rights Reserved. 3 * 4 */ 5 #ifndef POWER_HAL_TIME_QOS_MANAGER_H 6 #define POWER_HAL_TIME_QOS_MANAGER_H 7 8 #include <stdint.h> 9 #include <sys/types.h> 10 11 #include <utils/threads.h> 12 #include <utils/String8.h> 13 #include <utils/Errors.h> 14 #include <utils/Log.h> 15 16 using namespace android; 17 18 extern void sysfs_write(const char *path, const char *s); 19 20 class QosObject { 21 public: 22 virtual ~QosObject() {} 23 24 virtual void enter() = 0; 25 virtual void exit() = 0; 26 }; 27 28 class SysfsQosObject : public QosObject { 29 public: 30 SysfsQosObject(const char* nodeName, const char* enterCmd, const char* exitCmd) 31 : mNodeName(nodeName), mEnterCmd(enterCmd), mExitCmd(exitCmd) {} 32 33 virtual void enter(); 34 virtual void exit(); 35 36 private: 37 const char *mNodeName; 38 const char *mEnterCmd; 39 const char *mExitCmd; 40 41 }; 42 43 class TimedQosManager : public Thread { 44 public: 45 TimedQosManager(const char *name, QosObject *qosObj, bool oneShot) : 46 Thread(false), mName(name), mQosObject(qosObj), mOneShot(oneShot), mLock("lock") {} 47 48 virtual ~TimedQosManager() { delete mQosObject; } 49 50 virtual bool threadLoop(); 51 52 void requestTimedQos(nsecs_t timeout); 53 54 private: 55 const char *mName; 56 QosObject *mQosObject; 57 bool mOneShot; 58 59 Mutex mLock; 60 Condition mCondition; 61 62 nsecs_t mTargetTime; 63 }; 64 65 #endif 66