File: libvirt-gconfig-xml-doc.c

package info (click to toggle)
libvirt-glib 0.1.9-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,048 kB
  • ctags: 5,059
  • sloc: ansic: 19,912; sh: 11,803; makefile: 739; xml: 222; python: 134; perl: 104
file content (132 lines) | stat: -rw-r--r-- 4,233 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * libvirt-gconfig-xml-doc.c: libvirt XML document management
 *
 * Copyright (C) 2011 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Author: Christophe Fergeau <cfergeau@gmail.com>
 */

#include <config.h>

#include <string.h>

#include "libvirt-gconfig/libvirt-gconfig.h"
#include "libvirt-gconfig/libvirt-gconfig-xml-doc.h"

extern gboolean debugFlag;

#define GVIR_CONFIG_XML_DOC_GET_PRIVATE(obj)                         \
        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_XML_DOC, GVirConfigXmlDocPrivate))

struct _GVirConfigXmlDocPrivate
{
    xmlDocPtr doc;
};

G_DEFINE_TYPE(GVirConfigXmlDoc, gvir_config_xml_doc, G_TYPE_OBJECT);

enum {
    PROP_0,
    PROP_DOC
};

static void gvir_config_xml_doc_get_property(GObject *object,
                                              guint prop_id,
                                              GValue *value,
                                              GParamSpec *pspec)
{
    GVirConfigXmlDoc *xml_doc = GVIR_CONFIG_XML_DOC(object);

    switch (prop_id) {
    case PROP_DOC:
        g_value_set_pointer(value, xml_doc->priv->doc);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}

static void gvir_config_xml_doc_set_property(GObject *object,
                                              guint prop_id,
                                              const GValue *value,
                                              GParamSpec *pspec)
{
    GVirConfigXmlDoc *doc = GVIR_CONFIG_XML_DOC(object);

    switch (prop_id) {
    case PROP_DOC:
        doc->priv->doc = g_value_get_pointer(value);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}

static void gvir_config_xml_doc_finalize(GObject *object)
{
    GVirConfigXmlDoc *doc = GVIR_CONFIG_XML_DOC(object);
    GVirConfigXmlDocPrivate *priv = doc->priv;

    g_debug("Finalize GVirConfigXmlDoc=%p", doc);

    xmlFreeDoc(priv->doc);

    G_OBJECT_CLASS(gvir_config_xml_doc_parent_class)->finalize(object);
}

static void gvir_config_xml_doc_class_init(GVirConfigXmlDocClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS(klass);

    g_type_class_add_private(klass, sizeof(GVirConfigXmlDocPrivate));

    object_class->finalize = gvir_config_xml_doc_finalize;
    object_class->get_property = gvir_config_xml_doc_get_property;
    object_class->set_property = gvir_config_xml_doc_set_property;

    g_object_class_install_property(object_class,
                                    PROP_DOC,
                                    g_param_spec_pointer("doc",
                                                        "XML Doc",
                                                        "The XML doc this config object corresponds to",
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT_ONLY |
                                                        G_PARAM_STATIC_STRINGS));
}


static void gvir_config_xml_doc_init(GVirConfigXmlDoc *xml_doc)
{
    GVirConfigXmlDocPrivate *priv;

    g_debug("Init GVirConfigXmlDoc=%p", xml_doc);

    priv = xml_doc->priv = GVIR_CONFIG_XML_DOC_GET_PRIVATE(xml_doc);

    memset(priv, 0, sizeof(*priv));
}


GVirConfigXmlDoc *gvir_config_xml_doc_new(xmlDocPtr doc)
{
    if (doc == NULL) {
        doc = xmlNewDoc((xmlChar *)"1.0");
    }
    return GVIR_CONFIG_XML_DOC(g_object_new(GVIR_CONFIG_TYPE_XML_DOC,
                                             "doc", doc,
                                             NULL));
}