From cd36491ca34d68b65f33be9289e314ca3a5f2ae6 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 11 Mar 2009 20:02:50 +0100 Subject: [PATCH] Add basic support for notifier infrastructure --- include/Makefile.am | 2 +- include/notifier.h | 55 +++++++++++++++++++++++++++++++++++ src/Makefile.am | 4 +-- src/connman.h | 5 ++++ src/element.c | 2 ++ src/notifier.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 include/notifier.h create mode 100644 src/notifier.c diff --git a/include/Makefile.am b/include/Makefile.am index f8e9e73..a13ef80 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -2,7 +2,7 @@ includedir = @includedir@/connman include_HEADERS = types.h log.h plugin.h security.h resolver.h \ - storage.h device.h network.h + storage.h device.h network.h notifier.h nodist_include_HEADERS = version.h diff --git a/include/notifier.h b/include/notifier.h new file mode 100644 index 0000000..fc9939c --- /dev/null +++ b/include/notifier.h @@ -0,0 +1,55 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. + * + * 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_NOTIFIER_H +#define __CONNMAN_NOTIFIER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * SECTION:notifier + * @title: Notifier premitives + * @short_description: Functions for registering notifier modules + */ + +#define CONNMAN_NOTIFIER_PRIORITY_LOW -100 +#define CONNMAN_NOTIFIER_PRIORITY_DEFAULT 0 +#define CONNMAN_NOTIFIER_PRIORITY_HIGH 100 + +struct connman_notifier { + const char *name; + int priority; + int (*device_powered) (struct connman_device *device, + connman_bool_t powered); +}; + +extern int connman_notifier_register(struct connman_notifier *notifier); +extern void connman_notifier_unregister(struct connman_notifier *notifier); + +#ifdef __cplusplus +} +#endif + +#endif /* __CONNMAN_NOTIFIER_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 79da404..897d573 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,8 +9,8 @@ sbin_PROGRAMS = connmand connmand_SOURCES = main.c connman.h log.c selftest.c error.c plugin.c \ profile.c element.c device.c network.c connection.c \ - security.c resolver.c storage.c manager.c agent.c \ - ipv4.c detect.c rtnl.c dbus.c + security.c resolver.c notifier.c storage.c manager.c \ + agent.c ipv4.c detect.c rtnl.c dbus.c if UDEV connmand_SOURCES += udev.c diff --git a/src/connman.h b/src/connman.h index 36d65ef..c4a079e 100644 --- a/src/connman.h +++ b/src/connman.h @@ -197,6 +197,11 @@ connman_bool_t __connman_network_has_driver(struct connman_network *network); int __connman_profile_add_network(struct connman_network *network); int __connman_profile_remove_network(struct connman_network *network); +#include + +int __connman_notifier_init(void); +void __connman_notifier_cleanup(void); + #include int __connman_rtnl_init(void); diff --git a/src/element.c b/src/element.c index b7e8951..9a2ec3b 100644 --- a/src/element.c +++ b/src/element.c @@ -1157,6 +1157,7 @@ int __connman_element_init(DBusConnection *conn, const char *device, element_root = g_node_new(element); + __connman_notifier_init(); __connman_network_init(); __connman_device_init(); @@ -1241,6 +1242,7 @@ void __connman_element_cleanup(void) __connman_device_cleanup(); __connman_network_cleanup(); + __connman_notifier_cleanup(); g_node_traverse(element_root, G_POST_ORDER, G_TRAVERSE_ALL, -1, free_driver, NULL); diff --git a/src/notifier.c b/src/notifier.c new file mode 100644 index 0000000..e2dcff8 --- /dev/null +++ b/src/notifier.c @@ -0,0 +1,79 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. + * + * 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 + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "connman.h" + +static GSList *notifier_list = NULL; + +static gint compare_priority(gconstpointer a, gconstpointer b) +{ + const struct connman_notifier *notifier1 = a; + const struct connman_notifier *notifier2 = b; + + return notifier2->priority - notifier1->priority; +} + +/** + * connman_notifier_register: + * @notifier: notifier module + * + * Register a new notifier module + * + * Returns: %0 on success + */ +int connman_notifier_register(struct connman_notifier *notifier) +{ + DBG("notifier %p name %s", notifier, notifier->name); + + notifier_list = g_slist_insert_sorted(notifier_list, notifier, + compare_priority); + + return 0; +} + +/** + * connman_notifier_unregister: + * @notifier: notifier module + * + * Remove a previously registered notifier module + */ +void connman_notifier_unregister(struct connman_notifier *notifier) +{ + DBG("notifier %p name %s", notifier, notifier->name); + + notifier_list = g_slist_remove(notifier_list, notifier); +} + +int __connman_notifier_init(void) +{ + DBG(""); + + return 0; +} + +void __connman_notifier_cleanup(void) +{ + DBG(""); +} -- 1.7.9.5