|
Packit |
a07778 |
/*
|
|
Packit |
a07778 |
* libvirt-gobject-main.c: libvirt gobject integration
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Copyright (C) 2008 Daniel P. Berrange
|
|
Packit |
a07778 |
* Copyright (C) 2010-2011 Red Hat, Inc.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a07778 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License as published by the Free Software Foundation; either
|
|
Packit |
a07778 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a07778 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a07778 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a07778 |
* Lesser General Public License for more details.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License along with this library. If not, see
|
|
Packit |
a07778 |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include <config.h>
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include <stdlib.h>
|
|
Packit |
a07778 |
#include <stdio.h>
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include "libvirt-glib/libvirt-glib.h"
|
|
Packit |
a07778 |
#include "libvirt-gobject/libvirt-gobject.h"
|
|
Packit |
a07778 |
#include "libvirt-gconfig/libvirt-gconfig-compat.h"
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_init_object:
|
|
Packit |
a07778 |
* @argc: (inout): pointer to application's argc
|
|
Packit |
a07778 |
* @argv: (inout) (array length=argc) (allow-none) (transfer none): pointer to application's argv
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
void gvir_init_object(int *argc,
|
|
Packit |
a07778 |
char ***argv)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GError *err = NULL;
|
|
Packit |
a07778 |
if (!gvir_init_object_check(argc, argv, &err)) {
|
|
Packit |
a07778 |
g_error("Could not initialize libvirt-gobject: %s\n",
|
|
Packit |
a07778 |
err->message);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_log_handler(const gchar *log_domain G_GNUC_UNUSED,
|
|
Packit |
a07778 |
GLogLevelFlags log_level G_GNUC_UNUSED,
|
|
Packit |
a07778 |
const gchar *message,
|
|
Packit |
a07778 |
gpointer user_data)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
if (user_data)
|
|
Packit |
a07778 |
fprintf(stderr, "%s\n", message);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_init_object_check:
|
|
Packit |
a07778 |
* @argc: (inout): pointer to application's argc
|
|
Packit |
a07778 |
* @argv: (inout) (array length=argc) (allow-none) (transfer none): pointer to application's argv
|
|
Packit |
a07778 |
* @err: pointer to a #GError to which a message will be posted on error
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
gboolean gvir_init_object_check(int *argc,
|
|
Packit |
a07778 |
char ***argv,
|
|
Packit |
a07778 |
GError **err)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
g_type_init();
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
gvir_event_register();
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
if (!gvir_init_check(argc, argv, err))
|
|
Packit |
a07778 |
return FALSE;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
if (!gvir_config_init_check(argc, argv, err))
|
|
Packit |
a07778 |
return FALSE;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/* GLib >= 2.31.0 debug is off by default, so we need to
|
|
Packit |
a07778 |
* enable it. Older versions are on by default, so we need
|
|
Packit |
a07778 |
* to disable it.
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
#if GLIB_CHECK_VERSION(2, 31, 0)
|
|
Packit |
a07778 |
if (getenv("LIBVIRT_GOBJECT_DEBUG"))
|
|
Packit |
a07778 |
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
|
Packit |
a07778 |
gvir_log_handler, (void*)0x1);
|
|
Packit |
a07778 |
#else
|
|
Packit |
a07778 |
if (!getenv("LIBVIRT_GOBJECT_DEBUG"))
|
|
Packit |
a07778 |
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
|
Packit |
a07778 |
gvir_log_handler, NULL);
|
|
Packit |
a07778 |
#endif
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
return TRUE;
|
|
Packit |
a07778 |
}
|