From ef394579b0d3311f899de9c9ad3fb61d2995f109 Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Thu, 13 Apr 2017 09:56:13 -0700 Subject: [PATCH] client: Add INTERFACE_TYPE --- client/dbus-proxy.c | 28 ++++++++++++++++++++++++++++ client/dbus-proxy.h | 14 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index f1d2f7c2..bea53ae6 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -24,6 +24,7 @@ #include #endif +#include #include #include "dbus-proxy.h" @@ -421,8 +422,13 @@ void proxy_interface_type_unregister( l_queue_remove(proxy_interface_types, (void *) interface_type); } +extern struct interface_type_desc __start___interface[]; +extern struct interface_type_desc __stop___interface[]; + bool dbus_proxy_init(void) { + struct interface_type_desc *desc; + if (dbus) return true; @@ -433,6 +439,16 @@ bool dbus_proxy_init(void) proxy_interface_types = l_queue_new(); proxy_interfaces = l_queue_new(); + if (__start___interface == NULL || __stop___interface == NULL) + return false; + + for (desc = __start___interface; desc < __stop___interface; desc++) { + if (!desc->init) + continue; + + desc->init(); + } + l_dbus_set_disconnect_handler(dbus, dbus_disconnect_callback, NULL, NULL); @@ -445,6 +461,18 @@ bool dbus_proxy_init(void) bool dbus_proxy_exit(void) { + struct interface_type_desc *desc; + + if (__start___interface == NULL || __stop___interface == NULL) + return false; + + for (desc = __start___interface; desc < __stop___interface; desc++) { + if (!desc->exit) + continue; + + desc->exit(); + } + l_queue_destroy(proxy_interface_types, NULL); proxy_interface_types = NULL; diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h index 5aa6af8c..5ffe5f0a 100644 --- a/client/dbus-proxy.h +++ b/client/dbus-proxy.h @@ -20,6 +20,8 @@ * */ +#include + struct proxy_interface; #define IWD_ADAPTER_INTERFACE "net.connman.iwd.Adapter" @@ -57,5 +59,17 @@ void proxy_interface_type_register( void proxy_interface_type_unregister( const struct proxy_interface_type *interface_type); +struct interface_type_desc { + const char *interface; + int (*init)(void); + void (*exit)(void); +} __attribute__((aligned(8))); + +#define INTERFACE_TYPE(interface, init, exit) \ + static struct interface_type_desc __interface_type_ ## interface\ + __attribute__((used, section("__interface"), aligned(8))) = {\ + #interface, init, exit \ + }; \ + bool dbus_proxy_init(void); bool dbus_proxy_exit(void);