Library initialization

## Library initialization Library initialization — Initialize the library |

## Stability Level

Stable, unless otherwise indicated

## Synopsis

    #include <libvirt-glib/libvirt-glib.h>

    void                gvir_init                           (int *argc,
                                                             char ***argv);
    gboolean            gvir_init_check                     (int *argc,
                                                             char ***argv,
                                                             GError **err);

## Description

The Libvirt GLib library provides glue to integrate core libvirt infrastructure with the GLib library. This enables consistent error reporting procedures and a common event loop implementation for applications.

Before using any functions in the Libvirt GLib library, it must be initialized by calling `gvir_init` or `gvir_init_check`.

Example 1. Initializing the Libvirt GLib library

    1
    2
    3
    4
    5
    6
    7
    int main(int argc, char **argv) {
      ...setup...
      gvir_init(&argc, &argv);
      ...more setup...
      gtk_main();
      return 0;
    }

## Details

### gvir_init ()

    void                gvir_init                           (int *argc,
                                                             char ***argv);

Call this function before using any other Libvirt GLib functions in your applications. It will initialize everything needed to operate the toolkit and parses some standard command line options.

Although you are expected to pass the `argc`, `argv` parameters from `main()` to this function, it is possible to pass NULL if `argv` is not available or commandline handling is not required.

`argc` and `argv` are adjusted accordingly so your own code will never see those standard arguments.

This method will also turn on debug logging of the library if the `LIBVIRT_GLIB_DEBUG` environment variable is set.

This function will terminate your program if it was unable to initialize for some reason. If you want the program to fall back to an alternate mode of operation call `gvir_init_check` instead.

`argc` : | Address of the argc parameter of your `main()` function (or 0 if argv is NULL). This will be changed if any arguments were handled. [inout]
`argv` : | Address of the `argv` parameter of `main()`, or `NULL`. Any options understood by GTK+ are stripped before return. [array length=argc][inout][allow-none][transfer none]

### gvir_init_check ()

    gboolean            gvir_init_check                     (int *argc,
                                                             char ***argv,
                                                             GError **err);

This function does the same work as `gvir_init()` with only a single change: It does not terminate the program if the Libvirt GLib library can't be initialized. Instead it returns `FALSE` on failure.

This way the application can fall back to some other mode of operation.

`argc` : | Address of the argc parameter of your `main()` function (or 0 if argv is NULL). This will be changed if any arguments were handled. [inout]
`argv` : | Address of the `argv` parameter of `main()`, or `NULL`. Any options understood by GTK+ are stripped before return. [array length=argc][inout][allow-none][transfer none]
`err` : | filled with the error information if initialized failed.
Returns : | `TRUE` if the library was successfully initialized, `FALSE` otherwise