Commit 646dd5dd authored by Slava Monich's avatar Slava Monich

[connman] Cleaned up wakeup timers

Renamed jolla_wakeup_timer into sailfish_wakeup_timer.
Renamed connman_wakeup functions for consistency with their glib counterparts.
Added connman_wakeup_timer_add() and connman_wakeup_timer_add_seconds().
parent dcacafe0
*~
*.o
*.a
*.lo
......@@ -60,6 +61,9 @@ tools/session-test
tools/netlink-test
unit/test-ippool
unit/test-nat
unit/test-nat
unit/test-dnsproxy
unit/test-sailfish_wakeup_timer
doc/*.bak
doc/*.stamp
......
......@@ -267,23 +267,23 @@ client_connmanctl_LDADD = gdbus/libgdbus-internal.la @DBUS_LIBS@ @GLIB_LIBS@ \
endif
noinst_PROGRAMS += unit/test-ippool \
unit/test-jolla-wakeup-timer unit/test-dnsproxy
unit/test-sailfish_wakeup_timer unit/test-dnsproxy
unit_test_ippool_SOURCES = src/log.c src/dbus.c src/error.c \
src/ippool.c unit/test-ippool.c
unit_test_ippool_LDADD = gdbus/libgdbus-internal.la \
@GLIB_LIBS@ @DBUS_LIBS@ -ldl
unit_test_jolla_wakeup_timer_SOURCES = unit/test-jolla-wakeup-timer.c \
unit_test_sailfish_wakeup_timer_SOURCES = unit/test-sailfish_wakeup_timer.c \
src/log.c src/wakeup_timer.c \
plugins/jolla_wakeup_timer.c
unit_test_jolla_wakeup_timer_LDADD = @GLIB_LIBS@ -lrt -ldl
plugins/sailfish_wakeup_timer.c
unit_test_sailfish_wakeup_timer_LDADD = @GLIB_LIBS@ -lrt -ldl
unit_test_dnsproxy_SOURCES = unit/test-dnsproxy.c src/log.c
unit_test_dnsproxy_LDADD = @GLIB_LIBS@ -lresolv -ldl
TESTS = unit/test-ippool \
unit/test-jolla-wakeup-timer unit/test-dnsproxy
unit/test-sailfish_wakeup_timer unit/test-dnsproxy
if WISPR
noinst_PROGRAMS += tools/wispr
......
......@@ -50,9 +50,9 @@ builtin_modules += jolla_gps
builtin_sources += plugins/jolla-gps.c
endif
if JOLLA_WAKEUP_TIMER
builtin_modules += jolla_wakeup_timer
builtin_sources += plugins/jolla_wakeup_timer.c
if SAILFISH_WAKEUP_TIMER
builtin_modules += sailfish_wakeup_timer
builtin_sources += plugins/sailfish_wakeup_timer.c
endif
if OFONO
......
......@@ -66,12 +66,13 @@ AC_ARG_ENABLE(jolla-gps,
[enable_jolla_gps=${enableval}], [enable_jolla_gps="no"])
AM_CONDITIONAL(JOLLA_GPS, test "${enable_jolla_gps}" != "no")
AC_ARG_ENABLE(jolla_wakeup_timer, AC_HELP_STRING([--enable-jolla-wakeup-timer],
[enable Jolla wakeup timer support]),
[enable_jolla_wakeup_timer=${enableval}])
AM_CONDITIONAL(JOLLA_WAKEUP_TIMER, test "${enable_jolla_wakeup_timer}" != "no")
AC_ARG_ENABLE(sailfish_wakeup_timer,
AC_HELP_STRING([--enable-sailfish-wakeup-timer],
[enable Sailfish wakeup timer support]),
[enable_sailfish_wakeup_timer=${enableval}])
AM_CONDITIONAL(SAILFISH_WAKEUP_TIMER, test "${enable_sailfish_wakeup_timer}" != "no")
if (test "${enable_jolla_wakeup_timer}" != "no"); then
if (test "${enable_sailfish_wakeup_timer}" != "no"); then
PKG_CHECK_MODULES(IPHB, libiphb, dummy=yes,
AC_MSG_ERROR(IPHB library is required))
else
......
......@@ -580,7 +580,7 @@ static gboolean send_probe_packet(gpointer dhcp_data)
} else
timeout = (ANNOUNCE_WAIT * 1000);
dhcp_client->timeout = connman_wakeup_timer(G_PRIORITY_HIGH,
dhcp_client->timeout = connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
timeout,
ipv4ll_probe_timeout,
dhcp_client,
......@@ -608,7 +608,7 @@ static gboolean send_announce_packet(gpointer dhcp_data)
if (dhcp_client->state == IPV4LL_DEFEND) {
dhcp_client->timeout =
connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
DEFEND_INTERVAL,
ipv4ll_defend_timeout,
dhcp_client,
......@@ -616,7 +616,7 @@ static gboolean send_announce_packet(gpointer dhcp_data)
return TRUE;
} else
dhcp_client->timeout =
connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
ANNOUNCE_INTERVAL,
ipv4ll_announce_timeout,
dhcp_client,
......@@ -1395,7 +1395,7 @@ static void ipv4ll_start(GDHCPClient *dhcp_client)
timeout = ipv4ll_random_delay_ms(PROBE_WAIT);
dhcp_client->retry_times++;
dhcp_client->timeout = connman_wakeup_timer(G_PRIORITY_HIGH,
dhcp_client->timeout = connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
timeout,
send_probe_packet,
dhcp_client,
......@@ -1478,7 +1478,7 @@ static int ipv4ll_recv_arp_packet(GDHCPClient *dhcp_client)
/*restart whole state machine*/
dhcp_client->retry_times++;
dhcp_client->timeout =
connman_wakeup_timer(G_PRIORITY_HIGH,
connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
ipv4ll_random_delay_ms(PROBE_WAIT),
send_probe_packet,
dhcp_client,
......@@ -1627,7 +1627,8 @@ static void start_request(GDHCPClient *dhcp_client)
send_request(dhcp_client);
dhcp_client->timeout = connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
dhcp_client->timeout =
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
REQUEST_TIMEOUT,
request_timeout,
dhcp_client,
......@@ -1700,7 +1701,7 @@ static gboolean continue_rebound(gpointer user_data)
if (dhcp_client->T2 > 60) {
dhcp_get_random(&rand);
dhcp_client->t2_timeout =
connman_wakeup_timer(G_PRIORITY_HIGH,
connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
dhcp_client->T2 * 1000 + (rand % 2000) - 1000,
continue_rebound,
dhcp_client,
......@@ -1747,7 +1748,8 @@ static gboolean continue_renew (gpointer user_data)
if (dhcp_client->T1 > 60) {
dhcp_get_random(&rand);
dhcp_client->t1_timeout = connman_wakeup_timer(G_PRIORITY_HIGH,
dhcp_client->t1_timeout =
connman_wakeup_timer_add_full(G_PRIORITY_HIGH,
dhcp_client->T1 * 1000 + (rand % 2000) - 1000,
continue_renew,
dhcp_client,
......@@ -1789,17 +1791,20 @@ static void start_bound(GDHCPClient *dhcp_client)
dhcp_client->T2 = dhcp_client->lease_seconds * 0.875;
dhcp_client->expire = dhcp_client->lease_seconds;
dhcp_client->t1_timeout = connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
dhcp_client->t1_timeout =
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
dhcp_client->T1,
start_renew, dhcp_client,
NULL);
dhcp_client->t2_timeout = connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
dhcp_client->t2_timeout =
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
dhcp_client->T2,
start_rebound, dhcp_client,
NULL);
dhcp_client->lease_timeout= connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
dhcp_client->lease_timeout =
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
dhcp_client->expire,
start_expire, dhcp_client,
NULL);
......@@ -2445,7 +2450,8 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition,
remove_timeouts(dhcp_client);
dhcp_client->timeout = connman_wakeup_timer_seconds(
dhcp_client->timeout =
connman_wakeup_timer_add_seconds_full(
G_PRIORITY_HIGH, 3,
restart_dhcp_timeout,
dhcp_client,
......@@ -2868,8 +2874,8 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client, const char *last_address)
dhcp_client->state = REBOOTING;
send_request(dhcp_client);
dhcp_client->timeout = connman_wakeup_timer_seconds(
G_PRIORITY_HIGH,
dhcp_client->timeout =
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
REQUEST_TIMEOUT,
reboot_timeout,
dhcp_client,
......@@ -2878,7 +2884,8 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client, const char *last_address)
}
send_discover(dhcp_client, addr);
dhcp_client->timeout = connman_wakeup_timer_seconds(G_PRIORITY_HIGH,
dhcp_client->timeout =
connman_wakeup_timer_add_seconds_full(G_PRIORITY_HIGH,
DISCOVER_TIMEOUT,
discover_timeout,
dhcp_client,
......
/*
*
* Connection Manager
*
* Copyright (C) 2014 Jolla Ltd. All rights reserved.
* Copyright (C) 2014-2016 Jolla Ltd. All rights reserved.
* Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -13,11 +12,6 @@
* 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
......@@ -25,9 +19,7 @@
#include <glib.h>
#ifdef __cplusplus
extern "C" {
#endif
G_BEGIN_DECLS
struct connman_wakeup_timer {
const char *name;
......@@ -43,23 +35,26 @@ struct connman_wakeup_timer {
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_register(const struct connman_wakeup_timer *timer);
void connman_wakeup_timer_unregister(const struct connman_wakeup_timer *timer);
int connman_wakeup_timer(gint priority,
guint interval,
guint connman_wakeup_timer_add(guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
int connman_wakeup_timer_seconds(gint priority,
gpointer data);
guint connman_wakeup_timer_add_full(gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
guint connman_wakeup_timer_add_seconds(guint interval,
GSourceFunc function,
gpointer data);
guint connman_wakeup_timer_add_seconds_full(gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
#ifdef __cplusplus
}
#endif
G_END_DECLS
#endif /* __CONNMAN_WAKEUP_TIMER_H */
/*
*
* Connection Manager
*
* Copyright (C) 2014 Jolla Ltd. All rights reserved.
* Copyright (C) 2014-2016 Jolla Ltd. All rights reserved.
* Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -13,11 +12,6 @@
* 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
*
*/
/*
......@@ -522,11 +516,13 @@ static guint wakeup_timeout_add_seconds(gint priority,
TRUE);
}
static struct connman_wakeup_timer timer = {
"Jolla wakeup timer", wakeup_timeout_add, wakeup_timeout_add_seconds
static const struct connman_wakeup_timer sailfish_wakeup_timer = {
"Jolla wakeup timer",
wakeup_timeout_add,
wakeup_timeout_add_seconds
};
static int jolla_wakeup_timer_init(void)
static int sailfish_wakeup_timer_init(void)
{
struct timespec now;
int r;
......@@ -549,7 +545,7 @@ static int jolla_wakeup_timer_init(void)
if (r < 0)
goto error;
r = connman_wakeup_timer_register(&timer);
r = connman_wakeup_timer_register(&sailfish_wakeup_timer);
if (r < 0)
goto error;
......@@ -562,11 +558,11 @@ error:
return r;
}
static void jolla_wakeup_timer_exit(void)
static void sailfish_wakeup_timer_exit(void)
{
DBG("");
connman_wakeup_timer_unregister(&timer);
connman_wakeup_timer_unregister(&sailfish_wakeup_timer);
if (context.timeouts) {
g_list_free(context.timeouts);
......@@ -578,6 +574,6 @@ static void jolla_wakeup_timer_exit(void)
context.initialized = FALSE;
}
CONNMAN_PLUGIN_DEFINE(jolla_wakeup_timer, "Jolla wakeup timer", VERSION,
CONNMAN_PLUGIN_DEFINE(sailfish_wakeup_timer, "Sailfish wakeup timer", VERSION,
CONNMAN_PLUGIN_PRIORITY_DEFAULT,
jolla_wakeup_timer_init, jolla_wakeup_timer_exit)
sailfish_wakeup_timer_init, sailfish_wakeup_timer_exit)
......@@ -260,11 +260,9 @@ static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
DBG("No lease available ipv4ll %d client %p", ipv4ll_running,
dhcp->ipv4ll_client);
dhcp->timeout = connman_wakeup_timer_seconds(G_PRIORITY_DEFAULT,
RATE_LIMIT_INTERVAL,
dhcp->timeout = connman_wakeup_timer_add_seconds(RATE_LIMIT_INTERVAL,
dhcp_retry_cb,
dhcp,
NULL);
dhcp);
if (ipv4ll_running)
return;
......
This diff is collapsed.
/*
*
* Connection Manager
*
* Copyright (C) 2014 Jolla Ltd. All rights reserved.
......@@ -13,20 +12,15 @@
* 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;
static const struct connman_wakeup_timer *timer = NULL;
int connman_wakeup_timer_register(struct connman_wakeup_timer *t)
int connman_wakeup_timer_register(const struct connman_wakeup_timer *t)
{
if (!t)
return -EINVAL;
......@@ -39,17 +33,25 @@ int connman_wakeup_timer_register(struct connman_wakeup_timer *t)
return 0;
}
void connman_wakeup_timer_unregister(struct connman_wakeup_timer *t)
void connman_wakeup_timer_unregister(const 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,
guint connman_wakeup_timer_add(guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify)
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)
{
if (!timer)
return g_timeout_add_full(priority, interval, function,
......@@ -59,7 +61,15 @@ int connman_wakeup_timer(gint priority,
notify);
}
int connman_wakeup_timer_seconds(gint priority,
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,
guint interval,
GSourceFunc function,
gpointer data,
......
/*
*
* Connection Manager
*
* Copyright (C) 2014 Jolla Ltd. All rights reserved.
* Copyright (C) 2014-2016 Jolla Ltd. All rights reserved.
* Contact: Hannu Mallat <hannu.mallat@jollamobile.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -13,11 +12,6 @@
* 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
*
*/
#ifdef HAVE_CONFIG_H
......@@ -40,7 +34,7 @@
static GMainLoop *main_loop = NULL;
extern struct connman_plugin_desc __connman_builtin_jolla_wakeup_timer;
extern struct connman_plugin_desc __connman_builtin_sailfish_wakeup_timer;
extern int __connman_log_init(const char *program, const char *debug,
gboolean detach, gboolean backtrace,
......@@ -104,7 +98,7 @@ static gboolean create_timeout_within_callback_cb(gpointer user_data)
for (i = 0; i < CHUNK && timeouts_scheduled < MAX_COUNT; i++) {
timeouts_scheduled++;
g_assert(connman_wakeup_timer
g_assert(connman_wakeup_timer_add_full
(G_PRIORITY_DEFAULT,
g_test_rand_int_range(0, MAX_DELAY),
create_timeout_within_callback_cb,
......@@ -127,7 +121,7 @@ static gboolean create_timeout_within_callback_seed(gpointer user_data)
for (i = 0; i < CHUNK && timeouts_scheduled < MAX_COUNT; i++) {
timeouts_scheduled++;
g_assert(connman_wakeup_timer
g_assert(connman_wakeup_timer_add_full
(G_PRIORITY_DEFAULT,
g_test_rand_int_range(0, MAX_DELAY),
create_timeout_within_callback_cb,
......@@ -144,16 +138,16 @@ static void create_timeout_within_callback(void)
timeouts_handled = 0;
main_loop = g_main_loop_new(NULL, FALSE);
__connman_log_init("test-jolla-wakeup-timer",
__connman_log_init("test-sailfish-wakeup-timer",
g_test_verbose() ? "*" : NULL,
FALSE, FALSE,
"test-jolla-wakeup-timer", "1");
g_assert((__connman_builtin_jolla_wakeup_timer.init)() == 0);
"test-sailfish-wakeup-timer", "1");
g_assert((__connman_builtin_sailfish_wakeup_timer.init)() == 0);
g_timeout_add(0, create_timeout_within_callback_seed, NULL);
g_main_loop_run(main_loop);
(__connman_builtin_jolla_wakeup_timer.exit)();
(__connman_builtin_sailfish_wakeup_timer.exit)();
g_main_loop_unref(main_loop);
}
......
......@@ -110,7 +110,7 @@ Documentation for connman.
--enable-loopback=builtin \
--enable-pacrunner=builtin \
--enable-jolla-gps=builtin \
--enable-jolla-wakeup-timer=builtin \
--enable-sailfish-wakeup-timer=builtin \
--enable-client \
--enable-test \
--enable-debuglog \
......
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