Create wrapper function for set_wakeup_callback

Bug: 70669809
Test:  Compiles

Change-Id: I55f8b9995c2d872504b586addb07a18206da7fbe
This commit is contained in:
Steve Paik 2017-12-15 13:26:28 -08:00
parent fea16e1dea
commit 2d44190539
4 changed files with 27 additions and 22 deletions

View File

@ -28,8 +28,7 @@ static struct autosuspend_ops *autosuspend_ops;
static bool autosuspend_enabled;
static bool autosuspend_inited;
static int autosuspend_init(void)
{
static int autosuspend_init(void) {
if (autosuspend_inited) {
return 0;
}
@ -51,8 +50,7 @@ out:
return 0;
}
int autosuspend_enable(void)
{
int autosuspend_enable(void) {
int ret;
ret = autosuspend_init();
@ -75,8 +73,7 @@ int autosuspend_enable(void)
return 0;
}
int autosuspend_disable(void)
{
int autosuspend_disable(void) {
int ret;
ret = autosuspend_init();
@ -98,3 +95,16 @@ int autosuspend_disable(void)
autosuspend_enabled = false;
return 0;
}
void autosuspend_set_wakeup_callback(void (*func)(bool success)) {
int ret;
ret = autosuspend_init();
if (ret) {
return;
}
ALOGV("set_wakeup_callback");
autosuspend_ops->set_wakeup_callback(func);
}

View File

@ -20,10 +20,9 @@
struct autosuspend_ops {
int (*enable)(void);
int (*disable)(void);
void (*set_wakeup_callback)(void (*func)(bool success));
};
struct autosuspend_ops *autosuspend_autosleep_init(void);
struct autosuspend_ops *autosuspend_earlysuspend_init(void);
struct autosuspend_ops *autosuspend_wakeup_count_init(void);
#endif

View File

@ -42,7 +42,7 @@ static int state_fd;
static int wakeup_count_fd;
static pthread_t suspend_thread;
static sem_t suspend_lockout;
static const char *sleep_state = "mem";
static const char* sleep_state = "mem";
static void (*wakeup_func)(bool success) = NULL;
static int sleep_time = BASE_SLEEP_TIME;
@ -55,8 +55,7 @@ static void update_sleep_time(bool success) {
sleep_time = MIN(sleep_time * 2, 60000000);
}
static void *suspend_thread_func(void *arg __attribute__((unused)))
{
static void* suspend_thread_func(void* arg __attribute__((unused))) {
char buf[80];
char wakeup_count[20];
int wakeup_count_len;
@ -117,8 +116,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
return NULL;
}
static int autosuspend_wakeup_count_enable(void)
{
static int autosuspend_wakeup_count_enable(void) {
char buf[80];
int ret;
@ -136,8 +134,7 @@ static int autosuspend_wakeup_count_enable(void)
return ret;
}
static int autosuspend_wakeup_count_disable(void)
{
static int autosuspend_wakeup_count_disable(void) {
char buf[80];
int ret;
@ -155,8 +152,7 @@ static int autosuspend_wakeup_count_disable(void)
return ret;
}
void set_wakeup_callback(void (*func)(bool success))
{
static void autosuspend_set_wakeup_callback(void (*func)(bool success)) {
if (wakeup_func != NULL) {
ALOGE("Duplicate wakeup callback applied, keeping original");
return;
@ -165,12 +161,12 @@ void set_wakeup_callback(void (*func)(bool success))
}
struct autosuspend_ops autosuspend_wakeup_count_ops = {
.enable = autosuspend_wakeup_count_enable,
.disable = autosuspend_wakeup_count_disable,
.enable = autosuspend_wakeup_count_enable,
.disable = autosuspend_wakeup_count_disable,
.set_wakeup_callback = autosuspend_set_wakeup_callback,
};
struct autosuspend_ops *autosuspend_wakeup_count_init(void)
{
struct autosuspend_ops* autosuspend_wakeup_count_init(void) {
int ret;
char buf[80];

View File

@ -51,7 +51,7 @@ int autosuspend_disable(void);
* success is true if the suspend was sucessful and false if the suspend
* aborted due to some reason.
*/
void set_wakeup_callback(void (*func)(bool success));
void autosuspend_set_wakeup_callback(void (*func)(bool success));
__END_DECLS