Commit 0b6cb423 authored by Hannu Mallat's avatar Hannu Mallat

[connman] plugins: Create an interface for wakeup timers

Mobile phones and other battery-powered systems may suspend often and
for long periods of time. However, connman may need to perform
scheduled operations such as DHCP renewal at specific times regardless
of whether the system is suspended or not.

Provide a plugin interface for implementing wakeup timers which can be
used to request the system to wake up from suspend at a given
time. These timers are intended for relatively infrequent events which
do not need high timing precision, not as general purpose replacement
for g_timeout functions, as wakeup from suspend can be a slow and
expensive operation.

If no wakeup timer is implemented, regular glib timeouts are used.

Note that only one wakeup timer plugin may be registered at a time.
parent 439808ed
......@@ -11,7 +11,7 @@ include_HEADERS = include/log.h include/plugin.h \
include/device.h include/network.h include/inet.h \
include/storage.h include/provision.h \
include/session.h include/ipaddress.h include/agent.h \
include/inotify.h include/peer.h
include/inotify.h include/peer.h include/wakeup_timer.h
nodist_include_HEADERS = include/version.h
......@@ -105,7 +105,8 @@ src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) \
src/session.c src/tethering.c src/wpad.c src/wispr.c \
src/stats.c src/iptables.c src/dnsproxy.c src/6to4.c \
src/ippool.c src/bridge.c src/nat.c src/ipaddress.c \
src/inotify.c src/firewall.c src/ipv6pd.c src/peer.c
src/inotify.c src/firewall.c src/ipv6pd.c src/peer.c \
src/wakeup_timer.c
src_connmand_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
@GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ @GNUTLS_LIBS@ \
......
/*
*
* Connection Manager
*
* Copyright (C) 2014 Jolla Ltd. All rights reserved.
* Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __CONNMAN_WAKEUP_TIMER_H
#define __CONNMAN_WAKEUP_TIMER_H
#include <glib.h>
#ifdef __cplusplus
extern "C" {
#endif
struct connman_wakeup_timer {
const char *name;
guint (*timeout_add) (gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
guint (*timeout_add_seconds) (gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
};
int connman_wakeup_timer_register(struct connman_wakeup_timer *wakeup_timer);
void connman_wakeup_timer_unregister(struct connman_wakeup_timer *t);
int connman_wakeup_timer(gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
int connman_wakeup_timer_seconds(gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
#ifdef __cplusplus
}
#endif
#endif /* __CONNMAN_WAKEUP_TIMER_H */
/*
*
* Connection Manager
*
* Copyright (C) 2014 Jolla Ltd. All rights reserved.
* Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <errno.h>
#include "wakeup_timer.h"
static struct connman_wakeup_timer *timer = NULL;
int connman_wakeup_timer_register(struct connman_wakeup_timer *t)
{
if (!t)
return -EINVAL;
if (timer)
return -EALREADY;
timer = t;
return 0;
}
void connman_wakeup_timer_unregister(struct connman_wakeup_timer *t)
{
if (timer && t && g_strcmp0(timer->name, t->name) == 0)
timer = NULL;
}
int connman_wakeup_timer(gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify)
{
if (!timer)
return g_timeout_add_full(priority, interval, function,
data, notify);
else
return (timer->timeout_add)(priority, interval, function, data,
notify);
}
int connman_wakeup_timer_seconds(gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify)
{
if (!timer)
return g_timeout_add_seconds_full(priority, interval, function,
data, notify);
else
return (timer->timeout_add_seconds)(priority, interval,
function, data, notify);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment