diff options
| -rw-r--r-- | network/hal.c | 36 | ||||
| -rw-r--r-- | network/hal.h | 4 | ||||
| -rw-r--r-- | network/main.c | 5 | 
3 files changed, 43 insertions, 2 deletions
diff --git a/network/hal.c b/network/hal.c index f024282e..79e2b6e5 100644 --- a/network/hal.c +++ b/network/hal.c @@ -25,13 +25,47 @@  #include <config.h>  #endif +#include <errno.h> + +#include <dbus/dbus.h> +#include <hal/libhal.h> + +#include "logging.h" +  #include "hal.h" -int hal_init(void) +static LibHalContext *hal_ctx = NULL; + +int hal_init(DBusConnection *conn)  { +	hal_ctx = libhal_ctx_new(); +	if (!hal_ctx) +		return -ENOMEM; + +	if (libhal_ctx_set_dbus_connection(hal_ctx, conn) == FALSE) { +		libhal_ctx_free(hal_ctx); +		hal_ctx = NULL; +		return -EIO; +	} + +	if (libhal_ctx_init(hal_ctx, NULL) == FALSE) { +		error("Unable to init HAL context"); +		libhal_ctx_free(hal_ctx); +		hal_ctx = NULL; +		return -EIO; +	} +  	return 0;  }  void hal_cleanup(void)  { +	if (!hal_ctx) +		return; + +	libhal_ctx_shutdown(hal_ctx, NULL); + +	libhal_ctx_free(hal_ctx); + +	hal_ctx = NULL;  } diff --git a/network/hal.h b/network/hal.h index 769f203b..f664e143 100644 --- a/network/hal.h +++ b/network/hal.h @@ -21,5 +21,7 @@   *   */ -int hal_init(void); +#include <dbus/dbus.h> + +int hal_init(DBusConnection *conn);  void hal_cleanup(void); diff --git a/network/main.c b/network/main.c index d0daf429..607285f7 100644 --- a/network/main.c +++ b/network/main.c @@ -37,6 +37,7 @@  #include "logging.h"  #include "manager.h" +#include "hal.h"  static GMainLoop *main_loop; @@ -66,6 +67,8 @@ int main(int argc, char *argv[])  	/* Create event loop */  	main_loop = g_main_loop_new(NULL, FALSE); +	hal_init(NULL); +  	if (network_init() == -1)  		goto fail; @@ -76,6 +79,8 @@ int main(int argc, char *argv[])  	network_exit(); +	hal_cleanup(); +  fail:  	g_main_loop_unref(main_loop);  | 
