~chunsang/+junk/powerd

« back to all changes in this revision

Viewing changes to libsuspend/earlysuspend.c

  • Committer: Tarmac
  • Author(s): Seth Forshee, mfrey at canonical, Matthew Fischer
  • Date: 2013-05-21 15:38:46 UTC
  • mfrom: (9.1.28 powerd)
  • Revision ID: tarmac-20130521153846-10di0d3835ufiu4v
Massive influx of changes including:
1) control file cleanup and new deps
2) support for listening for power requests on dbus
3) tie in to seth's low level libsuspend code
4) a simple C based test client for the power requests.

Approved by Michael Frey, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This file is part of powerd.
 
5
 *
 
6
 * powerd is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * powerd is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include <stdio.h>
 
20
#include "common.h"
 
21
#include "sysfs.h"
 
22
 
 
23
static const char state_path[] = "/sys/power/state";
 
24
static const char wakelock_path[] = "/sys/power/wake_lock";
 
25
static const char autosleep_path[] = "/sys/power/autosleep";
 
26
 
 
27
static const char mem_str[] = "mem";
 
28
static const char on_str[] = "on";
 
29
 
 
30
static int earlysuspend_enter(void)
 
31
{
 
32
    int ret = sysfs_write(state_path, mem_str, ARRAY_SIZE(mem_str) - 1);
 
33
    return ret < 0 ? ret : 0;
 
34
}
 
35
 
 
36
static int earlysuspend_exit(void)
 
37
{
 
38
    int ret = sysfs_write(state_path, on_str, ARRAY_SIZE(on_str) - 1);
 
39
    return ret < 0 ? ret : 0;
 
40
}
 
41
 
 
42
static const struct suspend_handler earlysuspend_handler = {
 
43
    .enter = earlysuspend_enter,
 
44
    .exit = earlysuspend_exit,
 
45
};
 
46
 
 
47
const struct suspend_handler *earlysuspend_detect(void)
 
48
{
 
49
    if (!sysfs_file_exists(autosleep_path) &&
 
50
        sysfs_file_exists(wakelock_path) &&
 
51
        sysfs_file_exists(state_path))
 
52
        return &earlysuspend_handler;
 
53
 
 
54
    return NULL;
 
55
}