5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <connman/service.h>
27 #include <connman/ondemand.h>
28 #include <connman/notifier.h>
29 #include <connman/log.h>
33 static volatile gint started;
34 static gboolean connected;
35 struct connman_service *ondemand_service;
37 static void ondemand_default_changed(struct connman_service *service)
39 DBG("service %p", service);
41 if (service == NULL) {
49 static struct connman_notifier ondemand_notifier = {
51 .default_changed = ondemand_default_changed,
54 gboolean connman_ondemand_connected(void)
56 DBG("connected %d", connected);
62 int connman_ondemand_start(const char *bearer, unsigned int idle_timeout)
66 if (g_atomic_int_get(&started) > 0)
69 g_atomic_int_inc(&started);
71 ondemand_service = __connman_session_request(bearer, "__ondemand__");
72 if (ondemand_service == NULL)
73 g_atomic_int_set(&started, 0);
76 * 1) Set IDLETIMER target.
77 * 2) Listen for the sysfs/netlink event.
78 * 3) Stop the session.
84 int __connman_ondemand_init(void)
86 return connman_notifier_register(&ondemand_notifier);
89 void __connman_ondemand_cleanup(void)
91 connman_notifier_unregister(&ondemand_notifier);