3
* oFono - Open Source Telephony
5
* Copyright (C) 2015 Jolla Ltd. All rights reserved.
6
* Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
#ifndef __OFONO_WAKELOCK_H_
25
#define __OFONO_WAKELOCK_H_
27
#include <ofono/types.h>
31
* Wakelocks ensure system does not suspend/enter power save mode
32
* before an ongoing operation completes. This header declares a
33
* wakelock API that can be implemented by a OS-specific plugin.
36
struct wakelock; /* Opaque */
38
struct wakelock_table {
39
int (*create)(const char *name, struct wakelock **);
40
int (*free)(struct wakelock *);
41
int (*acquire)(struct wakelock *);
42
int (*release)(struct wakelock *);
43
ofono_bool_t (*is_locked)(struct wakelock *);
47
/*** Functions for wakelock users ***/
50
* This will create a wakelock which will be held for a short duration
51
* and then automatically freed. If this is called multiple times the
52
* timeout will be restarted on every call.
54
void wakelock_system_lock(void);
57
* Create a wakelock. Multiple wakelocks can be created; if any one of
58
* them is activated, system will be prevented from going to suspend.
59
* This makes it possible to overlap locks to hand over from subsystem
60
* to subsystem, each with their own wakelock-guarded sections,
61
* without falling to suspend in between.
63
int wakelock_create(const char *name, struct wakelock **wakelock);
66
* Free a wakelock, releasing all acquisitions at the same time
67
* and deallocating the lock.
69
int wakelock_free(struct wakelock *wakelock);
72
* Acquire a wakelock. Multiple acquisitions are possible, meaning
73
* that the wakelock needs to be released the same number of times
74
* until it is actually deactivated.
76
int wakelock_acquire(struct wakelock *wakelock);
79
* Release a wakelock, deactivating it if all acquisitions are
80
* released, letting system suspend.
82
int wakelock_release(struct wakelock *wakelock);
85
* Check if a wakelock is currently locked or not.
87
ofono_bool_t wakelock_is_locked(struct wakelock *wakelock);
89
/*** Functions for wakelock implementors ***/
92
* Register a wakelock implementation. Only one implementation may be
93
* registered at a time. In the absence of an implementation, all
94
* wakelock functions are no-ops.
96
int wakelock_plugin_register(const char *name, struct wakelock_table *fns);
98
int wakelock_plugin_unregister(void);