wakeup_timer.c 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *  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.
 */

#include <errno.h>

#include "wakeup_timer.h"

21
static const struct connman_wakeup_timer *timer = NULL;
22

23
int connman_wakeup_timer_register(const struct connman_wakeup_timer *t)
24 25 26 27 28 29 30 31 32 33 34 35
{
	if (!t)
		return -EINVAL;

	if (timer)
		return -EALREADY;

	timer = t;

	return 0;
}

36
void connman_wakeup_timer_unregister(const struct connman_wakeup_timer *t)
37 38 39 40 41
{
	if (timer && t && g_strcmp0(timer->name, t->name) == 0)
		timer = NULL;
}

42
guint connman_wakeup_timer_add(guint interval,
43
				GSourceFunc function,
44 45 46 47 48 49 50 51 52 53 54
				gpointer data)
{
	return connman_wakeup_timer_add_full(G_PRIORITY_DEFAULT,
					interval, function, data, NULL);
}

guint connman_wakeup_timer_add_full(gint priority,
					guint interval,
					GSourceFunc function,
					gpointer data,
					GDestroyNotify notify)
55 56 57 58 59 60 61 62 63
{
	if (!timer)
		return g_timeout_add_full(priority, interval, function,
						data, notify);
	else
		return (timer->timeout_add)(priority, interval, function, data,
						notify);
}

64 65 66 67 68 69 70 71 72
guint connman_wakeup_timer_add_seconds(guint interval,
					GSourceFunc function,
					gpointer data)
{
	return connman_wakeup_timer_add_seconds_full(G_PRIORITY_DEFAULT,
					interval, function, data, NULL);
}

guint connman_wakeup_timer_add_seconds_full(gint priority,
73 74 75 76 77 78 79 80 81 82 83 84
					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);
}