~chunsang/+junk/powerd

« back to all changes in this revision

Viewing changes to libsuspend/libsuspend.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 <errno.h>
 
21
#include "libsuspend.h"
 
22
#include "common.h"
 
23
 
 
24
const struct suspend_handler *handler;
 
25
 
 
26
void libsuspend_init(int force_mock)
 
27
{
 
28
    if (!force_mock) {
 
29
        handler = autosleep_detect();
 
30
        if (handler)
 
31
            return;
 
32
 
 
33
        handler = earlysuspend_detect();
 
34
        if (handler)
 
35
            return;
 
36
 
 
37
        handler = legacy_detect();
 
38
        if (handler)
 
39
            return;
 
40
 
 
41
        printf("No suspend interface detected, using mock suspend\n");
 
42
    }
 
43
 
 
44
    handler = mocksuspend_detect();
 
45
}
 
46
 
 
47
int libsuspend_prepare_suspend(void)
 
48
{
 
49
    if (!handler)
 
50
        return -ENODEV;
 
51
 
 
52
    if (handler->prepare)
 
53
        return handler->prepare();
 
54
 
 
55
    return 0;
 
56
}
 
57
 
 
58
int libsuspend_enter_suspend(void)
 
59
{
 
60
    if (!handler)
 
61
        return -ENODEV;
 
62
 
 
63
    if (handler->enter)
 
64
        return handler->enter();
 
65
 
 
66
    return 0;
 
67
}
 
68
 
 
69
int libsuspend_exit_suspend(void)
 
70
{
 
71
    if (!handler)
 
72
        return -ENODEV;
 
73
 
 
74
    if (handler->exit)
 
75
        return handler->exit();
 
76
 
 
77
    return 0;
 
78
}