aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/wakelock.c
blob: 59468092fb252af80f02e3e237f1aaec2b9ecf2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * This file is part of libsamsung-ipc.
 *
 * Copyright (C) 2012 Alexander Tarasikov <alexander.tarasikov@gmail.com>
 *
 * libsamsung-ipc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * libsamsung-ipc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <assert.h>
#include <fcntl.h>
#include <wakelock.h>
#include <stdlib.h>
#include <string.h>

static int wake_lock_fd = -1;
static int wake_unlock_fd = -1;

int wake_lock(char *lock_name)
{
    int rc;
    assert(lock_name != NULL);

    if (wake_lock_fd < 0)
        wake_lock_fd = open("/sys/power/wake_lock", O_RDWR);

    if (wake_lock_fd < 0)
        return wake_lock_fd;

    rc = write(wake_lock_fd, lock_name, strlen(lock_name));

    return rc;
}

int wake_unlock(char *lock_name)
{
    int rc;
    assert(lock_name != NULL);

    if (wake_unlock_fd < 0)
        wake_unlock_fd = open("/sys/power/wake_unlock", O_RDWR);

    if (wake_unlock_fd < 0)
        return wake_lock_fd;

    rc = write(wake_unlock_fd, lock_name, strlen(lock_name));

    return rc;
}