Add basic support for notifier infrastructure
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 11 Mar 2009 19:02:50 +0000 (20:02 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 11 Mar 2009 19:02:50 +0000 (20:02 +0100)
include/Makefile.am
include/notifier.h [new file with mode: 0644]
src/Makefile.am
src/connman.h
src/element.c
src/notifier.c [new file with mode: 0644]

index f8e9e73..a13ef80 100644 (file)
@@ -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 (file)
index 0000000..fc9939c
--- /dev/null
@@ -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 <connman/device.h>
+
+#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 */
index 79da404..897d573 100644 (file)
@@ -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
index 36d65ef..c4a079e 100644 (file)
@@ -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 <connman/notifier.h>
+
+int __connman_notifier_init(void);
+void __connman_notifier_cleanup(void);
+
 #include <connman/rtnl.h>
 
 int __connman_rtnl_init(void);
index b7e8951..9a2ec3b 100644 (file)
@@ -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 (file)
index 0000000..e2dcff8
--- /dev/null
@@ -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 <config.h>
+#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("");
+}