Codebase list libvirt-glib / upstream/0_1.git55696
New upstream version 0~1.git55696 Guido Günther 12 years ago
91 changed file(s) with 8688 addition(s) and 526 deletion(s). Raw diff Collapse all Expand all
0 build-aux
1 gnulib
2 Makefile
3 Makefile.in
4 *.o
5 *.Po
6 *.lo
7 *.Plo
8 *.Tpo
9 *.la
10 *~
11 *.orig
12 m4
13 autom4te.cache
14 config.*
15 COPYING
16 ABOUT-NLS
17 stamp-h1
18 src/virsh
19 */.libs
20 *.cov
21 *.gcda
22 *.gcno
23 aclocal.m4
24 libtool
25 ltmain.sh
26 mkinstalldirs
27 configure
28 INSTALL
29 compile
30 depcomp
31 install-sh
32 missing
33 examples/event-test
34 examples/conn-test
35 libvirt-glib.spec
36 libvirt-glib-1.0.pc
37 libvirt-gobject-1.0.pc
38 mingw32-libvirt-glib.spec
39 python/*pyc
40 */*.gir
41 */*.typelib
42 build/
43 libvirt-gobject/libvirt-gobject-enums.h
44 libvirt-gobject/libvirt-gobject-enums.c
+0
-78
.hgignore less more
0 build-aux/
1 gnulib/
2 Makefile$
3 Makefile\.in$
4 .\.Po$
5 .\.lo$
6 .\.o$
7 .\.Plo$
8 .\.Tpo$
9 .*~
10 \.orig$
11 ^m4
12 ^autom4te\.cache
13 ^config\.
14 ^COPYING
15 ^ABOUT-NLS
16 ^stamp-h1
17 ^src/virsh
18 ^src/libvirt.la
19 ^src/libvirt_test.la
20 ^src/\.libs
21 .*\.cov
22 .*\.gcda
23 .*\.gcno
24 ^aclocal.m4$
25 ^docs/devhelp/libvirt.devhelp$
26 ^libtool$
27 ^libvirt\.pc$
28 ^libvirt\.spec$
29 ^ltmain.sh$
30 ^mkinstalldirs$
31 ^po/Makefile\.in\.in$
32 ^po/Makevars\.template$
33 ^po/POTFILES$
34 ^po/Rules-quot$
35 ^po/boldquot\.sed$
36 ^po/insert-header\.sin$
37 ^po/quot\.sed$
38 ^po/remove-potcdate.sin$
39 ^po/remove-potcdate.sed$
40 ^po/.*\.gmo$
41 ^po/stamp-po$
42 ^configure$
43 ^qemud/libvirt_qemud$
44 ^qemud/libvirtd$
45 ^qemud/.libs
46 ^po/en@boldquot.header$
47 ^po/en@quot.header$
48 ^tests/.*test$
49 ^tests/reconnect$
50 ^python/libvirt\.py$
51 ^python/libvirt-py\.c$
52 ^python/libvirt-py\.h$
53 ^python/libvirtclass\.py$
54 ^python/libvirtclass\.txt$
55 ^python/libvirtmod\.la$
56 ^python/libvirt-export\.c$
57 ^python/\.libs
58 ^proxy/libvirt_proxy$
59 ^docs/examples/\.libs
60 ^docs/examples/info1$
61 ^docs/examples/suspend$
62 ^tests/.*\.gcda$
63 ^tests/.*\.gcno$
64 ^INSTALL$
65 ^compile$
66 ^depcomp$
67 ^install-sh$
68 ^missing$
69 ^src/libvirt_parthelper$
70 ^src/.*\.gcov$
71 ^qemud/libvirtd\.init$
72 ^coverage/
73 ^results.log$
74 src/.*\.la$
75 ^mingw-libvirt.spec$
76 ^src/libvirt_lxc$
77 ^build/
0 Tips for hacking on libvirt-glib
1 ================================
2
3 To test the GObject introspection based language bindings without
4 having to run make install, there are two environment variables
5 that need to be set:
6
7 export GI_TYPELIB_PATH=`pwd`/libvirt-glib:`pwd`/libvirt-gconfig:`pwd`/libvirt-gobject
8 export LD_LIBRARY_PATH=`pwd`/libvirt-glib/.libs:`pwd`/libvirt-gconfig/.libs:`pwd`/libvirt-gobject/.libs
+0
-1
INSTALL less more
0 /usr/share/automake-1.10/INSTALL
00
1 SUBDIRS = include src python examples
1 SUBDIRS = libvirt-glib libvirt-gconfig libvirt-gobject python examples
2
3 ACLOCAL_AMFLAGS = -I m4
24
35 pkgconfigdir = $(libdir)/pkgconfig
4 pkgconfig_DATA = libvirt-glib.pc
6 pkgconfig_DATA = libvirt-glib-1.0.pc libvirt-gconfig-1.0.pc libvirt-gobject-1.0.pc
57
6 EXTRA_DIST = @PACKAGE@.spec libvirt-glib.pc.in
8 EXTRA_DIST = @PACKAGE@.spec $(pkgconfig_DATA:%.pc=%.pc.in)
79
8 DISTCLEAN_FILES = @PACKAGE@.spec libvirt-glib.pc
10 DISTCLEAN_FILES = @PACKAGE@.spec $(pkgconfig_DATA)
4444
4545 cd $THEDIR
4646
47 $srcdir/configure --enable-compile-warnings=maximum "$@" && {
47 if test "x$1" = "x--system"; then
48 shift
49 prefix=/usr
50 libdir=$prefix/lib
51 sysconfdir=/etc
52 localstatedir=/var
53 if [ -d /usr/lib64 ]; then
54 libdir=$prefix/lib64
55 fi
56 EXTRA_ARGS="--prefix=$prefix --sysconfdir=$sysconfdir --localstatedir=$localstatedir --libdir=$libdir"
57 fi
58
59 $srcdir/configure --enable-compile-warnings=maximum $EXTRA_ARGS "$@" && {
4860 echo
4961 echo "Now type 'make' to compile libvirt-glib."
5062 }
00
11 AC_INIT(libvirt-glib, 0.0.1)
2 AC_CONFIG_SRCDIR(src/events.c)
2 AC_CONFIG_SRCDIR(libvirt-glib/libvirt-glib-main.c)
33 AC_CONFIG_AUX_DIR([build-aux])
44 AM_CONFIG_HEADER(config.h)
5 AC_CONFIG_MACRO_DIR([m4])
56 dnl Make automake keep quiet about wildcards & other GNUmake-isms
67 AM_INIT_AUTOMAKE([-Wno-portability])
78 AC_CANONICAL_HOST
89
10 AM_SILENT_RULES([yes])
11
912 LIBVIRT_REQUIRED=0.5.0
1013 GLIB2_REQUIRED=2.10.0
11
14 GOBJECT2_REQUIRED=2.10.0
15 GIO_REQUIRED=2.10.0
16 GOBJECT_INTROSPECTION_REQUIRED=0.10.8
17 LIBXML2_REQUIRED=2.0.0
1218
1319 LIBVIRT_GLIB_MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'`
1420 LIBVIRT_GLIB_MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'`
3036 AC_LIBTOOL_WIN32_DLL
3137 AC_PROG_LIBTOOL
3238
33 AC_CONFIG_LIBOBJ_DIR([src])
39 dnl AC_CONFIG_LIBOBJ_DIR([src])
3440
3541 AC_DEFINE([_GNU_SOURCE], [], [Enable GNU extensions])
3642
3844
3945 PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
4046 PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_REQUIRED)
47 PKG_CHECK_MODULES(GTHREAD2, gthread-2.0 >= $GLIB2_REQUIRED)
48 PKG_CHECK_MODULES(GOBJECT2, gobject-2.0 >= $GLIB2_REQUIRED)
49 PKG_CHECK_MODULES(GIO2, gio-2.0 >= $GLIB2_REQUIRED)
50 PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= $LIBXML2_REQUIRED)
4151
4252 dnl Extra link-time flags for Cygwin.
4353 dnl Copied from libxml2 configure.in, but I removed mingw changes
8494 dnl
8595 dnl check for python
8696 dnl
97 AC_ARG_WITH([python],
98 AC_HELP_STRING([--with-python], [Build python bindings @<:@default=yes@:>@]),[],[with_python=yes])
8799
88100 PYTHON_VERSION=
89101 PYTHON_INCLUDES=
91103 PYTHON_TESTS=
92104 pythondir=
93105 if test "$with_python" != "no" ; then
106 if test "$with_python" = "yes" ; then
107 with_python=""
108 fi
94109 if test -x "$with_python/bin/python"
95110 then
96111 echo Found python in $with_python/bin/python
157172 AC_SUBST([PYTHON_INCLUDES])
158173 AC_SUBST([PYTHON_SITE_PACKAGES])
159174
175 AC_ARG_ENABLE([introspection],
176 AS_HELP_STRING([--enable-introspection], [enable GObject introspection]),
177 [], [enable_introspection=check])
178
179 if test "x$enable_introspection" != "xno" ; then
180 PKG_CHECK_MODULES([GOBJECT_INTROSPECTION],
181 [gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_REQUIRED],
182 [enable_introspection=yes],
183 [
184 if test "x$enable_introspection" = "xcheck"; then
185 enable_introspection=no
186 else
187 AC_MSG_ERROR([gobject-introspection is not available])
188 fi
189 ])
190 if test "x$enable_introspection" = "xyes" ; then
191 AC_DEFINE([WITH_GOBJECT_INTROSPECTION], [1], [enable GObject introspection support])
192 AC_SUBST(GOBJECT_INTROSPECTION_CFLAGS)
193 AC_SUBST(GOBJECT_INTROSPECTION_LIBS)
194 AC_SUBST([G_IR_SCANNER], [$($PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0)])
195 AC_SUBST([G_IR_COMPILER], [$($PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0)])
196 fi
197 fi
198 AM_CONDITIONAL([WITH_GOBJECT_INTROSPECTION], [test "x$enable_introspection" = "xyes"])
160199
161200 AC_OUTPUT(Makefile
162 include/Makefile
163 include/libvirt-glib/Makefile
164 src/Makefile
201 libvirt-glib/Makefile
202 libvirt-gconfig/Makefile
203 libvirt-gobject/Makefile
165204 examples/Makefile
166205 python/Makefile
167 libvirt-glib.pc
206 libvirt-glib-1.0.pc
207 libvirt-gconfig-1.0.pc
208 libvirt-gobject-1.0.pc
168209 libvirt-glib.spec
169210 mingw32-libvirt-glib.spec)
00
1 noinst_PROGRAMS = event-test
1 noinst_PROGRAMS = event-test conn-test
22
33 EXTRA_DIST = event-test.py
44
55 event_test_CFLAGS = \
66 $(WARN_CFLAGS) \
7 $(GLIB2_CFLAGS) \
78 $(LIBVIRT_CFLAGS) \
8 $(GLIB2_CFLAGS) \
9 -I$(top_srcdir)/include \
10 -I../include
9 -I$(top_srcdir)
1110 event_test_SOURCES = \
1211 event-test.c
1312 event_test_LDADD = \
14 ../src/libvirt-glib.la \
13 ../libvirt-glib/libvirt-glib-1.0.la \
1514 $(LIBVIRT_LIBS) \
1615 $(GLIB2_LIBS)
16
17 conn_test_CFLAGS = \
18 $(WARN_CFLAGS) \
19 $(GLIB2_CFLAGS) \
20 $(LIBVIRT_CFLAGS) \
21 -I$(top_srcdir)
22 conn_test_SOURCES = \
23 conn-test.c
24 conn_test_LDADD = \
25 ../libvirt-gobject/libvirt-gobject-1.0.la \
26 $(LIBVIRT_LIBS) \
27 $(GLIB2_LIBS)
28
0 /*
1 * conn-test.c: test libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #include <config.h>
23
24 #include <libvirt-gobject/libvirt-gobject.h>
25
26 static void
27 do_connection_open(GObject *source,
28 GAsyncResult *res,
29 gpointer opaque)
30 {
31 GVirConnection *conn = GVIR_CONNECTION(source);
32 GError *err = NULL;
33 GMainLoop *loop = opaque;
34
35 if (!gvir_connection_open_finish(conn, res, &err)) {
36 g_error("%s", err->message);
37 }
38 g_print("Connected to libvirt\n");
39 g_main_loop_quit(loop);
40 }
41
42 int main(int argc, char **argv)
43 {
44 GVirConnection *conn;
45 GMainLoop *loop;
46
47 gvir_init_object(&argc, &argv);
48
49 if (argc != 2)
50 g_error("syntax: %s URI", argv[0]);
51
52 conn = gvir_connection_new(argv[1]);
53
54 loop = g_main_loop_new(g_main_context_default(),
55 TRUE);
56
57 gvir_connection_open_async(conn, NULL, do_connection_open, loop);
58 gvir_connection_open_async(conn, NULL, do_connection_open, loop);
59
60 g_main_loop_run(loop);
61
62 return 0;
63 }
64
0 #!/usr/bin/gjs
1
2 const lv = imports.gi.LibvirtGObject;
3 const gio = imports.gi.Gio;
4 const gtk = imports.gi.Gtk;
5
6 lv.init_object(null, null);
7
8 var conn = new lv.Connection({ uri: "test:///default" })
9 var canc = new gio.Cancellable()
10
11 function done(conn, result, data) {
12 try {
13 conn.open_finish(result)
14
15 print("Opened " + conn.get_uri())
16
17 conn.fetch_domains(null)
18 print ("Fetched")
19 var doms = conn.get_domains()
20 print ("Got " + doms)
21
22 for (var d in doms) {
23 print ("One dom: " + doms[d])
24 print ("Name " + doms[d].get_name())
25 var conf = doms[d].get_config(0)
26 print ("Conf " + conf)
27 var xml = conf.get_doc()
28 print ("XML " + xml)
29 print ("Info " + doms[d].get_info().memory)
30 }
31
32 } finally {
33 gtk.main_quit()
34 }
35 }
36
37 conn.open_async(canc, done, null)
38
39 gtk.main(null, null)
40
0 #!/usr/bin/python
1
2 from gi.repository import LibvirtGObject;
3 from gi.repository import Gio;
4 from gi.repository import Gtk;
5
6 LibvirtGObject.init_object_check(None);
7
8 conn = LibvirtGObject.Connection(uri="test:///default")
9 canc = Gio.Cancellable()
10
11 def done(conn, result, data):
12 try:
13 conn.open_finish(result)
14
15 print("Opened " + conn.get_uri())
16
17 conn.fetch_domains(None)
18 print ("Fetched")
19 doms = conn.get_domains()
20 print ("Got " + str(doms))
21
22 for d in doms:
23 print ("One dom: " + str(d))
24 print ("Name " + d.get_name())
25 conf = d.get_config(0)
26 print ("Conf " + str(conf))
27
28 try:
29 conf.validate()
30
31 print "Document is valid according to %s" % conf.get_schema()
32 except Exception, e:
33 print "Document is not valid according to %s: %s: %s" % (conf.get_schema(), str(e), str(type(e)))
34
35 xml = conf.get_doc()
36 print ("XML " + xml)
37 print ("Info " + str(d.get_info().memory))
38
39 finally:
40 Gtk.main_quit()
41
42
43 conn.open_async(canc, done, None)
44
45 Gtk.main()
46
47
153153 {
154154 GMainLoop *loop;
155155
156 gvir_init(&argc, &argv);
157
156158 if(argc > 1 && STREQ(argv[1],"--help")) {
157159 usage(argv[0]);
158160 return -1;
159161 }
160162 loop = g_main_loop_new(g_main_context_default(), 1);
161163
162 virEventRegisterGLib();
164 gvir_event_register();
163165
164166 virConnectPtr dconn = NULL;
165167 dconn = virConnectOpen (argv[1] ? argv[1] : NULL);
00
1 import pygtk
1 import gtk
22 import libvirt
3 import libvirtglib
43 import getopt
54 import sys
5
6 from gi.repository import LibvirtGLib;
67
78 def eventToString(event):
89 eventStrings = ( "Added",
1516 "Restored" );
1617 return eventStrings[event];
1718
18 def myDomainEventCallback1 (conn, dom, event, opaque):
19 def myDomainEventCallback1 (conn, dom, event, detail, opaque):
1920 print "myDomainEventCallback1 EVENT: Domain %s(%s) %s" % (dom.name(), dom.ID(), eventToString(event))
2021
21 def myDomainEventCallback2 (conn, dom, event, opaque):
22 def myDomainEventCallback2 (conn, dom, event, detail, opaque):
2223 print "myDomainEventCallback2 EVENT: Domain %s(%s) %s" % (dom.name(), dom.ID(), eventToString(event))
2324
2425 def usage():
4546
4647 print "Using uri:" + uri
4748
48 libvirtglib.eventRegister()
49 LibvirtGLib.init("")
50 LibvirtGLib.event_register()
51 # libvirtglib.eventRegister()
4952 vc = libvirt.open(uri)
5053
5154 #Add 2 callbacks to prove this works with more than just one
+0
-2
include/Makefile.am less more
0
1 SUBDIRS = libvirt-glib
+0
-3
include/libvirt-glib/Makefile.am less more
0
1 libvirt_glib_includedir = $(includedir)/libvirt-glib
2 libvirt_glib_include_HEADERS = libvirt-glib.h
+0
-36
include/libvirt-glib/libvirt-glib.h less more
0 /*
1 * libvirt-glib.h: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #ifndef __LIBVIRT_GLIB_H__
23 #define __LIBVIRT_GLIB_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 void virEventRegisterGLib(void);
30
31 #ifdef __cplusplus
32 };
33 #endif
34
35 #endif /* __LIBVIRT_GLIB_H__ */
0
1 EXTRA_DIST = libvirt-gconfig.sym
2
3 lib_LTLIBRARIES = libvirt-gconfig-1.0.la
4
5 GCONFIG_HEADER_FILES = \
6 libvirt-gconfig.h \
7 libvirt-gconfig-object.h \
8 libvirt-gconfig-capabilities.h \
9 libvirt-gconfig-domain.h \
10 libvirt-gconfig-domain-snapshot.h \
11 libvirt-gconfig-interface.h \
12 libvirt-gconfig-network.h \
13 libvirt-gconfig-network-filter.h \
14 libvirt-gconfig-node-device.h \
15 libvirt-gconfig-secret.h \
16 libvirt-gconfig-storage-pool.h \
17 libvirt-gconfig-storage-vol.h
18 GCONFIG_SOURCE_FILES = \
19 libvirt-gconfig-object.c \
20 libvirt-gconfig-capabilities.c \
21 libvirt-gconfig-domain.c \
22 libvirt-gconfig-domain-snapshot.c \
23 libvirt-gconfig-interface.c \
24 libvirt-gconfig-network.c \
25 libvirt-gconfig-network-filter.c \
26 libvirt-gconfig-node-device.c \
27 libvirt-gconfig-secret.c \
28 libvirt-gconfig-storage-pool.c \
29 libvirt-gconfig-storage-vol.c
30
31 libvirt_gconfig_1_0_ladir = $(includedir)/libvirt-gconfig-1.0/libvirt-gconfig
32 libvirt_gconfig_1_0_la_HEADERS = \
33 $(GCONFIG_HEADER_FILES)
34 libvirt_gconfig_1_0_la_SOURCES = \
35 $(libvirt_gconfig_1_0_la_HEADERS) \
36 $(GCONFIG_SOURCE_FILES)
37 libvirt_gconfig_1_0_la_CFLAGS = \
38 -DDATADIR="\"$(datadir)\"" \
39 -DLIBVIRT_GCONFIG_BUILD \
40 $(COVERAGE_CFLAGS) \
41 -I$(top_srcdir) \
42 $(GOBJECT2_CFLAGS) \
43 $(LIBXML2_CFLAGS) \
44 $(WARN_CFLAGS)
45 libvirt_gconfig_1_0_la_LIBADD = \
46 $(GOBJECT2_LIBS) \
47 $(LIBXML2_LIBS) \
48 $(CYGWIN_EXTRA_LIBADD)
49 libvirt_gconfig_1_0_la_DEPENDENCIES = \
50 libvirt-gconfig.sym
51 libvirt_gconfig_1_0_la_LDFLAGS = \
52 $(COVERAGE_CFLAGS:-f%=-Wc,f%) \
53 $(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS) \
54 -Wl,--version-script=$(srcdir)/libvirt-gconfig.sym \
55 -version-info $(LIBVIRT_GLIB_VERSION_INFO)
56
57 if WITH_GOBJECT_INTROSPECTION
58
59 LibvirtGConfig-1.0.gir: libvirt-gconfig-1.0.la $(G_IR_SCANNER) Makefile.am
60 $(AM_V_GEN)$(G_IR_SCANNER) \
61 --quiet \
62 --warn-all \
63 --namespace LibvirtGConfig \
64 --nsversion 1.0 \
65 --include GObject-2.0 \
66 --identifier-prefix=GVirConfig \
67 --symbol-prefix=gvir \
68 --library=$(builddir)/libvirt-gconfig-1.0.la \
69 --output $@ \
70 -I$(top_srcdir) \
71 -I$(top_builddir) \
72 --verbose \
73 --pkg=gobject-2.0 \
74 $(srcdir)/libvirt-gconfig.h \
75 $(GCONFIG_SOURCE_FILES:%=$(srcdir)/%) \
76 $(GCONFIG_HEADER_FILES:%=$(srcdir)/%)
77
78 girdir = $(datadir)/gir-1.0
79 gir_DATA = LibvirtGConfig-1.0.gir
80
81 typelibsdir = $(libdir)/girepository-1.0
82 typelibs_DATA = LibvirtGConfig-1.0.typelib
83
84 %.typelib: %.gir
85 $(AM_V_GEN)$(G_IR_COMPILER) \
86 --includedir=$(builddir) \
87 --includedir=$(girdir) \
88 -o $@ $<
89
90 CLEANFILES = $(gir_DATA) $(typelibs_DATA)
91
92 endif # WITH_GOBJECT_INTROSPECTION
0 /*
1 * libvirt-gobject-config_capabilities.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_CAPABILITIES, GVirConfigCapabilitiesPrivate))
35
36 struct _GVirConfigCapabilitiesPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigCapabilities, gvir_config_capabilities, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_capabilities_class_init(GVirConfigCapabilitiesClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesPrivate));
48 }
49
50
51 static void gvir_config_capabilities_init(GVirConfigCapabilities *conn)
52 {
53 GVirConfigCapabilitiesPrivate *priv;
54
55 DEBUG("Init GVirConfigCapabilities=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigCapabilities *gvir_config_capabilities_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_CAPABILITIES(g_object_new(GVIR_TYPE_CONFIG_CAPABILITIES,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/capability.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-capabilities-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__
27 #define __LIBVIRT_GCONFIG_CAPABILITIES_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_CAPABILITIES (gvir_config_capabilities_get_type ())
32 #define GVIR_CONFIG_CAPABILITIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_CAPABILITIES, GVirConfigCapabilities))
33 #define GVIR_CONFIG_CAPABILITIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_CAPABILITIES, GVirConfigCapabilitiesClass))
34 #define GVIR_IS_CONFIG_CAPABILITIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_CAPABILITIES))
35 #define GVIR_IS_CONFIG_CAPABILITIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_CAPABILITIES))
36 #define GVIR_CONFIG_CAPABILITIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_CAPABILITIES, GVirConfigCapabilitiesClass))
37
38 typedef struct _GVirConfigCapabilities GVirConfigCapabilities;
39 typedef struct _GVirConfigCapabilitiesPrivate GVirConfigCapabilitiesPrivate;
40 typedef struct _GVirConfigCapabilitiesClass GVirConfigCapabilitiesClass;
41
42 struct _GVirConfigCapabilities
43 {
44 GVirConfigObject parent;
45
46 GVirConfigCapabilitiesPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigCapabilitiesClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_capabilities_get_type(void);
60
61 GVirConfigCapabilities *gvir_config_capabilities_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_CAPABILITIES_H__ */
0 /*
1 * libvirt-gobject-config_domain_snapshot.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_DOMAIN_SNAPSHOT_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, GVirConfigDomainSnapshotPrivate))
35
36 struct _GVirConfigDomainSnapshotPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigDomainSnapshot, gvir_config_domain_snapshot, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_domain_snapshot_class_init(GVirConfigDomainSnapshotClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigDomainSnapshotPrivate));
48 }
49
50
51 static void gvir_config_domain_snapshot_init(GVirConfigDomainSnapshot *conn)
52 {
53 GVirConfigDomainSnapshotPrivate *priv;
54
55 DEBUG("Init GVirConfigDomainSnapshot=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_DOMAIN_SNAPSHOT_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_DOMAIN_SNAPSHOT(g_object_new(GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/domainsnapshot.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-domain_snapshot-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__
27 #define __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT (gvir_config_domain_snapshot_get_type ())
32 #define GVIR_CONFIG_DOMAIN_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, GVirConfigDomainSnapshot))
33 #define GVIR_CONFIG_DOMAIN_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, GVirConfigDomainSnapshotClass))
34 #define GVIR_IS_CONFIG_DOMAIN_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT))
35 #define GVIR_IS_CONFIG_DOMAIN_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT))
36 #define GVIR_CONFIG_DOMAIN_SNAPSHOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, GVirConfigDomainSnapshotClass))
37
38 typedef struct _GVirConfigDomainSnapshot GVirConfigDomainSnapshot;
39 typedef struct _GVirConfigDomainSnapshotPrivate GVirConfigDomainSnapshotPrivate;
40 typedef struct _GVirConfigDomainSnapshotClass GVirConfigDomainSnapshotClass;
41
42 struct _GVirConfigDomainSnapshot
43 {
44 GVirConfigObject parent;
45
46 GVirConfigDomainSnapshotPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigDomainSnapshotClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_domain_snapshot_get_type(void);
60
61 GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__ */
0 /*
1 * libvirt-gobject-config_domain.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_DOMAIN_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN, GVirConfigDomainPrivate))
35
36 struct _GVirConfigDomainPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigDomain, gvir_config_domain, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_domain_class_init(GVirConfigDomainClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigDomainPrivate));
48 }
49
50
51 static void gvir_config_domain_init(GVirConfigDomain *conn)
52 {
53 GVirConfigDomainPrivate *priv;
54
55 DEBUG("Init GVirConfigDomain=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_DOMAIN_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigDomain *gvir_config_domain_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_DOMAIN(g_object_new(GVIR_TYPE_CONFIG_DOMAIN,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/domain.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-domain-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_DOMAIN_H__
27 #define __LIBVIRT_GCONFIG_DOMAIN_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_DOMAIN (gvir_config_domain_get_type ())
32 #define GVIR_CONFIG_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN, GVirConfigDomain))
33 #define GVIR_CONFIG_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN, GVirConfigDomainClass))
34 #define GVIR_IS_CONFIG_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN))
35 #define GVIR_IS_CONFIG_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN))
36 #define GVIR_CONFIG_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN, GVirConfigDomainClass))
37
38 typedef struct _GVirConfigDomain GVirConfigDomain;
39 typedef struct _GVirConfigDomainPrivate GVirConfigDomainPrivate;
40 typedef struct _GVirConfigDomainClass GVirConfigDomainClass;
41
42 struct _GVirConfigDomain
43 {
44 GVirConfigObject parent;
45
46 GVirConfigDomainPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigDomainClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_domain_get_type(void);
60
61 GVirConfigDomain *gvir_config_domain_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_DOMAIN_H__ */
0 /*
1 * libvirt-gobject-config_interface.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_INTERFACE_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterfacePrivate))
35
36 struct _GVirConfigInterfacePrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigInterface, gvir_config_interface, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_interface_class_init(GVirConfigInterfaceClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigInterfacePrivate));
48 }
49
50
51 static void gvir_config_interface_init(GVirConfigInterface *conn)
52 {
53 GVirConfigInterfacePrivate *priv;
54
55 DEBUG("Init GVirConfigInterface=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_INTERFACE_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigInterface *gvir_config_interface_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_INTERFACE(g_object_new(GVIR_TYPE_CONFIG_INTERFACE,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/interface.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-interface-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_INTERFACE_H__
27 #define __LIBVIRT_GCONFIG_INTERFACE_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_INTERFACE (gvir_config_interface_get_type ())
32 #define GVIR_CONFIG_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterface))
33 #define GVIR_CONFIG_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterfaceClass))
34 #define GVIR_IS_CONFIG_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_INTERFACE))
35 #define GVIR_IS_CONFIG_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_INTERFACE))
36 #define GVIR_CONFIG_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_INTERFACE, GVirConfigInterfaceClass))
37
38 typedef struct _GVirConfigInterface GVirConfigInterface;
39 typedef struct _GVirConfigInterfacePrivate GVirConfigInterfacePrivate;
40 typedef struct _GVirConfigInterfaceClass GVirConfigInterfaceClass;
41
42 struct _GVirConfigInterface
43 {
44 GVirConfigObject parent;
45
46 GVirConfigInterfacePrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigInterfaceClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_interface_get_type(void);
60
61 GVirConfigInterface *gvir_config_interface_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_INTERFACE_H__ */
0 /*
1 * libvirt-gobject-config_network_filter.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_NETWORK_FILTER_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_NETWORK_FILTER, GVirConfigNetworkFilterPrivate))
35
36 struct _GVirConfigNetworkFilterPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigNetworkFilter, gvir_config_network_filter, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_network_filter_class_init(GVirConfigNetworkFilterClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigNetworkFilterPrivate));
48 }
49
50
51 static void gvir_config_network_filter_init(GVirConfigNetworkFilter *conn)
52 {
53 GVirConfigNetworkFilterPrivate *priv;
54
55 DEBUG("Init GVirConfigNetworkFilter=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_NETWORK_FILTER_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigNetworkFilter *gvir_config_network_filter_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_NETWORK_FILTER(g_object_new(GVIR_TYPE_CONFIG_NETWORK_FILTER,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/nwfilter.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-nwfilter-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_NETWORK_FILTER_H__
27 #define __LIBVIRT_GCONFIG_NETWORK_FILTER_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_NETWORK_FILTER (gvir_config_network_filter_get_type ())
32 #define GVIR_CONFIG_NETWORK_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_NETWORK_FILTER, GVirConfigNetworkFilter))
33 #define GVIR_CONFIG_NETWORK_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_NETWORK_FILTER, GVirConfigNetworkFilterClass))
34 #define GVIR_IS_CONFIG_NETWORK_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_NETWORK_FILTER))
35 #define GVIR_IS_CONFIG_NETWORK_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_NETWORK_FILTER))
36 #define GVIR_CONFIG_NETWORK_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_NETWORK_FILTER, GVirConfigNetworkFilterClass))
37
38 typedef struct _GVirConfigNetworkFilter GVirConfigNetworkFilter;
39 typedef struct _GVirConfigNetworkFilterPrivate GVirConfigNetworkFilterPrivate;
40 typedef struct _GVirConfigNetworkFilterClass GVirConfigNetworkFilterClass;
41
42 struct _GVirConfigNetworkFilter
43 {
44 GVirConfigObject parent;
45
46 GVirConfigNetworkFilterPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigNetworkFilterClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_network_filter_get_type(void);
60
61 GVirConfigNetworkFilter *gvir_config_network_filter_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_NETWORK_FILTER_H__ */
0 /*
1 * libvirt-gobject-config_network.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_NETWORK_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_NETWORK, GVirConfigNetworkPrivate))
35
36 struct _GVirConfigNetworkPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigNetwork, gvir_config_network, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_network_class_init(GVirConfigNetworkClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigNetworkPrivate));
48 }
49
50
51 static void gvir_config_network_init(GVirConfigNetwork *conn)
52 {
53 GVirConfigNetworkPrivate *priv;
54
55 DEBUG("Init GVirConfigNetwork=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_NETWORK_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigNetwork *gvir_config_network_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_NETWORK(g_object_new(GVIR_TYPE_CONFIG_NETWORK,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/network.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-network-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_NETWORK_H__
27 #define __LIBVIRT_GCONFIG_NETWORK_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_NETWORK (gvir_config_network_get_type ())
32 #define GVIR_CONFIG_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_NETWORK, GVirConfigNetwork))
33 #define GVIR_CONFIG_NETWORK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_NETWORK, GVirConfigNetworkClass))
34 #define GVIR_IS_CONFIG_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_NETWORK))
35 #define GVIR_IS_CONFIG_NETWORK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_NETWORK))
36 #define GVIR_CONFIG_NETWORK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_NETWORK, GVirConfigNetworkClass))
37
38 typedef struct _GVirConfigNetwork GVirConfigNetwork;
39 typedef struct _GVirConfigNetworkPrivate GVirConfigNetworkPrivate;
40 typedef struct _GVirConfigNetworkClass GVirConfigNetworkClass;
41
42 struct _GVirConfigNetwork
43 {
44 GVirConfigObject parent;
45
46 GVirConfigNetworkPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigNetworkClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_network_get_type(void);
60
61 GVirConfigNetwork *gvir_config_network_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_NETWORK_H__ */
0 /*
1 * libvirt-gobject-config_node_device.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_NODE_DEVICE_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_NODE_DEVICE, GVirConfigNodeDevicePrivate))
35
36 struct _GVirConfigNodeDevicePrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigNodeDevice, gvir_config_node_device, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_node_device_class_init(GVirConfigNodeDeviceClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigNodeDevicePrivate));
48 }
49
50
51 static void gvir_config_node_device_init(GVirConfigNodeDevice *conn)
52 {
53 GVirConfigNodeDevicePrivate *priv;
54
55 DEBUG("Init GVirConfigNodeDevice=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_NODE_DEVICE_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigNodeDevice *gvir_config_node_device_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_NODE_DEVICE(g_object_new(GVIR_TYPE_CONFIG_NODE_DEVICE,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/nodedev.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-nodedevice-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_NODE_DEVICE_H__
27 #define __LIBVIRT_GCONFIG_NODE_DEVICE_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_NODE_DEVICE (gvir_config_node_device_get_type ())
32 #define GVIR_CONFIG_NODE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_NODE_DEVICE, GVirConfigNodeDevice))
33 #define GVIR_CONFIG_NODE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_NODE_DEVICE, GVirConfigNodeDeviceClass))
34 #define GVIR_IS_CONFIG_NODE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_NODE_DEVICE))
35 #define GVIR_IS_CONFIG_NODE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_NODE_DEVICE))
36 #define GVIR_CONFIG_NODE_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_NODE_DEVICE, GVirConfigNodeDeviceClass))
37
38 typedef struct _GVirConfigNodeDevice GVirConfigNodeDevice;
39 typedef struct _GVirConfigNodeDevicePrivate GVirConfigNodeDevicePrivate;
40 typedef struct _GVirConfigNodeDeviceClass GVirConfigNodeDeviceClass;
41
42 struct _GVirConfigNodeDevice
43 {
44 GVirConfigObject parent;
45
46 GVirConfigNodeDevicePrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigNodeDeviceClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_node_device_get_type(void);
60
61 GVirConfigNodeDevice *gvir_config_node_device_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_NODE_DEVICE_H__ */
0 /*
1 * libvirt-gconfig-config-object.c: base object for XML configuration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include <libxml/relaxng.h>
28 #include <libxml/xmlerror.h>
29
30 #include "libvirt-gconfig/libvirt-gconfig.h"
31
32 //extern gboolean debugFlag;
33 gboolean debugFlag;
34
35 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
36
37 #define GVIR_CONFIG_OBJECT_GET_PRIVATE(obj) \
38 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_OBJECT, GVirConfigObjectPrivate))
39
40 struct _GVirConfigObjectPrivate
41 {
42 gchar *doc;
43 gchar *schema;
44
45 xmlDocPtr docHandle;
46 };
47
48 G_DEFINE_ABSTRACT_TYPE(GVirConfigObject, gvir_config_object, G_TYPE_OBJECT);
49
50 enum {
51 PROP_0,
52 PROP_DOC,
53 PROP_SCHEMA,
54 };
55
56
57 #define GVIR_CONFIG_OBJECT_ERROR gvir_config_object_error_quark()
58
59
60 static GQuark
61 gvir_config_object_error_quark(void)
62 {
63 return g_quark_from_static_string("gvir-config-object");
64 }
65
66 static GError *gvir_xml_error_new_literal(GQuark domain,
67 gint code,
68 const gchar *message)
69 {
70 xmlErrorPtr xerr = xmlGetLastError();
71
72 if (!xerr)
73 return NULL;
74
75 if (message)
76 return g_error_new(domain,
77 code,
78 "%s: %s",
79 message,
80 xerr->message);
81 else
82 return g_error_new(domain,
83 code,
84 "%s",
85 message);
86 }
87
88
89 static GError *gvir_xml_error_new(GQuark domain,
90 gint code,
91 const gchar *format,
92 ...)
93 {
94 GError *err;
95 va_list args;
96 gchar *message;
97
98 va_start(args, format);
99 message = g_strdup_vprintf(format, args);
100 va_end(args);
101
102 err = gvir_xml_error_new_literal(domain, code, message);
103
104 g_free(message);
105
106 return err;
107 }
108
109 static void gvir_xml_generic_error_nop(void *userData G_GNUC_UNUSED,
110 const char *msg G_GNUC_UNUSED,
111 ...)
112 {
113 }
114
115 static void gvir_xml_structured_error_nop(void *userData G_GNUC_UNUSED,
116 xmlErrorPtr error G_GNUC_UNUSED)
117 {
118 }
119
120 static void gvir_config_object_get_property(GObject *object,
121 guint prop_id,
122 GValue *value,
123 GParamSpec *pspec)
124 {
125 GVirConfigObject *conn = GVIR_CONFIG_OBJECT(object);
126 GVirConfigObjectPrivate *priv = conn->priv;
127
128 switch (prop_id) {
129 case PROP_DOC:
130 g_value_set_string(value, priv->doc);
131 break;
132
133 case PROP_SCHEMA:
134 g_value_set_string(value, priv->schema);
135 break;
136
137 default:
138 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
139 }
140 }
141
142
143 static void gvir_config_object_set_property(GObject *object,
144 guint prop_id,
145 const GValue *value,
146 GParamSpec *pspec)
147 {
148 GVirConfigObject *conn = GVIR_CONFIG_OBJECT(object);
149 GVirConfigObjectPrivate *priv = conn->priv;
150
151 switch (prop_id) {
152 case PROP_DOC:
153 g_free(priv->doc);
154 priv->doc = g_value_dup_string(value);
155 break;
156
157 case PROP_SCHEMA:
158 g_free(priv->schema);
159 priv->schema = g_value_dup_string(value);
160 break;
161
162 default:
163 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
164 }
165 }
166
167
168 static void gvir_config_object_finalize(GObject *object)
169 {
170 GVirConfigObject *conn = GVIR_CONFIG_OBJECT(object);
171 GVirConfigObjectPrivate *priv = conn->priv;
172
173 DEBUG("Finalize GVirConfigObject=%p", conn);
174
175 g_free(priv->doc);
176 g_free(priv->schema);
177
178 if (priv->docHandle)
179 xmlFreeDoc(priv->docHandle);
180
181 G_OBJECT_CLASS(gvir_config_object_parent_class)->finalize(object);
182 }
183
184
185 static void gvir_config_object_class_init(GVirConfigObjectClass *klass)
186 {
187 GObjectClass *object_class = G_OBJECT_CLASS(klass);
188
189 object_class->finalize = gvir_config_object_finalize;
190 object_class->get_property = gvir_config_object_get_property;
191 object_class->set_property = gvir_config_object_set_property;
192
193 g_object_class_install_property(object_class,
194 PROP_DOC,
195 g_param_spec_string("doc",
196 "Doc",
197 "The XML document",
198 NULL,
199 G_PARAM_READABLE |
200 G_PARAM_WRITABLE |
201 G_PARAM_CONSTRUCT_ONLY |
202 G_PARAM_STATIC_NAME |
203 G_PARAM_STATIC_NICK |
204 G_PARAM_STATIC_BLURB));
205 g_object_class_install_property(object_class,
206 PROP_SCHEMA,
207 g_param_spec_string("schema",
208 "Schema",
209 "The doc RNG schema",
210 NULL,
211 G_PARAM_READABLE |
212 G_PARAM_WRITABLE |
213 G_PARAM_CONSTRUCT_ONLY |
214 G_PARAM_STATIC_NAME |
215 G_PARAM_STATIC_NICK |
216 G_PARAM_STATIC_BLURB));
217
218 g_type_class_add_private(klass, sizeof(GVirConfigObjectPrivate));
219 }
220
221
222 static void gvir_config_object_init(GVirConfigObject *conn)
223 {
224 GVirConfigObjectPrivate *priv;
225
226 DEBUG("Init GVirConfigObject=%p", conn);
227
228 priv = conn->priv = GVIR_CONFIG_OBJECT_GET_PRIVATE(conn);
229
230 memset(priv, 0, sizeof(*priv));
231 }
232
233 static void
234 gvir_config_object_parse(GVirConfigObject *config,
235 GError **err)
236 {
237 GVirConfigObjectPrivate *priv = config->priv;
238 if (priv->docHandle)
239 return;
240
241 priv->docHandle = xmlParseMemory(priv->doc, strlen(priv->doc));
242 if (!priv->docHandle) {
243 *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
244 0,
245 "%s",
246 "Unable to parse configuration");
247 }
248 }
249
250
251 void gvir_config_object_validate(GVirConfigObject *config,
252 GError **err)
253 {
254 GVirConfigObjectPrivate *priv = config->priv;
255 xmlRelaxNGParserCtxtPtr rngParser = NULL;
256 xmlRelaxNGPtr rng = NULL;
257 xmlRelaxNGValidCtxtPtr rngValid = NULL;
258
259 xmlSetGenericErrorFunc(NULL, gvir_xml_generic_error_nop);
260 xmlSetStructuredErrorFunc(NULL, gvir_xml_structured_error_nop);
261
262 gvir_config_object_parse(config, err);
263 if (*err)
264 return;
265
266 rngParser = xmlRelaxNGNewParserCtxt(priv->schema);
267 if (!rngParser) {
268 *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
269 0,
270 "Unable to create RNG parser for %s",
271 priv->schema);
272 return;
273 }
274
275 rng = xmlRelaxNGParse(rngParser);
276 if (!rng) {
277 *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
278 0,
279 "Unable to parse RNG %s",
280 priv->schema);
281 xmlRelaxNGFreeParserCtxt(rngParser);
282 return;
283 }
284 xmlRelaxNGFreeParserCtxt(rngParser);
285
286 rngValid = xmlRelaxNGNewValidCtxt(rng);
287 if (!rngValid) {
288 *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
289 0,
290 "Unable to create RNG validation context %s",
291 priv->schema);
292 xmlRelaxNGFree(rng);
293 return;
294 }
295
296 if (xmlRelaxNGValidateDoc(rngValid, priv->docHandle) != 0) {
297 *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
298 0,
299 "%s",
300 "Unable to validate doc");
301 xmlRelaxNGFreeValidCtxt(rngValid);
302 xmlRelaxNGFree(rng);
303 return;
304 }
305
306 xmlRelaxNGFreeValidCtxt(rngValid);
307 xmlRelaxNGFree(rng);
308 }
309
310 const gchar *gvir_config_object_get_doc(GVirConfigObject *config)
311 {
312 GVirConfigObjectPrivate *priv = config->priv;
313 return priv->doc;
314 }
315
316 const gchar *gvir_config_object_get_schema(GVirConfigObject *config)
317 {
318 GVirConfigObjectPrivate *priv = config->priv;
319 return priv->schema;
320 }
321
0 /*
1 * libvirt-gconfig-config-object.c: base object for XML configuration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_OBJECT_H__
27 #define __LIBVIRT_GCONFIG_OBJECT_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_OBJECT (gvir_config_object_get_type ())
32 #define GVIR_CONFIG_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_OBJECT, GVirConfigObject))
33 #define GVIR_CONFIG_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_OBJECT, GVirConfigObjectClass))
34 #define GVIR_IS_CONFIG_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_OBJECT))
35 #define GVIR_IS_CONFIG_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_OBJECT))
36 #define GVIR_CONFIG_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_OBJECT, GVirConfigObjectClass))
37
38 typedef struct _GVirConfigObject GVirConfigObject;
39 typedef struct _GVirConfigObjectPrivate GVirConfigObjectPrivate;
40 typedef struct _GVirConfigObjectClass GVirConfigObjectClass;
41
42 struct _GVirConfigObject
43 {
44 GObject parent;
45
46 GVirConfigObjectPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigObjectClass
52 {
53 GObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_object_get_type(void);
60
61 void gvir_config_object_validate(GVirConfigObject *config,
62 GError **err);
63
64 const gchar *gvir_config_object_get_doc(GVirConfigObject *config);
65 const gchar *gvir_config_object_get_schema(GVirConfigObject *config);
66
67 G_END_DECLS
68
69 #endif /* __LIBVIRT_GCONFIG_OBJECT_H__ */
0 /*
1 * libvirt-gobject-config_secret.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_SECRET_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_SECRET, GVirConfigSecretPrivate))
35
36 struct _GVirConfigSecretPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigSecret, gvir_config_secret, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_secret_class_init(GVirConfigSecretClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigSecretPrivate));
48 }
49
50
51 static void gvir_config_secret_init(GVirConfigSecret *conn)
52 {
53 GVirConfigSecretPrivate *priv;
54
55 DEBUG("Init GVirConfigSecret=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_SECRET_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigSecret *gvir_config_secret_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_SECRET(g_object_new(GVIR_TYPE_CONFIG_SECRET,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/secret.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-secret-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_SECRET_H__
27 #define __LIBVIRT_GCONFIG_SECRET_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_SECRET (gvir_config_secret_get_type ())
32 #define GVIR_CONFIG_SECRET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_SECRET, GVirConfigSecret))
33 #define GVIR_CONFIG_SECRET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_SECRET, GVirConfigSecretClass))
34 #define GVIR_IS_CONFIG_SECRET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_SECRET))
35 #define GVIR_IS_CONFIG_SECRET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_SECRET))
36 #define GVIR_CONFIG_SECRET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_SECRET, GVirConfigSecretClass))
37
38 typedef struct _GVirConfigSecret GVirConfigSecret;
39 typedef struct _GVirConfigSecretPrivate GVirConfigSecretPrivate;
40 typedef struct _GVirConfigSecretClass GVirConfigSecretClass;
41
42 struct _GVirConfigSecret
43 {
44 GVirConfigObject parent;
45
46 GVirConfigSecretPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigSecretClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_secret_get_type(void);
60
61 GVirConfigSecret *gvir_config_secret_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_SECRET_H__ */
0 /*
1 * libvirt-gconfig-storage-pool.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_STORAGE_POOL_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_STORAGE_POOL, GVirConfigStoragePoolPrivate))
35
36 struct _GVirConfigStoragePoolPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigStoragePool, gvir_config_storage_pool, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_storage_pool_class_init(GVirConfigStoragePoolClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigStoragePoolPrivate));
48 }
49
50
51 static void gvir_config_storage_pool_init(GVirConfigStoragePool *conn)
52 {
53 GVirConfigStoragePoolPrivate *priv;
54
55 DEBUG("Init GVirConfigStoragePool=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_STORAGE_POOL_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigStoragePool *gvir_config_storage_pool_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_STORAGE_POOL(g_object_new(GVIR_TYPE_CONFIG_STORAGE_POOL,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/storagepool.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-storage-pool-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_STORAGE_POOL_H__
27 #define __LIBVIRT_GCONFIG_STORAGE_POOL_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_STORAGE_POOL (gvir_config_storage_pool_get_type ())
32 #define GVIR_CONFIG_STORAGE_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_STORAGE_POOL, GVirConfigStoragePool))
33 #define GVIR_CONFIG_STORAGE_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_STORAGE_POOL, GVirConfigStoragePoolClass))
34 #define GVIR_IS_CONFIG_STORAGE_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_STORAGE_POOL))
35 #define GVIR_IS_CONFIG_STORAGE_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_STORAGE_POOL))
36 #define GVIR_CONFIG_STORAGE_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_STORAGE_POOL, GVirConfigStoragePoolClass))
37
38 typedef struct _GVirConfigStoragePool GVirConfigStoragePool;
39 typedef struct _GVirConfigStoragePoolPrivate GVirConfigStoragePoolPrivate;
40 typedef struct _GVirConfigStoragePoolClass GVirConfigStoragePoolClass;
41
42 struct _GVirConfigStoragePool
43 {
44 GVirConfigObject parent;
45
46 GVirConfigStoragePoolPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigStoragePoolClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_storage_pool_get_type(void);
60
61 GVirConfigStoragePool *gvir_config_storage_pool_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_STORAGE_POOL_H__ */
0 /*
1 * libvirt-gobject-config_storage_vol.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include "libvirt-gconfig/libvirt-gconfig.h"
28
29 extern gboolean debugFlag;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 #define GVIR_CONFIG_STORAGE_VOL_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_STORAGE_VOL, GVirConfigStorageVolPrivate))
35
36 struct _GVirConfigStorageVolPrivate
37 {
38 gboolean unused;
39 };
40
41 G_DEFINE_TYPE(GVirConfigStorageVol, gvir_config_storage_vol, GVIR_TYPE_CONFIG_OBJECT);
42
43
44 static void gvir_config_storage_vol_class_init(GVirConfigStorageVolClass *klass)
45 {
46
47 g_type_class_add_private(klass, sizeof(GVirConfigStorageVolPrivate));
48 }
49
50
51 static void gvir_config_storage_vol_init(GVirConfigStorageVol *conn)
52 {
53 GVirConfigStorageVolPrivate *priv;
54
55 DEBUG("Init GVirConfigStorageVol=%p", conn);
56
57 priv = conn->priv = GVIR_CONFIG_STORAGE_VOL_GET_PRIVATE(conn);
58
59 memset(priv, 0, sizeof(*priv));
60 }
61
62
63 GVirConfigStorageVol *gvir_config_storage_vol_new(const gchar *xml)
64 {
65 return GVIR_CONFIG_STORAGE_VOL(g_object_new(GVIR_TYPE_CONFIG_STORAGE_VOL,
66 "doc", xml,
67 "schema", DATADIR "/libvirt/schemas/storage_vol.rng",
68 NULL));
69 }
0 /*
1 * libvirt-gobject-storage_vol-config.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
23 #error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GCONFIG_STORAGE_VOL_H__
27 #define __LIBVIRT_GCONFIG_STORAGE_VOL_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONFIG_STORAGE_VOL (gvir_config_storage_vol_get_type ())
32 #define GVIR_CONFIG_STORAGE_VOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_STORAGE_VOL, GVirConfigStorageVol))
33 #define GVIR_CONFIG_STORAGE_VOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_STORAGE_VOL, GVirConfigStorageVolClass))
34 #define GVIR_IS_CONFIG_STORAGE_VOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_STORAGE_VOL))
35 #define GVIR_IS_CONFIG_STORAGE_VOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_STORAGE_VOL))
36 #define GVIR_CONFIG_STORAGE_VOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_STORAGE_VOL, GVirConfigStorageVolClass))
37
38 typedef struct _GVirConfigStorageVol GVirConfigStorageVol;
39 typedef struct _GVirConfigStorageVolPrivate GVirConfigStorageVolPrivate;
40 typedef struct _GVirConfigStorageVolClass GVirConfigStorageVolClass;
41
42 struct _GVirConfigStorageVol
43 {
44 GVirConfigObject parent;
45
46 GVirConfigStorageVolPrivate *priv;
47
48 /* Do not add fields to this struct */
49 };
50
51 struct _GVirConfigStorageVolClass
52 {
53 GVirConfigObjectClass parent_class;
54
55 gpointer padding[20];
56 };
57
58
59 GType gvir_config_storage_vol_get_type(void);
60
61 GVirConfigStorageVol *gvir_config_storage_vol_new(const gchar *xml);
62
63 G_END_DECLS
64
65 #endif /* __LIBVIRT_GCONFIG_STORAGE_VOL_H__ */
0 /*
1 * libvirt-gconfig.h: libvirt gconfig integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #ifndef __LIBVIRT_GCONFIG_H__
23 #define __LIBVIRT_GCONFIG_H__
24
25 #include <glib-object.h>
26
27 #include <libvirt-gconfig/libvirt-gconfig-object.h>
28 #include <libvirt-gconfig/libvirt-gconfig-capabilities.h>
29 #include <libvirt-gconfig/libvirt-gconfig-domain.h>
30 #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h>
31 #include <libvirt-gconfig/libvirt-gconfig-interface.h>
32 #include <libvirt-gconfig/libvirt-gconfig-network.h>
33 #include <libvirt-gconfig/libvirt-gconfig-node-device.h>
34 #include <libvirt-gconfig/libvirt-gconfig-network-filter.h>
35 #include <libvirt-gconfig/libvirt-gconfig-secret.h>
36 #include <libvirt-gconfig/libvirt-gconfig-storage-pool.h>
37 #include <libvirt-gconfig/libvirt-gconfig-storage-vol.h>
38
39 #endif /* __LIBVIRT_GCONFIG_H__ */
0 LIBVIRT_GOBJECT_0.0.1 {
1 global:
2 gvir_config_capabilities_get_type;
3 gvir_config_capabilities_new;
4
5 gvir_config_domain_get_type;
6 gvir_config_domain_new;
7
8 gvir_config_domain_snapshot_get_type;
9 gvir_config_domain_snapshot_new;
10
11 gvir_config_interface_get_type;
12 gvir_config_interface_new;
13
14 gvir_config_network_get_type;
15 gvir_config_network_new;
16
17 gvir_config_network_filter_get_type;
18 gvir_config_network_filter_new;
19
20 gvir_config_node_device_get_type;
21 gvir_config_node_device_new;
22
23 gvir_config_object_get_type;
24 gvir_config_object_new;
25 gvir_config_object_get_doc;
26 gvir_config_object_get_schema;
27 gvir_config_object_validate;
28
29 gvir_config_secret_get_type;
30 gvir_config_secret_new;
31
32 gvir_config_storage_pool_get_type;
33 gvir_config_storage_pool_new;
34
35 gvir_config_storage_vol_get_type;
36 gvir_config_storage_vol_new;
37
38 local:
39 *;
40 };
41
42 # .... define new API here using predicted next version number ....
0 prefix=@prefix@
1 exec_prefix=@exec_prefix@
2 libdir=@libdir@
3 includedir=@includedir@
4
5 Name: libvirt-gconfig
6 Version: @VERSION@
7 Description: libvirt GConfig library
8 Requires: gobject-2.0
9 Libs: -L${libdir} -lvirt-gconfig-1.0
10 Cflags: -I${includedir}/libvirt-gconfig-1.0
0
1 EXTRA_DIST = libvirt-glib.sym
2
3 lib_LTLIBRARIES = libvirt-glib-1.0.la
4
5 libvirt_glib_1_0_ladir = $(includedir)/libvirt-glib-1.0/libvirt-glib
6 libvirt_glib_1_0_la_HEADERS = \
7 libvirt-glib.h \
8 libvirt-glib-error.h \
9 libvirt-glib-event.h \
10 libvirt-glib-main.h
11 libvirt_glib_1_0_la_SOURCES = \
12 $(libvirt_glib_1_0_la_HEADERS) \
13 libvirt-glib-error.c \
14 libvirt-glib-event.c \
15 libvirt-glib-main.c
16 libvirt_glib_1_0_la_CFLAGS = \
17 -DLIBVIRT_GLIB_BUILD \
18 $(COVERAGE_CFLAGS) \
19 -I$(top_srcdir) \
20 $(LIBVIRT_CFLAGS) \
21 $(GLIB2_CFLAGS) \
22 $(GTHREAD2_CFLAGS) \
23 $(WARN_CFLAGS)
24 libvirt_glib_1_0_la_LIBADD = \
25 $(LIBVIRT_LIBS) \
26 $(GLIB2_LIBS) \
27 $(GTHREAD2_LIBS) \
28 $(CYGWIN_EXTRA_LIBADD)
29 libvirt_glib_1_0_la_DEPENDENCIES = \
30 libvirt-glib.sym
31 libvirt_glib_1_0_la_LDFLAGS = \
32 $(COVERAGE_CFLAGS:-f%=-Wc,f%) \
33 $(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS) \
34 -Wl,--version-script=$(srcdir)/libvirt-glib.sym \
35 -version-info $(LIBVIRT_GLIB_VERSION_INFO)
36
37 if WITH_GOBJECT_INTROSPECTION
38
39 LibvirtGLib-1.0.gir: libvirt-glib-1.0.la $(G_IR_SCANNER) Makefile.am
40 $(AM_V_GEN)$(G_IR_SCANNER) \
41 --quiet \
42 --warn-all \
43 --namespace LibvirtGLib \
44 --nsversion 1.0 \
45 --include GLib-2.0 \
46 --identifier-prefix=GVir \
47 --symbol-prefix=gvir \
48 --library=$(builddir)/libvirt-glib-1.0.la \
49 --add-include-path=$(builddir) \
50 --output $@ \
51 -I$(top_srcdir) \
52 -I$(srcdir) \
53 --pkg=glib-2.0 \
54 --pkg=gthread-2.0 \
55 $(libvirt_glib_1_0_la_SOURCES:%=$(srcdir)/%)
56
57 girdir = $(datadir)/gir-1.0
58 gir_DATA = LibvirtGLib-1.0.gir
59
60 typelibsdir = $(libdir)/girepository-1.0
61 typelibs_DATA = LibvirtGLib-1.0.typelib
62
63 %.typelib: %.gir
64 $(AM_V_GEN)$(G_IR_COMPILER) \
65 --includedir=$(builddir) \
66 --includedir=$(girdir) \
67 -o $@ $<
68
69 CLEANFILES = $(gir_DATA) $(typelibs_DATA)
70
71 endif # WITH_GOBJECT_INTROSPECTION
0 /*
1 * libvirt-glib-error.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/libvirt.h>
26 #include <libvirt/virterror.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29
30 /**
31 * gvir_error_new: (skip)
32 * @domain: error domain
33 * @code: error code
34 * @format: printf()-style format for error message
35 * @Varargs: parameters for message format
36 *
37 * Creates a new #GError with the given @domain and @code,
38 * and a message formatted with @format.
39 *
40 * Returns: a new #GError
41 */
42 GError *gvir_error_new(GQuark domain,
43 gint code,
44 const gchar *format,
45 ...)
46 {
47 GError *err;
48 va_list args;
49 gchar *message;
50
51 va_start(args, format);
52 message = g_strdup_vprintf(format, args);
53 va_end(args);
54
55 err = gvir_error_new_literal(domain, code, message);
56
57 g_free(message);
58
59 return err;
60 }
61
62 /**
63 * gvir_error_new_literal: (skip)
64 * @domain: error domain
65 * @code: error code
66 * @message: error message
67 *
68 * Creates a new #GError; unlike gvir_error_new(), @message is
69 * not a printf()-style format string. Use this function if
70 * @message contains text you don't have control over,
71 * that could include printf() escape sequences.
72 *
73 * Returns: a new #GError
74 */
75 GError *gvir_error_new_literal(GQuark domain,
76 gint code,
77 const gchar *message)
78 {
79 virErrorPtr verr = virGetLastError();
80
81 if (!verr)
82 return NULL;
83
84 if (message)
85 return g_error_new(domain,
86 code,
87 "%s: %s",
88 message,
89 verr->message);
90 else
91 return g_error_new(domain,
92 code,
93 "%s",
94 message);
95 }
96
97 /**
98 * gvir_error_new_valist: (skip)
99 * @domain: error domain
100 * @code: error code
101 * @format: printf()-style format for error message
102 * @args: #va_list of parameters for the message format
103 *
104 * Creates a new #GError with the given @domain and @code,
105 * and a message formatted with @format.
106 *
107 * Returns: a new #GError
108 */
109 GError *gvir_error_new_valist(GQuark domain,
110 gint code,
111 const gchar *format,
112 va_list args)
113 {
114 GError *err;
115 gchar *message;
116
117 message = g_strdup_vprintf(format, args);
118
119 err = gvir_error_new_literal(domain, code, message);
120
121 g_free(message);
122
123 return err;
124 }
125
0 /*
1 * libvirt-glib-error.h: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #ifndef __LIBVIRT_GLIB_ERROR_H__
24 #define __LIBVIRT_GLIB_ERROR_H__
25
26 #include <glib.h>
27
28 G_BEGIN_DECLS
29
30 GError *gvir_error_new(GQuark domain,
31 gint code,
32 const gchar *format,
33 ...);
34
35 GError *gvir_error_new_literal(GQuark domain,
36 gint code,
37 const gchar *message);
38
39 GError *gvir_error_new_valist(GQuark domain,
40 gint code,
41 const gchar *format,
42 va_list args);
43
44 G_END_DECLS
45
46 #endif /* __LIBVIRT_GLIB_ERROR_H__ */
0 /*
1 * libvirt-glib-event.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #include <libvirt/libvirt.h>
30
31 #include "libvirt-glib/libvirt-glib.h"
32
33 extern gboolean debugFlag;
34
35 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
36
37 struct gvir_event_handle
38 {
39 int watch;
40 int fd;
41 int events;
42 int enabled;
43 GIOChannel *channel;
44 guint source;
45 virEventHandleCallback cb;
46 void *opaque;
47 virFreeCallback ff;
48 };
49
50 struct gvir_event_timeout
51 {
52 int timer;
53 int interval;
54 guint source;
55 virEventTimeoutCallback cb;
56 void *opaque;
57 virFreeCallback ff;
58 };
59
60 GMutex *eventlock = NULL;
61
62 static int nextwatch = 1;
63 static unsigned int nhandles = 0;
64 static struct gvir_event_handle **handles = NULL;
65
66 static int nexttimer = 1;
67 static unsigned int ntimeouts = 0;
68 static struct gvir_event_timeout **timeouts = NULL;
69
70 static gboolean
71 gvir_event_handle_dispatch(GIOChannel *source G_GNUC_UNUSED,
72 GIOCondition condition,
73 gpointer opaque)
74 {
75 struct gvir_event_handle *data = opaque;
76 int events = 0;
77
78 if (condition & G_IO_IN)
79 events |= VIR_EVENT_HANDLE_READABLE;
80 if (condition & G_IO_OUT)
81 events |= VIR_EVENT_HANDLE_WRITABLE;
82 if (condition & G_IO_HUP)
83 events |= VIR_EVENT_HANDLE_HANGUP;
84 if (condition & G_IO_ERR)
85 events |= VIR_EVENT_HANDLE_ERROR;
86
87 DEBUG("Dispatch handler %d %d %p\n", data->fd, events, data->opaque);
88
89 (data->cb)(data->watch, data->fd, events, data->opaque);
90
91 return TRUE;
92 }
93
94
95 static int
96 gvir_event_handle_add(int fd,
97 int events,
98 virEventHandleCallback cb,
99 void *opaque,
100 virFreeCallback ff)
101 {
102 struct gvir_event_handle *data;
103 GIOCondition cond = 0;
104 int ret;
105
106 g_mutex_lock(eventlock);
107
108 handles = g_realloc(handles, sizeof(*handles)*(nhandles+1));
109 data = g_malloc(sizeof(*data));
110 memset(data, 0, sizeof(*data));
111
112 if (events & VIR_EVENT_HANDLE_READABLE)
113 cond |= G_IO_IN;
114 if (events & VIR_EVENT_HANDLE_WRITABLE)
115 cond |= G_IO_OUT;
116
117 data->watch = nextwatch++;
118 data->fd = fd;
119 data->events = events;
120 data->cb = cb;
121 data->opaque = opaque;
122 data->channel = g_io_channel_unix_new(fd);
123 data->ff = ff;
124
125 DEBUG("Add handle %d %d %p\n", data->fd, events, data->opaque);
126
127 data->source = g_io_add_watch(data->channel,
128 cond,
129 gvir_event_handle_dispatch,
130 data);
131
132 handles[nhandles++] = data;
133
134 ret = data->watch;
135
136 g_mutex_unlock(eventlock);
137
138 return ret;
139 }
140
141 static struct gvir_event_handle *
142 gvir_event_handle_find(int watch)
143 {
144 unsigned int i;
145 for (i = 0 ; i < nhandles ; i++)
146 if (handles[i]->watch == watch)
147 return handles[i];
148
149 return NULL;
150 }
151
152 static void
153 gvir_event_handle_update(int watch,
154 int events)
155 {
156 struct gvir_event_handle *data;
157
158 g_mutex_lock(eventlock);
159
160 data = gvir_event_handle_find(watch);
161 if (!data) {
162 DEBUG("Update for missing handle watch %d", watch);
163 goto cleanup;
164 }
165
166 if (events) {
167 GIOCondition cond = 0;
168 if (events == data->events)
169 goto cleanup;
170
171 if (data->source)
172 g_source_remove(data->source);
173
174 cond |= G_IO_HUP;
175 if (events & VIR_EVENT_HANDLE_READABLE)
176 cond |= G_IO_IN;
177 if (events & VIR_EVENT_HANDLE_WRITABLE)
178 cond |= G_IO_OUT;
179 data->source = g_io_add_watch(data->channel,
180 cond,
181 gvir_event_handle_dispatch,
182 data);
183 data->events = events;
184 } else {
185 if (!data->source)
186 goto cleanup;
187
188 g_source_remove(data->source);
189 data->source = 0;
190 data->events = 0;
191 }
192
193 cleanup:
194 g_mutex_unlock(eventlock);
195 }
196
197 static int
198 gvir_event_handle_remove(int watch)
199 {
200 struct gvir_event_handle *data;
201 int ret = -1;
202
203 g_mutex_lock(eventlock);
204
205 data = gvir_event_handle_find(watch);
206 if (!data) {
207 DEBUG("Remove of missing watch %d", watch);
208 goto cleanup;
209 }
210
211 DEBUG("Remove handle %d %d\n", watch, data->fd);
212
213 if (!data->source)
214 goto cleanup;
215
216 g_source_remove(data->source);
217 data->source = 0;
218 data->events = 0;
219 if (data->ff)
220 (data->ff)(data->opaque);
221 free(data);
222
223 ret = 0;
224
225 cleanup:
226 g_mutex_unlock(eventlock);
227 return ret;
228 }
229
230
231 static gboolean
232 gvir_event_timeout_dispatch(void *opaque)
233 {
234 struct gvir_event_timeout *data = opaque;
235 DEBUG("Dispatch timeout %p %p %d %p\n", data, data->cb, data->timer, data->opaque);
236 (data->cb)(data->timer, data->opaque);
237
238 return TRUE;
239 }
240
241 static int
242 gvir_event_timeout_add(int interval,
243 virEventTimeoutCallback cb,
244 void *opaque,
245 virFreeCallback ff)
246 {
247 struct gvir_event_timeout *data;
248 int ret;
249
250 g_mutex_lock(eventlock);
251
252 timeouts = g_realloc(timeouts, sizeof(*timeouts)*(ntimeouts+1));
253 data = g_malloc(sizeof(*data));
254 memset(data, 0, sizeof(*data));
255
256 data->timer = nexttimer++;
257 data->interval = interval;
258 data->cb = cb;
259 data->opaque = opaque;
260 data->ff = ff;
261 if (interval >= 0)
262 data->source = g_timeout_add(interval,
263 gvir_event_timeout_dispatch,
264 data);
265
266 timeouts[ntimeouts++] = data;
267
268 DEBUG("Add timeout %p %d %p %p %d\n", data, interval, cb, opaque, data->timer);
269
270 ret = data->timer;
271
272 g_mutex_unlock(eventlock);
273
274 return ret;
275 }
276
277
278 static struct gvir_event_timeout *
279 gvir_event_timeout_find(int timer)
280 {
281 unsigned int i;
282 for (i = 0 ; i < ntimeouts ; i++)
283 if (timeouts[i]->timer == timer)
284 return timeouts[i];
285
286 return NULL;
287 }
288
289
290 static void
291 gvir_event_timeout_update(int timer,
292 int interval)
293 {
294 struct gvir_event_timeout *data;
295
296 g_mutex_lock(eventlock);
297
298 data = gvir_event_timeout_find(timer);
299 if (!data) {
300 DEBUG("Update of missing timer %d", timer);
301 goto cleanup;
302 }
303
304 DEBUG("Update timeout %p %d %d\n", data, timer, interval);
305
306 if (interval >= 0) {
307 if (data->source)
308 goto cleanup;
309
310 data->interval = interval;
311 data->source = g_timeout_add(data->interval,
312 gvir_event_timeout_dispatch,
313 data);
314 } else {
315 if (!data->source)
316 goto cleanup;
317
318 g_source_remove(data->source);
319 data->source = 0;
320 }
321
322 cleanup:
323 g_mutex_unlock(eventlock);
324 }
325
326 static int
327 gvir_event_timeout_remove(int timer)
328 {
329 struct gvir_event_timeout *data;
330 int ret = -1;
331
332 g_mutex_lock(eventlock);
333
334 data = gvir_event_timeout_find(timer);
335 if (!data) {
336 DEBUG("Remove of missing timer %d", timer);
337 goto cleanup;
338 }
339
340 DEBUG("Remove timeout %p %d\n", data, timer);
341
342 if (!data->source)
343 goto cleanup;
344
345 g_source_remove(data->source);
346 data->source = 0;
347
348 if (data->ff)
349 (data->ff)(data->opaque);
350
351 free(data);
352
353 ret = 0;
354
355 cleanup:
356 g_mutex_unlock(eventlock);
357 return ret;
358 }
359
360
361 void gvir_event_register(void) {
362 eventlock = g_mutex_new();
363 virEventRegisterImpl(gvir_event_handle_add,
364 gvir_event_handle_update,
365 gvir_event_handle_remove,
366 gvir_event_timeout_add,
367 gvir_event_timeout_update,
368 gvir_event_timeout_remove);
369 }
370
0 /*
1 * libvirt-glib-event.h: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #ifndef __LIBVIRT_GLIB_EVENT_H__
24 #define __LIBVIRT_GLIB_EVENT_H__
25
26 #include <glib.h>
27
28 G_BEGIN_DECLS
29
30 void gvir_event_register(void);
31
32 G_END_DECLS
33
34 #endif /* __LIBVIRT_GLIB_EVENT_H__ */
0 /*
1 * libvirt-glib-main.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <stdlib.h>
26 #include <libvirt/virterror.h>
27
28 #include "libvirt-glib-main.h"
29
30 gboolean debugFlag = FALSE;
31
32 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
33
34 static void
35 gvir_error_func(gpointer opaque G_GNUC_UNUSED,
36 virErrorPtr err)
37 {
38 DEBUG("Error: %s", err->message);
39 }
40
41
42 void gvir_init(int *argc,
43 char ***argv)
44 {
45 GError *err = NULL;
46 if (!gvir_init_check(argc, argv, &err)) {
47 g_error("Could not initialize libvirt-glib: %s\n",
48 err->message);
49 }
50 }
51
52
53 gboolean gvir_init_check(int *argc G_GNUC_UNUSED,
54 char ***argv G_GNUC_UNUSED,
55 GError **err G_GNUC_UNUSED)
56 {
57 char *debugEnv = getenv("LIBVIRT_GLIB_DEBUG");
58 if (debugEnv && *debugEnv && *debugEnv != '0')
59 debugFlag = 1;
60
61 virSetErrorFunc(NULL, gvir_error_func);
62 if (!g_thread_supported())
63 g_thread_init(NULL);
64
65 return TRUE;
66 }
67
0 /*
1 * libvirt-glib-main.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #if !defined(__LIBVIRT_GLIB_H__) && !defined(LIBVIRT_GLIB_BUILD)
24 #error "Only <libvirt-glib/libvirt-glib.h> can be included directly."
25 #endif
26
27 #ifndef __LIBVIRT_GLIB_MAIN_H__
28 #define __LIBVIRT_GLIB_MAIN_H__
29
30 #include <glib.h>
31
32 G_BEGIN_DECLS
33
34 void gvir_init(int *argc,
35 char ***argv);
36 gboolean gvir_init_check(int *argc,
37 char ***argv,
38 GError **err);
39
40 G_END_DECLS
41
42 #endif /* __LIBVIRT_GLIB_MAIN_H__ */
0 /*
1 * libvirt-glib.h: libvirt glib integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #ifndef __LIBVIRT_GLIB_H__
23 #define __LIBVIRT_GLIB_H__
24
25 #include <libvirt-glib/libvirt-glib-main.h>
26 #include <libvirt-glib/libvirt-glib-event.h>
27 #include <libvirt-glib/libvirt-glib-error.h>
28
29 #endif /* __LIBVIRT_GLIB_H__ */
0 LIBVIRT_GLIB_0.0.1 {
1 global:
2 gvir_init;
3 gvir_init_check;
4 gvir_event_register;
5
6 gvir_error_new;
7 gvir_error_new_valist;
8 gvir_error_new_literal;
9
10 local:
11 *;
12 };
13
14 # .... define new API here using predicted next version number ....
0 prefix=@prefix@
1 exec_prefix=@exec_prefix@
2 libdir=@libdir@
3 includedir=@includedir@
4
5 Name: libvirt-glib
6 Version: @VERSION@
7 Description: libvirt glib library
8 Requires: glib-2.0
9 Libs: -L${libdir} -lvirt-glib-1.0
10 Libs.private: @LIBVIRT_LIBS @GLIB2_LIBS@
11 Cflags: -I${includedir}/libvirt-glib-1.0 @LIBVIRT_CFLAGS@ @GLIB2_CFLAGS@
+0
-12
libvirt-glib.pc.in less more
0 prefix=@prefix@
1 exec_prefix=@exec_prefix@
2 libdir=@libdir@
3 includedir=@includedir@
4
5 Name: libvirt
6 Version: @VERSION@
7 Description: libvirt library
8 Requires:
9 Libs: -L${libdir} -lvirt-glib
10 Libs.private: @LIBVIRT_LIBS @GLIB2_LIBS@
11 Cflags: -I${includedir} @LIBVIRT_CFLAGS@ @GLIB2_CFLAGS@
00 # -*- rpm-spec -*-
1
2 %define with_introspection 0
3 %define with_python 0
4
5 %if 0%{?fedora} >= 15
6 %define with_introspection 1
7 %endif
8 %if 0%{?fedora} < 15
9 %define with_python 1
10 %endif
11 %if 0%{?rhel} >= 6
12 %define with_introspection 1
13 %endif
14 %if 0%{?rhel} < 7
15 %define with_python 1
16 %endif
17
118
219 Name: @PACKAGE@
320 Version: @VERSION@
1229 BuildRequires: glib2-devel >= 2.10.0
1330 BuildRequires: libvirt-devel >= 0.5.0
1431 BuildRequires: python-devel
32 %if %{with_introspection}
33 BuildRequires: gobject-introspection-devel
34 %if 0%{?fedora} == 12
35 BuildRequires: gir-repository-devel
36 %endif
37 BuildRequires: gjs-devel
38 %endif
1539
1640 %package devel
1741 Group: Development/Libraries
1842 Summary: libvirt glib integration for events development files
19
43 Requires: %{name} = %{version}-%{release}
44
45 %package -n libvirt-gconfig
46 Group: Development/Libraries
47 Summary: libvirt object APIs for processing object configuration
48
49 %package -n libvirt-gobject
50 Group: Development/Libraries
51 Summary: libvirt object APIs for managing virtualization hosts
52
53 %package -n libvirt-gconfig-devel
54 Group: Development/Libraries
55 Summary: libvirt object APIs for processing object configuration development files
56 Requires: libvirt-gconfig = %{version}-%{release}
57
58 %package -n libvirt-gobject-devel
59 Group: Development/Libraries
60 Summary: libvirt object APIs for managing virtualization hosts development files
61 Requires: %{name}-devel = %{version}-%{release}
62 Requires: libvirt-gconfig-devel = %{version}-%{release}
63 Requires: libvirt-gobject = %{version}-%{release}
64
65 %if %{with_python}
2066 %package python
2167 Group: Development/Libraries
2268 Summary: libvirt glib integration for events python binding
69 %endif
2370
2471 %description
2572 This package provides integration between libvirt and the glib
2976 This package provides development header files and libraries for
3077 integration between libvirt and the glib event loop.
3178
79 %description -n libvirt-gconfig
80 This package provides APIs for processing the object configuration
81 data
82
83 %description -n libvirt-gconfig-devel
84 This package provides development header files and libraries for
85 the object configuration APIs.
86
87 %description -n libvirt-gobject
88 This package provides APIs for managing virtualization host
89 objects
90
91 %description -n libvirt-gobject-devel
92 This package provides development header files and libraries for
93 managing virtualization host objects
94
95 %if %{with_python}
3296 %description python
3397 This package provides a python module for integration between
3498 libvirt and the glib event loop
99 %endif
35100
36101 %prep
37102 %setup -q
38103
39104 %build
40 %configure
105
106 %if %{with_introspection}
107 %define introspection_arg --enable-introspection
108 %else
109 %define introspection_arg --disable-introspection
110 %endif
111 %if %{with_python}
112 %define python_arg --with-python
113 %else
114 %define python_arg --without-python
115 %endif
116
117 %configure %{introspection_arg} %{python_arg}
41118 %__make %{?_smp_mflags}
42119
43120
44121 %install
45122 rm -rf $RPM_BUILD_ROOT
46123 %__make install DESTDIR=$RPM_BUILD_ROOT
47 rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}.a
48 rm -f $RPM_BUILD_ROOT%{_libdir}/%{name}.la
124 rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-glib-1.0.a
125 rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-glib-1.0.la
126 rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-gconfig-1.0.a
127 rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-gconfig-1.0.la
128 rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-gobject-1.0.a
129 rm -f $RPM_BUILD_ROOT%{_libdir}/libvirt-gobject-1.0.la
49130
50131 %clean
51132 rm -rf $RPM_BUILD_ROOT
53134 %files
54135 %defattr(-,root,root,-)
55136 %doc README COPYING AUTHORS ChangeLog NEWS
56 %{_libdir}/%{name}.so.*
137 %{_libdir}/libvirt-glib-1.0.so.*
138 %if %{with_introspection}
139 %{_libdir}/girepository-1.0/LibvirtGLib-1.0.typelib
140 %endif
141
142 %files -n libvirt-gconfig
143 %{_libdir}/libvirt-gconfig-1.0.so.*
144 %if %{with_introspection}
145 %{_libdir}/girepository-1.0/LibvirtGConfig-1.0.typelib
146 %endif
147
148 %files -n libvirt-gobject
149 %{_libdir}/libvirt-gobject-1.0.so.*
150 %if %{with_introspection}
151 %{_libdir}/girepository-1.0/LibvirtGObject-1.0.typelib
152 %endif
57153
58154 %files devel
59155 %defattr(-,root,root,-)
60156 %doc examples/event-test.c
61 %{_libdir}/%{name}.so
62 %{_libdir}/pkgconfig/%{name}.pc
63 %{_includedir}/%{name}/%{name}.h
64
157 %{_libdir}/libvirt-glib-1.0.so
158 %{_libdir}/pkgconfig/libvirt-glib-1.0.pc
159 %dir %{_includedir}/libvirt-glib-1.0
160 %dir %{_includedir}/libvirt-glib-1.0/libvirt-glib
161 %{_includedir}/libvirt-glib-1.0/libvirt-glib/libvirt-glib.h
162 %{_includedir}/libvirt-glib-1.0/libvirt-glib/libvirt-glib-*.h
163 %if %{with_introspection}
164 %{_datadir}/gir-1.0/LibvirtGLib-1.0.gir
165 %endif
166
167 %files -n libvirt-gconfig-devel
168 %defattr(-,root,root,-)
169 %doc examples/event-test.c
170 %{_libdir}/libvirt-gconfig-1.0.so
171 %{_libdir}/pkgconfig/libvirt-gconfig-1.0.pc
172 %dir %{_includedir}/libvirt-gconfig-1.0
173 %dir %{_includedir}/libvirt-gconfig-1.0/libvirt-gconfig
174 %{_includedir}/libvirt-gconfig-1.0/libvirt-gconfig/libvirt-gconfig.h
175 %{_includedir}/libvirt-gconfig-1.0/libvirt-gconfig/libvirt-gconfig-*.h
176 %if %{with_introspection}
177 %{_datadir}/gir-1.0/LibvirtGConfig-1.0.gir
178 %endif
179
180 %files -n libvirt-gobject-devel
181 %defattr(-,root,root,-)
182 %doc examples/event-test.c
183 %{_libdir}/libvirt-gobject-1.0.so
184 %{_libdir}/pkgconfig/libvirt-gobject-1.0.pc
185 %dir %{_includedir}/libvirt-gobject-1.0
186 %dir %{_includedir}/libvirt-gobject-1.0/libvirt-gobject
187 %{_includedir}/libvirt-gobject-1.0/libvirt-gobject/libvirt-gobject.h
188 %{_includedir}/libvirt-gobject-1.0/libvirt-gobject/libvirt-gobject-*.h
189 %if %{with_introspection}
190 %{_datadir}/gir-1.0/LibvirtGObject-1.0.gir
191 %endif
192
193 %if %{with_python}
65194 %files python
66195 %defattr(-,root,root,-)
67196 %doc examples/event-test.py
68197 %{_libdir}/python*/site-packages/libvirtglib.py*
69198 %{_libdir}/python*/site-packages/libvirtglibmod*
199 %endif
70200
71201 %changelog
72202 * Sun Oct 19 2008 Daniel P. Berrange <berrange@redhat.com> - 0.0.1-1
0
1 EXTRA_DIST = libvirt-gobject.sym
2
3 lib_LTLIBRARIES = libvirt-gobject-1.0.la
4
5 GOBJECT_HEADER_FILES = \
6 libvirt-gobject.h \
7 libvirt-gobject-main.h \
8 libvirt-gobject-domain-snapshot.h \
9 libvirt-gobject-domain.h \
10 libvirt-gobject-interface.h \
11 libvirt-gobject-network.h \
12 libvirt-gobject-network-filter.h \
13 libvirt-gobject-node-device.h \
14 libvirt-gobject-secret.h \
15 libvirt-gobject-storage-vol.h \
16 libvirt-gobject-storage-pool.h \
17 libvirt-gobject-stream.h \
18 libvirt-gobject-connection.h \
19 libvirt-gobject-manager.h
20 GOBJECT_SOURCE_FILES = \
21 libvirt-gobject-main.c \
22 libvirt-gobject-domain-snapshot.c \
23 libvirt-gobject-domain.c \
24 libvirt-gobject-interface.c \
25 libvirt-gobject-network.c \
26 libvirt-gobject-network-filter.c \
27 libvirt-gobject-node-device.c \
28 libvirt-gobject-secret.c \
29 libvirt-gobject-storage-vol.c \
30 libvirt-gobject-storage-pool.c \
31 libvirt-gobject-stream.c \
32 libvirt-gobject-connection.c \
33 libvirt-gobject-manager.c
34
35 libvirt_gobject_1_0_ladir = $(includedir)/libvirt-gobject-1.0/libvirt-gobject
36 libvirt_gobject_1_0_la_HEADERS = \
37 libvirt-gobject-enums.h \
38 $(GOBJECT_HEADER_FILES)
39 libvirt_gobject_1_0_la_SOURCES = \
40 $(libvirt_gobject_1_0_la_HEADERS) \
41 libvirt-gobject-enums.c \
42 $(GOBJECT_SOURCE_FILES)
43 libvirt_gobject_1_0_la_CFLAGS = \
44 -DDATADIR="\"$(datadir)\"" \
45 -DLIBVIRT_GOBJECT_BUILD \
46 $(COVERAGE_CFLAGS) \
47 -I$(top_srcdir) \
48 $(LIBVIRT_CFLAGS) \
49 $(GOBJECT2_CFLAGS) \
50 $(GIO2_CFLAGS) \
51 $(WARN_CFLAGS)
52 libvirt_gobject_1_0_la_LIBADD = \
53 $(LIBVIRT_LIBS) \
54 $(GOBJECT2_LIBS) \
55 $(GIO2_LIBS) \
56 ../libvirt-glib/libvirt-glib-1.0.la \
57 ../libvirt-gconfig/libvirt-gconfig-1.0.la \
58 $(CYGWIN_EXTRA_LIBADD)
59 libvirt_gobject_1_0_la_DEPENDENCIES = \
60 libvirt-gobject.sym \
61 ../libvirt-glib/libvirt-glib-1.0.la \
62 ../libvirt-gconfig/libvirt-gconfig-1.0.la
63 libvirt_gobject_1_0_la_LDFLAGS = \
64 $(COVERAGE_CFLAGS:-f%=-Wc,f%) \
65 $(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS) \
66 -Wl,--version-script=$(srcdir)/libvirt-gobject.sym \
67 -version-info $(LIBVIRT_GLIB_VERSION_INFO)
68
69 libvirt-gobject-enums.c: libvirt-gobject-domain.h libvirt-gobject-connection.h
70 $(AM_V_GEN)glib-mkenums \
71 --fhead "#include \"libvirt-gobject/libvirt-gobject.h\"\n\n" \
72 --vhead "static const G@Type@Value _@enum_name@_values[] = {" \
73 --vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
74 --vtail " { 0, NULL, NULL }\n};\n\n" \
75 --vtail "GType\n@enum_name@_get_type (void)\n{\n" \
76 --vtail " static GType type = 0;\n\n" \
77 --vtail " if (!type)\n" \
78 --vtail " type = g_@type@_register_static (\"@EnumName@\", _@enum_name@_values);\n\n" \
79 --vtail " return type;\n}\n\n" \
80 $^ | sed -e 's/g_vir/gvir/g' > $@
81
82 libvirt-gobject-enums.h: libvirt-gobject-domain.h libvirt-gobject-connection.h
83 $(AM_V_GEN)glib-mkenums --fhead "#ifndef __LIBVIRT_GOBJECT_ENUMS_H__\n" \
84 --fhead "#define __LIBVIRT_GOBJECT_ENUMS_H__\n\n" \
85 --fhead "G_BEGIN_DECLS\n\n" \
86 --ftail "G_END_DECLS\n\n" \
87 --ftail "#endif /* __LIBVIRT_GOBJECT_ENUMS_H__ */\n" \
88 --eprod "#define GVIR_TYPE_@ENUMSHORT@ @enum_name@_get_type()\n" \
89 --eprod "GType @enum_name@_get_type (void);\n" \
90 $^ | sed -e 's/g_vir/gvir/g' > $@
91
92 BUILT_SOURCES = libvirt-gobject-enums.c libvirt-gobject-enums.h
93
94 CLEANFILES = $(BUILT_SOURCES)
95
96 if WITH_GOBJECT_INTROSPECTION
97
98 LibvirtGObject-1.0.gir: libvirt-gobject-1.0.la $(G_IR_SCANNER) Makefile.am
99 $(AM_V_GEN)$(G_IR_SCANNER) \
100 --quiet \
101 --warn-all \
102 --namespace LibvirtGObject \
103 --nsversion 1.0 \
104 --include GObject-2.0 \
105 --include Gio-2.0 \
106 --include LibvirtGLib-1.0 \
107 --include LibvirtGConfig-1.0 \
108 --identifier-prefix=GVir \
109 --symbol-prefix=gvir \
110 --library=$(builddir)/libvirt-gobject-1.0.la \
111 --add-include-path=$(top_builddir)/libvirt-glib \
112 --add-include-path=$(top_builddir)/libvirt-gconfig \
113 --output $@ \
114 -I$(top_srcdir) \
115 -I$(top_builddir) \
116 --verbose \
117 --pkg=gobject-2.0 \
118 --pkg=gthread-2.0 \
119 $(srcdir)/libvirt-gobject.h \
120 $(GOBJECT_SOURCE_FILES:%=$(srcdir)/%) \
121 $(GOBJECT_HEADER_FILES:%=$(srcdir)/%) \
122 $(builddir)/libvirt-gobject-enums.c
123
124 girdir = $(datadir)/gir-1.0
125 gir_DATA = LibvirtGObject-1.0.gir
126
127 typelibsdir = $(libdir)/girepository-1.0
128 typelibs_DATA = LibvirtGObject-1.0.typelib
129
130 %.typelib: %.gir
131 $(AM_V_GEN)$(G_IR_COMPILER) \
132 --includedir=$(top_builddir)/libvirt-glib \
133 --includedir=$(top_builddir)/libvirt-gconfig \
134 --includedir=$(builddir) \
135 --includedir=$(girdir) \
136 -o $@ $<
137
138 CLEANFILES += $(gir_DATA) $(typelibs_DATA)
139
140 endif # WITH_GOBJECT_INTROSPECTION
0 /*
1 * libvirt-gobject-connection.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/libvirt.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_CONNECTION_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONNECTION, GVirConnectionPrivate))
37
38 struct _GVirConnectionPrivate
39 {
40 GMutex *lock;
41 gchar *uri;
42 virConnectPtr conn;
43
44 GHashTable *domains;
45 GHashTable *pools;
46 };
47
48 G_DEFINE_TYPE(GVirConnection, gvir_connection, G_TYPE_OBJECT);
49
50
51 enum {
52 PROP_0,
53 PROP_URI,
54 PROP_HANDLE,
55 };
56
57
58 #define GVIR_CONNECTION_ERROR gvir_connection_error_quark()
59
60 static GQuark
61 gvir_connection_error_quark(void)
62 {
63 return g_quark_from_static_string("gvir-connection");
64 }
65
66 static void gvir_connection_get_property(GObject *object,
67 guint prop_id,
68 GValue *value,
69 GParamSpec *pspec)
70 {
71 GVirConnection *conn = GVIR_CONNECTION(object);
72 GVirConnectionPrivate *priv = conn->priv;
73
74 switch (prop_id) {
75 case PROP_URI:
76 g_value_set_string(value, priv->uri);
77 break;
78 case PROP_HANDLE:
79 g_value_set_boxed(value, priv->conn);
80 break;
81
82 default:
83 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
84 }
85 }
86
87
88 static void gvir_connection_set_property(GObject *object,
89 guint prop_id,
90 const GValue *value,
91 GParamSpec *pspec)
92 {
93 GVirConnection *conn = GVIR_CONNECTION(object);
94 GVirConnectionPrivate *priv = conn->priv;
95
96 switch (prop_id) {
97 case PROP_URI:
98 g_free(priv->uri);
99 priv->uri = g_value_dup_string(value);
100 break;
101
102 case PROP_HANDLE:
103 if (priv->conn)
104 virConnectClose(priv->conn);
105 priv->conn = g_value_dup_boxed(value);
106 break;
107
108 default:
109 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
110 }
111 }
112
113
114 static void gvir_connection_finalize(GObject *object)
115 {
116 GVirConnection *conn = GVIR_CONNECTION(object);
117 GVirConnectionPrivate *priv = conn->priv;
118
119 DEBUG("Finalize GVirConnection=%p", conn);
120
121 if (gvir_connection_is_open(conn))
122 gvir_connection_close(conn);
123
124 g_mutex_free(priv->lock);
125 g_free(priv->uri);
126
127 G_OBJECT_CLASS(gvir_connection_parent_class)->finalize(object);
128 }
129
130
131 static GVirStream* gvir_connection_stream_new(GVirConnection *self G_GNUC_UNUSED,
132 gpointer handle)
133 {
134 return g_object_new(GVIR_TYPE_STREAM, "handle", handle, NULL);
135 }
136
137 static void gvir_connection_class_init(GVirConnectionClass *klass)
138 {
139 GObjectClass *object_class = G_OBJECT_CLASS (klass);
140
141 object_class->finalize = gvir_connection_finalize;
142 object_class->get_property = gvir_connection_get_property;
143 object_class->set_property = gvir_connection_set_property;
144
145 klass->stream_new = gvir_connection_stream_new;
146
147 g_object_class_install_property(object_class,
148 PROP_URI,
149 g_param_spec_string("uri",
150 "URI",
151 "The connection URI",
152 NULL,
153 G_PARAM_READABLE |
154 G_PARAM_WRITABLE |
155 G_PARAM_CONSTRUCT_ONLY |
156 G_PARAM_STATIC_NAME |
157 G_PARAM_STATIC_NICK |
158 G_PARAM_STATIC_BLURB));
159
160 g_signal_new("vir-connection-opened",
161 G_OBJECT_CLASS_TYPE(object_class),
162 G_SIGNAL_RUN_FIRST,
163 G_STRUCT_OFFSET(GVirConnectionClass, vir_connection_opened),
164 NULL, NULL,
165 g_cclosure_marshal_VOID__VOID,
166 G_TYPE_NONE,
167 0);
168 g_signal_new("vir-connection-closed",
169 G_OBJECT_CLASS_TYPE(object_class),
170 G_SIGNAL_RUN_FIRST,
171 G_STRUCT_OFFSET(GVirConnectionClass, vir_connection_closed),
172 NULL, NULL,
173 g_cclosure_marshal_VOID__VOID,
174 G_TYPE_NONE,
175 0);
176
177 g_signal_new("vir-domain-added",
178 G_OBJECT_CLASS_TYPE(object_class),
179 G_SIGNAL_RUN_FIRST,
180 G_STRUCT_OFFSET(GVirConnectionClass, vir_domain_added),
181 NULL, NULL,
182 g_cclosure_marshal_VOID__VOID,
183 G_TYPE_NONE,
184 0);
185 g_signal_new("vir-domain-removed",
186 G_OBJECT_CLASS_TYPE(object_class),
187 G_SIGNAL_RUN_FIRST,
188 G_STRUCT_OFFSET(GVirConnectionClass, vir_domain_removed),
189 NULL, NULL,
190 g_cclosure_marshal_VOID__VOID,
191 G_TYPE_NONE,
192 0);
193
194 g_object_class_install_property(object_class,
195 PROP_HANDLE,
196 g_param_spec_boxed("handle",
197 "Handle",
198 "The connection handle",
199 GVIR_TYPE_CONNECTION_HANDLE,
200 G_PARAM_READABLE |
201 G_PARAM_WRITABLE |
202 G_PARAM_CONSTRUCT_ONLY |
203 G_PARAM_STATIC_NAME |
204 G_PARAM_STATIC_NICK |
205 G_PARAM_STATIC_BLURB));
206
207 g_type_class_add_private(klass, sizeof(GVirConnectionPrivate));
208 }
209
210
211 static void gvir_connection_init(GVirConnection *conn)
212 {
213 GVirConnectionPrivate *priv;
214
215 DEBUG("Init GVirConnection=%p", conn);
216
217 priv = conn->priv = GVIR_CONNECTION_GET_PRIVATE(conn);
218
219 memset(priv, 0, sizeof(*priv));
220
221 priv->lock = g_mutex_new();
222 }
223
224
225 GVirConnection *gvir_connection_new(const char *uri)
226 {
227 return GVIR_CONNECTION(g_object_new(GVIR_TYPE_CONNECTION,
228 "uri", uri,
229 NULL));
230 }
231
232
233 /**
234 * gvir_connection_open:
235 * @conn: the connection
236 * @cancellable: (allow-none)(transfer none): cancellation object
237 */
238 gboolean gvir_connection_open(GVirConnection *conn,
239 GCancellable *cancellable,
240 GError **err)
241 {
242 GVirConnectionPrivate *priv = conn->priv;
243
244 if (g_cancellable_set_error_if_cancelled(cancellable, err))
245 return FALSE;
246
247 g_mutex_lock(priv->lock);
248 if (priv->conn) {
249 *err = g_error_new(GVIR_CONNECTION_ERROR,
250 0,
251 "Connection %s is already open",
252 priv->uri);
253 g_mutex_unlock(priv->lock);
254 return FALSE;
255 }
256
257 if (!(priv->conn = virConnectOpen(priv->uri))) {
258 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
259 0,
260 "Unable to open %s",
261 priv->uri);
262 g_mutex_unlock(priv->lock);
263 return FALSE;
264 }
265
266 g_mutex_unlock(priv->lock);
267
268 g_signal_emit_by_name(conn, "vir-connection-opened");
269 return TRUE;
270 }
271
272
273 static void
274 gvir_connection_open_helper(GSimpleAsyncResult *res,
275 GObject *object,
276 GCancellable *cancellable)
277 {
278 GVirConnection *conn = GVIR_CONNECTION(object);
279 GError *err = NULL;
280
281 if (!gvir_connection_open(conn, cancellable, &err)) {
282 g_simple_async_result_set_from_error(res, err);
283 g_error_free(err);
284 }
285 }
286
287
288 /**
289 * gvir_connection_open_async:
290 * @conn: the connection
291 * @cancellable: (allow-none)(transfer none): cancellation object
292 * @callback: (transfer none): completion callback
293 * @opaque: (transfer none)(allow-none): opaque data for callback
294 */
295 void gvir_connection_open_async(GVirConnection *conn,
296 GCancellable *cancellable,
297 GAsyncReadyCallback callback,
298 gpointer opaque)
299 {
300 GSimpleAsyncResult *res;
301
302 res = g_simple_async_result_new(G_OBJECT(conn),
303 callback,
304 opaque,
305 gvir_connection_open);
306 g_simple_async_result_run_in_thread(res,
307 gvir_connection_open_helper,
308 G_PRIORITY_DEFAULT,
309 cancellable);
310 g_object_unref(res);
311 }
312
313
314 /**
315 * gvir_connection_open_finish:
316 * @conn: the connection
317 * @result: (transfer none): async method result
318 */
319 gboolean gvir_connection_open_finish(GVirConnection *conn,
320 GAsyncResult *result,
321 GError **err)
322 {
323 g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
324 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
325
326 if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
327 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
328 g_warn_if_fail (g_simple_async_result_get_source_tag(simple) == gvir_connection_open);
329 if (g_simple_async_result_propagate_error(simple, err))
330 return FALSE;
331 }
332
333 return TRUE;
334 }
335
336
337 gboolean gvir_connection_is_open(GVirConnection *conn)
338 {
339 GVirConnectionPrivate *priv = conn->priv;
340 gboolean open = TRUE;
341 g_mutex_lock(priv->lock);
342 if (!priv->conn)
343 open = FALSE;
344 g_mutex_unlock(priv->lock);
345 return open;
346 }
347
348 void gvir_connection_close(GVirConnection *conn)
349 {
350 GVirConnectionPrivate *priv = conn->priv;
351 DEBUG("Close GVirConnection=%p", conn);
352
353 g_mutex_lock(priv->lock);
354
355 if (priv->domains) {
356 g_hash_table_unref(priv->domains);
357 priv->domains = NULL;
358 }
359
360 if (priv->pools) {
361 g_hash_table_unref(priv->pools);
362 priv->pools = NULL;
363 }
364
365 if (priv->conn) {
366 virConnectClose(priv->conn);
367 priv->conn = NULL;
368 }
369 /* xxx signals */
370
371 g_mutex_unlock(priv->lock);
372
373 g_signal_emit_by_name(conn, "vir-connection-closed");
374 }
375
376 typedef gint (* CountFunction) (virConnectPtr vconn);
377 typedef gint (* ListFunction) (virConnectPtr vconn, gchar **lst, gint max);
378
379 static gchar ** fetch_list(virConnectPtr vconn,
380 const char *name,
381 CountFunction count_func,
382 ListFunction list_func,
383 GCancellable *cancellable,
384 gint *length,
385 GError **err)
386 {
387 gchar **lst = NULL;
388 gint n = 0;
389 gint i;
390
391 if ((n = count_func(vconn)) < 0) {
392 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
393 0,
394 "Unable to count %s", name);
395 goto error;
396 }
397
398 if (n) {
399 if (g_cancellable_set_error_if_cancelled(cancellable, err))
400 goto error;
401
402 lst = g_new(gchar *, n);
403 if ((n = list_func(vconn, lst, n)) < 0) {
404 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
405 0,
406 "Unable to list %s %d", name, n);
407 goto error;
408 }
409 }
410
411 *length = n;
412 return lst;
413
414 error:
415 for (i = 0 ; i < n; i++)
416 g_free(lst[i]);
417 g_free(lst);
418 return NULL;
419 }
420
421 /**
422 * gvir_connection_fetch_domains:
423 * @conn: the connection
424 * @cancellable: (allow-none)(transfer none): cancellation object
425 */
426 gboolean gvir_connection_fetch_domains(GVirConnection *conn,
427 GCancellable *cancellable,
428 GError **err)
429 {
430 GVirConnectionPrivate *priv = conn->priv;
431 GHashTable *doms;
432 gchar **inactive = NULL;
433 gint ninactive = 0;
434 gint *active = NULL;
435 gint nactive = 0;
436 gboolean ret = FALSE;
437 gint i;
438 virConnectPtr vconn = NULL;
439
440 g_mutex_lock(priv->lock);
441 if (!priv->conn) {
442 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
443 0,
444 "Connection is not open");
445 g_mutex_unlock(priv->lock);
446 goto cleanup;
447 }
448 vconn = priv->conn;
449 /* Stop another thread closing the connection just at the minute */
450 virConnectRef(vconn);
451 g_mutex_unlock(priv->lock);
452
453 if (g_cancellable_set_error_if_cancelled(cancellable, err))
454 goto cleanup;
455
456 if ((nactive = virConnectNumOfDomains(vconn)) < 0) {
457 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
458 0,
459 "Unable to count domains");
460 goto cleanup;
461 }
462 if (nactive) {
463 if (g_cancellable_set_error_if_cancelled(cancellable, err))
464 goto cleanup;
465
466 active = g_new(gint, nactive);
467 if ((nactive = virConnectListDomains(vconn, active, nactive)) < 0) {
468 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
469 0,
470 "Unable to list domains");
471 goto cleanup;
472 }
473 }
474
475 if (g_cancellable_set_error_if_cancelled(cancellable, err))
476 goto cleanup;
477
478 inactive = fetch_list(vconn,
479 "Domains",
480 virConnectNumOfDefinedDomains,
481 virConnectListDefinedDomains,
482 cancellable,
483 &ninactive,
484 err);
485 if (*err != NULL)
486 goto cleanup;
487
488 doms = g_hash_table_new_full(g_str_hash,
489 g_str_equal,
490 g_free,
491 g_object_unref);
492
493 for (i = 0 ; i < nactive ; i++) {
494 if (g_cancellable_set_error_if_cancelled(cancellable, err))
495 goto cleanup;
496
497 virDomainPtr vdom = virDomainLookupByID(vconn, active[i]);
498 GVirDomain *dom;
499 if (!vdom)
500 continue;
501
502 dom = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN,
503 "handle", vdom,
504 NULL));
505
506 g_hash_table_insert(doms,
507 g_strdup(gvir_domain_get_uuid(dom)),
508 dom);
509 }
510
511 for (i = 0 ; i < ninactive ; i++) {
512 if (g_cancellable_set_error_if_cancelled(cancellable, err))
513 goto cleanup;
514
515 virDomainPtr vdom = virDomainLookupByName(vconn, inactive[i]);
516 GVirDomain *dom;
517 if (!vdom)
518 continue;
519
520 dom = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN,
521 "handle", vdom,
522 NULL));
523
524 g_hash_table_insert(doms,
525 g_strdup(gvir_domain_get_uuid(dom)),
526 dom);
527 }
528
529 g_mutex_lock(priv->lock);
530 if (priv->domains)
531 g_hash_table_unref(priv->domains);
532 priv->domains = doms;
533 virConnectClose(vconn);
534 g_mutex_unlock(priv->lock);
535
536 ret = TRUE;
537
538 cleanup:
539 g_free(active);
540 for (i = 0 ; i < ninactive ; i++)
541 g_free(inactive[i]);
542 g_free(inactive);
543 return ret;
544 }
545
546 /**
547 * gvir_connection_fetch_storage_pools:
548 * @conn: the connection
549 * @cancellable: (allow-none)(transfer none): cancellation object
550 */
551 gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn,
552 GCancellable *cancellable,
553 GError **err)
554 {
555 GVirConnectionPrivate *priv = conn->priv;
556 GHashTable *pools;
557 gchar **inactive = NULL;
558 gint ninactive = 0;
559 gchar **active = NULL;
560 gint nactive = 0;
561 gboolean ret = FALSE;
562 gint i;
563 virConnectPtr vconn = NULL;
564
565 g_mutex_lock(priv->lock);
566 if (!priv->conn) {
567 *err = gvir_error_new(GVIR_CONNECTION_ERROR,
568 0,
569 "Connection is not open");
570 g_mutex_unlock(priv->lock);
571 goto cleanup;
572 }
573 vconn = priv->conn;
574 /* Stop another thread closing the connection just at the minute */
575 virConnectRef(vconn);
576 g_mutex_unlock(priv->lock);
577
578 if (g_cancellable_set_error_if_cancelled(cancellable, err))
579 goto cleanup;
580
581 active = fetch_list(vconn,
582 "Storage Pools",
583 virConnectNumOfStoragePools,
584 virConnectListStoragePools,
585 cancellable,
586 &nactive,
587 err);
588 if (*err != NULL)
589 goto cleanup;
590
591 if (g_cancellable_set_error_if_cancelled(cancellable, err))
592 goto cleanup;
593
594 inactive = fetch_list(vconn,
595 "Storage Pools",
596 virConnectNumOfDefinedStoragePools,
597 virConnectListDefinedStoragePools,
598 cancellable,
599 &ninactive,
600 err);
601 if (*err != NULL)
602 goto cleanup;
603
604 pools = g_hash_table_new_full(g_str_hash,
605 g_str_equal,
606 g_free,
607 g_object_unref);
608
609 for (i = 0 ; i < nactive ; i++) {
610 if (g_cancellable_set_error_if_cancelled(cancellable, err))
611 goto cleanup;
612
613 virStoragePoolPtr vpool;
614 GVirStoragePool *pool;
615
616 vpool = virStoragePoolLookupByName(vconn, active[i]);
617 if (!vpool)
618 continue;
619
620 pool = GVIR_STORAGE_POOL(g_object_new(GVIR_TYPE_STORAGE_POOL,
621 "handle", vpool,
622 NULL));
623
624 g_hash_table_insert(pools,
625 g_strdup(gvir_storage_pool_get_uuid(pool)),
626 pool);
627 }
628
629 for (i = 0 ; i < ninactive ; i++) {
630 if (g_cancellable_set_error_if_cancelled(cancellable, err))
631 goto cleanup;
632
633 virStoragePoolPtr vpool;
634 GVirStoragePool *pool;
635
636 vpool = virStoragePoolLookupByName(vconn, inactive[i]);
637 if (!vpool)
638 continue;
639
640 pool = GVIR_STORAGE_POOL(g_object_new(GVIR_TYPE_STORAGE_POOL,
641 "handle", vpool,
642 NULL));
643
644 g_hash_table_insert(pools,
645 g_strdup(gvir_storage_pool_get_uuid(pool)),
646 pool);
647 }
648
649 g_mutex_lock(priv->lock);
650 if (priv->pools)
651 g_hash_table_unref(priv->pools);
652 priv->pools = pools;
653 virConnectClose(vconn);
654 g_mutex_unlock(priv->lock);
655
656 ret = TRUE;
657
658 cleanup:
659 for (i = 0 ; i < nactive ; i++)
660 g_free(active[i]);
661 g_free(active);
662 for (i = 0 ; i < ninactive ; i++)
663 g_free(inactive[i]);
664 g_free(inactive);
665 return ret;
666 }
667
668 static void
669 gvir_connection_fetch_domains_helper(GSimpleAsyncResult *res,
670 GObject *object,
671 GCancellable *cancellable)
672 {
673 GVirConnection *conn = GVIR_CONNECTION(object);
674 GError *err = NULL;
675
676 if (!gvir_connection_fetch_domains(conn, cancellable, &err)) {
677 g_simple_async_result_set_from_error(res, err);
678 g_error_free(err);
679 }
680 }
681
682
683 /**
684 * gvir_connection_fetch_domains_async:
685 * @conn: the connection
686 * @cancellable: (allow-none)(transfer none): cancellation object
687 * @callback: (transfer none): completion callback
688 * @opaque: (transfer none)(allow-none): opaque data for callback
689 */
690 void gvir_connection_fetch_domains_async(GVirConnection *conn,
691 GCancellable *cancellable,
692 GAsyncReadyCallback callback,
693 gpointer opaque)
694 {
695 GSimpleAsyncResult *res;
696
697 res = g_simple_async_result_new(G_OBJECT(conn),
698 callback,
699 opaque,
700 gvir_connection_fetch_domains);
701 g_simple_async_result_run_in_thread(res,
702 gvir_connection_fetch_domains_helper,
703 G_PRIORITY_DEFAULT,
704 cancellable);
705 g_object_unref(res);
706 }
707
708 /**
709 * gvir_connection_fetch_domains_finish:
710 * @conn: the connection
711 * @result: (transfer none): async method result
712 */
713 gboolean gvir_connection_fetch_domains_finish(GVirConnection *conn,
714 GAsyncResult *result,
715 GError **err)
716 {
717 g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
718 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
719
720 if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
721 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
722 g_warn_if_fail (g_simple_async_result_get_source_tag(simple) == gvir_connection_fetch_domains);
723 if (g_simple_async_result_propagate_error(simple, err))
724 return FALSE;
725 }
726
727 return TRUE;
728 }
729
730 static void
731 gvir_connection_fetch_pools_helper(GSimpleAsyncResult *res,
732 GObject *object,
733 GCancellable *cancellable)
734 {
735 GVirConnection *conn = GVIR_CONNECTION(object);
736 GError *err = NULL;
737
738 if (!gvir_connection_fetch_storage_pools(conn, cancellable, &err)) {
739 g_simple_async_result_set_from_error(res, err);
740 g_error_free(err);
741 }
742 }
743
744 /**
745 * gvir_connection_fetch_storage_pools_async:
746 * @conn: the connection
747 * @cancellable: (allow-none)(transfer none): cancellation object
748 * @callback: (transfer none): completion callback
749 * @opaque: (transfer none)(allow-none): opaque data for callback
750 */
751 void gvir_connection_fetch_storage_pools_async(GVirConnection *conn,
752 GCancellable *cancellable,
753 GAsyncReadyCallback callback,
754 gpointer opaque)
755 {
756 GSimpleAsyncResult *res;
757
758 res = g_simple_async_result_new(G_OBJECT(conn),
759 callback,
760 opaque,
761 gvir_connection_fetch_storage_pools);
762 g_simple_async_result_run_in_thread(res,
763 gvir_connection_fetch_pools_helper,
764 G_PRIORITY_DEFAULT,
765 cancellable);
766 g_object_unref(res);
767 }
768
769 /**
770 * gvir_connection_fetch_storage_pools_finish:
771 * @conn: the connection
772 * @result: (transfer none): async method result
773 */
774 gboolean gvir_connection_fetch_storage_pools_finish(GVirConnection *conn,
775 GAsyncResult *result,
776 GError **err)
777 {
778 g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
779 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
780
781 if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
782 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
783 g_warn_if_fail (g_simple_async_result_get_source_tag(simple) ==
784 gvir_connection_fetch_storage_pools);
785 if (g_simple_async_result_propagate_error(simple, err))
786 return FALSE;
787 }
788
789 return TRUE;
790 }
791
792 const gchar *gvir_connection_get_uri(GVirConnection *conn)
793 {
794 GVirConnectionPrivate *priv = conn->priv;
795 return priv->uri;
796 }
797
798 static void gvir_domain_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
799 {
800 g_object_ref(obj);
801 }
802
803 /**
804 * gvir_connection_get_domains:
805 *
806 * Return value: (element-type LibvirtGObject.Domain) (transfer full): List of #GVirDomain
807 */
808 GList *gvir_connection_get_domains(GVirConnection *conn)
809 {
810 GVirConnectionPrivate *priv = conn->priv;
811 GList *domains;
812 g_mutex_lock(priv->lock);
813 domains = g_hash_table_get_values(priv->domains);
814 g_list_foreach(domains, gvir_domain_ref, NULL);
815 g_mutex_unlock(priv->lock);
816 return domains;
817 }
818
819 /**
820 * gvir_connection_get_storage_pools:
821 *
822 * Return value: (element-type LibvirtGObject.StoragePool) (transfer full): List
823 * of #GVirStoragePool
824 */
825 GList *gvir_connection_get_storage_pools(GVirConnection *conn)
826 {
827 GVirConnectionPrivate *priv = conn->priv;
828 GList *pools;
829
830 g_mutex_lock(priv->lock);
831 pools = g_hash_table_get_values(priv->pools);
832 g_list_foreach(pools, gvir_domain_ref, NULL);
833 g_mutex_unlock(priv->lock);
834
835 return pools;
836 }
837
838 /**
839 * gvir_connection_get_domain:
840 * @uuid: uuid string of the requested domain
841 *
842 * Return value: (transfer full): the #GVirDomain, or NULL
843 */
844 GVirDomain *gvir_connection_get_domain(GVirConnection *conn,
845 const gchar *uuid)
846 {
847 GVirConnectionPrivate *priv = conn->priv;
848 GVirDomain *dom;
849 g_mutex_lock(priv->lock);
850 dom = g_hash_table_lookup(priv->domains, uuid);
851 if (dom)
852 g_object_ref(dom);
853 g_mutex_unlock(priv->lock);
854 return dom;
855 }
856
857 /**
858 * gvir_connection_get_storage_pool:
859 * @uuid: uuid string of the requested storage pool
860 *
861 * Return value: (transfer full): the #GVirStoragePool, or NULL
862 */
863 GVirStoragePool *gvir_connection_get_storage_pool(GVirConnection *conn,
864 const gchar *uuid)
865 {
866 GVirConnectionPrivate *priv = conn->priv;
867 GVirStoragePool *pool;
868
869 g_mutex_lock(priv->lock);
870 pool = g_hash_table_lookup(priv->pools, uuid);
871 if (pool)
872 g_object_ref(pool);
873 g_mutex_unlock(priv->lock);
874
875 return pool;
876 }
877
878 /**
879 * gvir_connection_find_domain_by_id:
880 * @id: id of the requested domain
881 *
882 * Return value: (transfer full): the #GVirDomain, or NULL
883 */
884 GVirDomain *gvir_connection_find_domain_by_id(GVirConnection *conn,
885 gint id)
886 {
887 GVirConnectionPrivate *priv = conn->priv;
888 GHashTableIter iter;
889 gpointer key, value;
890
891 g_mutex_lock(priv->lock);
892 g_hash_table_iter_init(&iter, priv->domains);
893
894 while (g_hash_table_iter_next(&iter, &key, &value)) {
895 GVirDomain *dom = value;
896 gint thisid = gvir_domain_get_id(dom, NULL);
897
898 if (thisid == id) {
899 g_object_ref(dom);
900 g_mutex_unlock(priv->lock);
901 return dom;
902 }
903 }
904 g_mutex_unlock(priv->lock);
905
906 return NULL;
907 }
908
909
910 /**
911 * gvir_connection_find_domain_by_name:
912 * @name: name of the requested domain
913 *
914 * Return value: (transfer full): the #GVirDomain, or NULL
915 */
916 GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn,
917 const gchar *name)
918 {
919 GVirConnectionPrivate *priv = conn->priv;
920 GHashTableIter iter;
921 gpointer key, value;
922
923 g_mutex_lock(priv->lock);
924 g_hash_table_iter_init(&iter, priv->domains);
925
926 while (g_hash_table_iter_next(&iter, &key, &value)) {
927 GVirDomain *dom = value;
928 const gchar *thisname = gvir_domain_get_name(dom);
929
930 if (strcmp(thisname, name) == 0) {
931 g_object_ref(dom);
932 g_mutex_unlock(priv->lock);
933 return dom;
934 }
935 }
936 g_mutex_unlock(priv->lock);
937
938 return NULL;
939 }
940
941 /**
942 * gvir_connection_find_storage_pool_by_name:
943 * @name: name of the requested storage pool
944 *
945 * Return value: (transfer full): the #GVirStoragePool, or NULL
946 */
947 GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn,
948 const gchar *name)
949 {
950 GVirConnectionPrivate *priv = conn->priv;
951 GHashTableIter iter;
952 gpointer key, value;
953
954 g_mutex_lock(priv->lock);
955 g_hash_table_iter_init(&iter, priv->pools);
956
957 while (g_hash_table_iter_next(&iter, &key, &value)) {
958 GVirStoragePool *pool = value;
959 const gchar *thisname = gvir_storage_pool_get_name(pool);
960
961 if (strcmp(thisname, name) == 0) {
962 g_object_ref(pool);
963 g_mutex_unlock(priv->lock);
964 return pool;
965 }
966 }
967 g_mutex_unlock(priv->lock);
968
969 return NULL;
970 }
971
972 static gpointer
973 gvir_connection_handle_copy(gpointer src)
974 {
975 virConnectRef(src);
976 return src;
977 }
978
979
980 GType gvir_connection_handle_get_type(void)
981 {
982 static GType handle_type = 0;
983
984 if (G_UNLIKELY(handle_type == 0))
985 handle_type = g_boxed_type_register_static
986 ("GVirConnectionHandle",
987 gvir_connection_handle_copy,
988 (GBoxedFreeFunc)virConnectClose);
989
990 return handle_type;
991 }
992
993 /**
994 * gvir_connection_get_stream:
995 * @flags: flags to use for the stream
996 *
997 * Return value: (transfer full): a #GVirStream stream, or NULL
998 */
999 GVirStream *gvir_connection_get_stream(GVirConnection *self,
1000 gint flags)
1001 {
1002 GVirConnectionClass *klass;
1003
1004 g_return_val_if_fail(GVIR_IS_CONNECTION(self), NULL);
1005 g_return_val_if_fail(self->priv->conn, NULL);
1006
1007 klass = GVIR_CONNECTION_GET_CLASS(self);
1008 g_return_val_if_fail(klass->stream_new, NULL);
1009
1010 virStreamPtr st = virStreamNew(self->priv->conn, flags);
1011
1012 return klass->stream_new(self, st);
1013 }
1014
1015 /**
1016 * gvir_connection_create_domain:
1017 * @conn: the connection on which to create the dmain
1018 * @conf: the configuration for the new domain
1019 * Returns: (transfer full): the newly created domain
1020 */
1021 GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
1022 GVirConfigDomain *conf,
1023 GError **err)
1024 {
1025 const gchar *xml;
1026 virDomainPtr handle;
1027 GVirConnectionPrivate *priv = conn->priv;
1028
1029 xml = gvir_config_object_get_doc(GVIR_CONFIG_OBJECT(conf));
1030
1031 g_return_val_if_fail(xml != NULL, NULL);
1032
1033 if (!(handle = virDomainDefineXML(priv->conn, xml))) {
1034 *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR,
1035 0,
1036 "Failed to create domain");
1037 return NULL;
1038 }
1039
1040 GVirDomain *domain;
1041
1042 domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN,
1043 "handle", handle,
1044 NULL));
1045
1046 g_mutex_lock(priv->lock);
1047 g_hash_table_insert(priv->domains,
1048 g_strdup(gvir_domain_get_uuid(domain)),
1049 domain);
1050 g_mutex_unlock(priv->lock);
1051
1052 return g_object_ref(domain);
1053 }
0 /*
1 * libvirt-gobject-connection.h: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_CONNECTION_H__
27 #define __LIBVIRT_GOBJECT_CONNECTION_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_CONNECTION (gvir_connection_get_type ())
32 #define GVIR_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONNECTION, GVirConnection))
33 #define GVIR_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONNECTION, GVirConnectionClass))
34 #define GVIR_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONNECTION))
35 #define GVIR_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONNECTION))
36 #define GVIR_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONNECTION, GVirConnectionClass))
37
38 #define GVIR_TYPE_CONNECTION_HANDLE (gvir_connection_handle_get_type ())
39
40 typedef struct _GVirConnection GVirConnection;
41 typedef struct _GVirConnectionPrivate GVirConnectionPrivate;
42 typedef struct _GVirConnectionClass GVirConnectionClass;
43
44 struct _GVirConnection
45 {
46 GObject parent;
47
48 GVirConnectionPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirConnectionClass
54 {
55 GObjectClass parent_class;
56
57 /* signals */
58 void (*vir_connection_opened)(GVirConnection *conn);
59 void (*vir_connection_closed)(GVirConnection *conn);
60
61 void (*vir_domain_added)(GVirConnection *conn, GVirDomain *dom);
62 void (*vir_domain_removed)(GVirConnection *conn, GVirDomain *dom);
63
64 GVirStream *(*stream_new)(GVirConnection *conn, gpointer handle);
65
66 gpointer padding[20];
67 };
68
69 GType gvir_connection_get_type(void);
70 GType gvir_connection_handle_get_type(void);
71
72 GVirConnection *gvir_connection_new(const char *uri);
73 gboolean gvir_connection_open(GVirConnection *conn,
74 GCancellable *cancellable,
75 GError **err);
76 void gvir_connection_open_async(GVirConnection *conn,
77 GCancellable *cancellable,
78 GAsyncReadyCallback callback,
79 gpointer opaque);
80 gboolean gvir_connection_open_finish(GVirConnection *conn,
81 GAsyncResult *result,
82 GError **err);
83 gboolean gvir_connection_is_open(GVirConnection *conn);
84 void gvir_connection_close(GVirConnection *conn);
85
86 gboolean gvir_connection_fetch_domains(GVirConnection *conn,
87 GCancellable *cancellable,
88 GError **err);
89 void gvir_connection_fetch_domains_async(GVirConnection *conn,
90 GCancellable *cancellable,
91 GAsyncReadyCallback callback,
92 gpointer opaque);
93 gboolean gvir_connection_fetch_domains_finish(GVirConnection *conn,
94 GAsyncResult *result,
95 GError **err);
96
97
98 const gchar *gvir_connection_get_uri(GVirConnection *conn);
99
100
101 GList *gvir_connection_get_domains(GVirConnection *conn);
102 GVirDomain *gvir_connection_get_domain(GVirConnection *conn,
103 const gchar *uuid);
104 GVirDomain *gvir_connection_find_domain_by_id(GVirConnection *conn,
105 gint id);
106 GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn,
107 const gchar *name);
108
109 GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
110 GVirConfigDomain *conf,
111 GError **err);
112
113 #if 0
114 GList *gvir_connection_get_interfaces(GVirConnection *conn);
115 GVirInterface *gvir_connection_get_interface(GVirConnection *conn,
116 const gchar *name);
117 GVirInterface *gvir_connection_find_interface_by_mac(GVirConnection *conn,
118 const gchar *macaddr);
119
120
121 GList *gvir_connection_get_networks(GVirConnection *conn);
122 GVirNetwork *gvir_connection_get_network(GVirConnection *conn,
123 const gchar *uuid);
124 GVirNetwork *gvir_connection_find_network_by_name(GVirConnection *conn,
125 const gchar *name);
126
127
128 GList *gvir_connection_get_network_filters(GVirConnection *conn);
129 GVirNetworkFilter *gvir_connection_get_network_filter(GVirConnection *conn,
130 const gchar *uuid);
131 GVirNetworkFilter *gvir_connection_find_network_filter_by_name(GVirConnection *conn,
132 const gchar *name);
133
134
135 GList *gvir_connection_get_node_devices(GVirConnection *conn);
136 GVirNodeDevice *gvir_connection_get_node_device(GVirConnection *conn,
137 const gchar *name);
138
139
140 GList *gvir_connection_get_secrets(GVirConnection *conn);
141 GVirSecret *gvir_connection_get_secret(GVirConnection *conn,
142 const gchar *uuid);
143 #endif
144
145 gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn,
146 GCancellable *cancellable,
147 GError **err);
148 void gvir_connection_fetch_storage_pools_async(GVirConnection *conn,
149 GCancellable *cancellable,
150 GAsyncReadyCallback callback,
151 gpointer opaque);
152 gboolean gvir_connection_fetch_storage_pools_finish(GVirConnection *conn,
153 GAsyncResult *result,
154 GError **err);
155
156 GList *gvir_connection_get_storage_pools(GVirConnection *conn);
157 GVirStoragePool *gvir_connection_get_storage_pool(GVirConnection *conn,
158 const gchar *uuid);
159 GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn,
160 const gchar *name);
161
162 GVirStream *gvir_connection_get_stream(GVirConnection *conn,
163 gint flags);
164
165 G_END_DECLS
166
167 #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
0 /*
1 * libvirt-gobject-domain_snapshot.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_DOMAIN_SNAPSHOT_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN_SNAPSHOT, GVirDomainSnapshotPrivate))
37
38 struct _GVirDomainSnapshotPrivate
39 {
40 virDomainSnapshotPtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirDomainSnapshot, gvir_domain_snapshot, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_DOMAIN_SNAPSHOT_ERROR gvir_domain_snapshot_error_quark()
53
54
55 static GQuark
56 gvir_domain_snapshot_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-domain-snapshot");
59 }
60
61 static void gvir_domain_snapshot_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirDomainSnapshot *conn = GVIR_DOMAIN_SNAPSHOT(object);
67 GVirDomainSnapshotPrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_domain_snapshot_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirDomainSnapshot *conn = GVIR_DOMAIN_SNAPSHOT(object);
86 GVirDomainSnapshotPrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virDomainSnapshotFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_domain_snapshot_finalize(GObject *object)
102 {
103 GVirDomainSnapshot *conn = GVIR_DOMAIN_SNAPSHOT(object);
104 GVirDomainSnapshotPrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirDomainSnapshot=%p", conn);
107
108 virDomainSnapshotFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_domain_snapshot_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_domain_snapshot_class_init(GVirDomainSnapshotClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_domain_snapshot_finalize;
119 object_class->get_property = gvir_domain_snapshot_get_property;
120 object_class->set_property = gvir_domain_snapshot_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The domain_snapshot handle",
127 GVIR_TYPE_DOMAIN_SNAPSHOT_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirDomainSnapshotPrivate));
136 }
137
138
139 static void gvir_domain_snapshot_init(GVirDomainSnapshot *conn)
140 {
141 GVirDomainSnapshotPrivate *priv;
142
143 DEBUG("Init GVirDomainSnapshot=%p", conn);
144
145 priv = conn->priv = GVIR_DOMAIN_SNAPSHOT_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_domain_snapshot_handle_copy(gpointer src)
152 {
153 #if 0
154 virDomainSnapshotRef(src);
155 #endif
156 return src;
157 }
158
159
160 GType gvir_domain_snapshot_handle_get_type(void)
161 {
162 static GType handle_type = 0;
163
164 if (G_UNLIKELY(handle_type == 0))
165 handle_type = g_boxed_type_register_static
166 ("GVirDomainSnapshotHandle",
167 gvir_domain_snapshot_handle_copy,
168 (GBoxedFreeFunc)virDomainSnapshotFree);
169
170 return handle_type;
171 }
172
173
174 const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot)
175 {
176 #if 0
177 GVirDomainSnapshotPrivate *priv = snapshot->priv;
178 const char *name;
179
180 if (!(name = virDomainSnapshotGetName(priv->handle))) {
181 g_error("Failed to get domain_snapshot name on %p", priv->handle);
182 }
183
184 return name;
185 #else
186 if (snapshot || !snapshot)
187 return NULL;
188 #endif
189 }
190
191
192 /**
193 * gvir_domain_snapshot_get_config:
194 * @snapshot: the domain_snapshot
195 * @flags: the flags
196 * Returns: (transfer full): the config
197 */
198 GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config
199 (GVirDomainSnapshot *snapshot,
200 guint64 flags,
201 GError **err)
202 {
203 GVirDomainSnapshotPrivate *priv = snapshot->priv;
204 gchar *xml;
205
206 if (!(xml = virDomainSnapshotGetXMLDesc(priv->handle, flags))) {
207 *err = gvir_error_new_literal(GVIR_DOMAIN_SNAPSHOT_ERROR,
208 0,
209 "Unable to get domain_snapshot XML config");
210 return NULL;
211 }
212
213 GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new(xml);
214
215 g_free(xml);
216 return conf;
217 }
0 /*
1 * libvirt-gobject-domain_snapshot.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_DOMAIN_SNAPSHOT_H__
27 #define __LIBVIRT_GOBJECT_DOMAIN_SNAPSHOT_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_DOMAIN_SNAPSHOT (gvir_domain_snapshot_get_type ())
32 #define GVIR_DOMAIN_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_DOMAIN_SNAPSHOT, GVirDomainSnapshot))
33 #define GVIR_DOMAIN_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_DOMAIN_SNAPSHOT, GVirDomainSnapshotClass))
34 #define GVIR_IS_DOMAIN_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_DOMAIN_SNAPSHOT))
35 #define GVIR_IS_DOMAIN_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_DOMAIN_SNAPSHOT))
36 #define GVIR_DOMAIN_SNAPSHOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_DOMAIN_SNAPSHOT, GVirDomainSnapshotClass))
37
38 #define GVIR_TYPE_DOMAIN_SNAPSHOT_HANDLE (gvir_domain_snapshot_handle_get_type())
39
40 typedef struct _GVirDomainSnapshot GVirDomainSnapshot;
41 typedef struct _GVirDomainSnapshotPrivate GVirDomainSnapshotPrivate;
42 typedef struct _GVirDomainSnapshotClass GVirDomainSnapshotClass;
43
44 struct _GVirDomainSnapshot
45 {
46 GObject parent;
47
48 GVirDomainSnapshotPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirDomainSnapshotClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60
61 GType gvir_domain_snapshot_get_type(void);
62 GType gvir_domain_snapshot_handle_get_type(void);
63
64 const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot);
65
66 GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config
67 (GVirDomainSnapshot *snapshot,
68 guint64 flags,
69 GError **err);
70
71 G_END_DECLS
72
73 #endif /* __LIBVIRT_GOBJECT_DOMAIN_SNAPSHOT_H__ */
0 /*
1 * libvirt-gobject-domain.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_DOMAIN_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN, GVirDomainPrivate))
37
38 struct _GVirDomainPrivate
39 {
40 virDomainPtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirDomain, gvir_domain, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_DOMAIN_ERROR gvir_domain_error_quark()
53
54
55 static GQuark
56 gvir_domain_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-domain");
59 }
60
61 static void gvir_domain_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirDomain *conn = GVIR_DOMAIN(object);
67 GVirDomainPrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_domain_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirDomain *conn = GVIR_DOMAIN(object);
86 GVirDomainPrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virDomainFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_domain_finalize(GObject *object)
102 {
103 GVirDomain *conn = GVIR_DOMAIN(object);
104 GVirDomainPrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirDomain=%p", conn);
107
108 virDomainFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_domain_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_domain_class_init(GVirDomainClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_domain_finalize;
119 object_class->get_property = gvir_domain_get_property;
120 object_class->set_property = gvir_domain_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The domain handle",
127 GVIR_TYPE_DOMAIN_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirDomainPrivate));
136 }
137
138
139 static void gvir_domain_init(GVirDomain *conn)
140 {
141 GVirDomainPrivate *priv;
142
143 DEBUG("Init GVirDomain=%p", conn);
144
145 priv = conn->priv = GVIR_DOMAIN_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_domain_handle_copy(gpointer src)
152 {
153 virDomainRef(src);
154 return src;
155 }
156
157
158 GType gvir_domain_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirDomainHandle",
165 gvir_domain_handle_copy,
166 (GBoxedFreeFunc)virDomainFree);
167
168 return handle_type;
169 }
170
171 static GVirDomainInfo *
172 gvir_domain_info_copy(GVirDomainInfo *info)
173 {
174 return g_slice_dup(GVirDomainInfo, info);
175 }
176
177
178 static void
179 gvir_domain_info_free(GVirDomainInfo *info)
180 {
181 g_slice_free(GVirDomainInfo, info);
182 }
183
184
185 GType gvir_domain_info_get_type(void)
186 {
187 static GType info_type = 0;
188
189 if (G_UNLIKELY(info_type == 0))
190 info_type = g_boxed_type_register_static
191 ("GVirDomainInfo",
192 (GBoxedCopyFunc)gvir_domain_info_copy,
193 (GBoxedFreeFunc)gvir_domain_info_free);
194
195 return info_type;
196 }
197
198
199 const gchar *gvir_domain_get_name(GVirDomain *dom)
200 {
201 GVirDomainPrivate *priv = dom->priv;
202 const char *name;
203
204 if (!(name = virDomainGetName(priv->handle))) {
205 g_error("Failed to get domain name on %p", priv->handle);
206 }
207
208 return name;
209 }
210
211
212 gchar *gvir_domain_get_uuid(GVirDomain *dom)
213 {
214 GVirDomainPrivate *priv = dom->priv;
215 char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN);
216
217 if (virDomainGetUUIDString(priv->handle, uuid) < 0) {
218 g_error("Failed to get domain UUID on %p", priv->handle);
219 }
220 return uuid;
221 }
222
223 gint gvir_domain_get_id(GVirDomain *dom,
224 GError **err)
225 {
226 GVirDomainPrivate *priv = dom->priv;
227 gint ret;
228
229 if ((ret = virDomainGetID(priv->handle)) < 0) {
230 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
231 0,
232 "Unable to get ID for domain");
233 }
234 return ret;
235 }
236
237
238 /**
239 * gvir_domain_start:
240 * @dom: the domain
241 * @flags: the flags
242 */
243 gboolean gvir_domain_start(GVirDomain *dom,
244 guint64 flags G_GNUC_UNUSED,
245 GError **err)
246 {
247 GVirDomainPrivate *priv = dom->priv;
248
249 if (virDomainCreate(priv->handle) < 0) {
250 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
251 0,
252 "Unable to start domain");
253 return FALSE;
254 }
255
256 return TRUE;
257 }
258
259 /**
260 * gvir_domain_stop:
261 * @dom: the domain
262 * @flags: the flags
263 */
264 gboolean gvir_domain_stop(GVirDomain *dom,
265 guint64 flags G_GNUC_UNUSED,
266 GError **err)
267 {
268 GVirDomainPrivate *priv = dom->priv;
269
270 if (virDomainDestroy(priv->handle) < 0) {
271 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
272 0,
273 "Unable to stop domain");
274 return FALSE;
275 }
276
277 return TRUE;
278 }
279
280 /**
281 * gvir_domain_delete:
282 * @dom: the domain
283 * @flags: the flags
284 */
285 gboolean gvir_domain_delete(GVirDomain *dom,
286 guint64 flags G_GNUC_UNUSED,
287 GError **err)
288 {
289 GVirDomainPrivate *priv = dom->priv;
290
291 if (virDomainUndefine(priv->handle) < 0) {
292 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
293 0,
294 "Unable to delete domain");
295 return FALSE;
296 }
297
298 return TRUE;
299 }
300
301 /**
302 * gvir_domain_shutdown:
303 * @dom: the domain
304 * @flags: the flags
305 */
306 gboolean gvir_domain_shutdown(GVirDomain *dom,
307 guint64 flags G_GNUC_UNUSED,
308 GError **err)
309 {
310 GVirDomainPrivate *priv = dom->priv;
311
312 if (virDomainShutdown(priv->handle) < 0) {
313 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
314 0,
315 "Unable to shutdown domain");
316 return FALSE;
317 }
318
319 return TRUE;
320 }
321
322 /**
323 * gvir_domain_reboot:
324 * @dom: the domain
325 * @flags: the flags
326 */
327 gboolean gvir_domain_reboot(GVirDomain *dom,
328 guint64 flags,
329 GError **err)
330 {
331 GVirDomainPrivate *priv = dom->priv;
332
333 if (virDomainReboot(priv->handle, flags) < 0) {
334 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
335 0,
336 "Unable to reboot domain");
337 return FALSE;
338 }
339
340 return TRUE;
341 }
342
343 /**
344 * gvir_domain_get_config:
345 * @dom: the domain
346 * @flags: the flags
347 * Returns: (transfer full): the config
348 */
349 GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom,
350 guint64 flags,
351 GError **err)
352 {
353 GVirDomainPrivate *priv = dom->priv;
354 gchar *xml;
355
356 if (!(xml = virDomainGetXMLDesc(priv->handle, flags))) {
357 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
358 0,
359 "Unable to get domain XML config");
360 return NULL;
361 }
362
363 GVirConfigDomain *conf = gvir_config_domain_new(xml);
364
365 g_free(xml);
366 return conf;
367 }
368
369
370 /**
371 * gvir_domain_get_info:
372 * @dom: the domain
373 * Returns: (transfer full): the info
374 */
375 GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
376 GError **err)
377 {
378 GVirDomainPrivate *priv = dom->priv;
379 virDomainInfo info;
380 GVirDomainInfo *ret;
381
382 if (virDomainGetInfo(priv->handle, &info) < 0) {
383 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
384 0,
385 "Unable to get domain info");
386 return NULL;
387 }
388
389 ret = g_slice_new(GVirDomainInfo);
390 ret->state = info.state;
391 ret->maxMem = info.maxMem;
392 ret->memory = info.memory;
393 ret->nrVirtCpu = info.nrVirtCpu;
394 ret->cpuTime = info.cpuTime;
395
396 return ret;
397 }
398
399 /**
400 * gvir_domain_screenshot:
401 * @stream: stream to use as output
402 * @monitor_id: monitor ID to take screenshot from
403 * @flags: extra flags, currently unused
404 *
405 * Returns: (transfer full): mime-type of the image format, or NULL upon error.
406 */
407 gchar *gvir_domain_screenshot(GVirDomain *dom,
408 GVirStream *stream,
409 guint64 monitor_id,
410 guint64 flags,
411 GError **err)
412 {
413 GVirDomainPrivate *priv;
414 virStreamPtr st = NULL;
415 gchar *mime = NULL;
416
417 g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
418 g_return_val_if_fail(GVIR_IS_STREAM(stream), NULL);
419
420 priv = dom->priv;
421 g_object_get(stream, "handle", &st, NULL);
422
423 if (!(mime = virDomainScreenshot(priv->handle,
424 st,
425 monitor_id,
426 flags))) {
427 *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR,
428 0,
429 "Unable to take a screenshot");
430 goto end;
431 }
432 end:
433 if (st != NULL)
434 virStreamFree(st);
435 return mime;
436 }
0 /*
1 * libvirt-gobject-domain.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_DOMAIN_H__
27 #define __LIBVIRT_GOBJECT_DOMAIN_H__
28
29 G_BEGIN_DECLS
30
31 #include <libvirt-gobject/libvirt-gobject-stream.h>
32
33 #define GVIR_TYPE_DOMAIN (gvir_domain_get_type ())
34 #define GVIR_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_DOMAIN, GVirDomain))
35 #define GVIR_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_DOMAIN, GVirDomainClass))
36 #define GVIR_IS_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_DOMAIN))
37 #define GVIR_IS_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_DOMAIN))
38 #define GVIR_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_DOMAIN, GVirDomainClass))
39
40 #define GVIR_TYPE_DOMAIN_INFO (gvir_domain_info_get_type())
41 #define GVIR_TYPE_DOMAIN_HANDLE (gvir_domain_handle_get_type())
42
43 typedef struct _GVirDomain GVirDomain;
44 typedef struct _GVirDomainPrivate GVirDomainPrivate;
45 typedef struct _GVirDomainClass GVirDomainClass;
46
47 struct _GVirDomain
48 {
49 GObject parent;
50
51 GVirDomainPrivate *priv;
52
53 /* Do not add fields to this struct */
54 };
55
56 struct _GVirDomainClass
57 {
58 GObjectClass parent_class;
59
60 void (*vir_domain_started)(GVirDomain *dom);
61 void (*vir_domain_stopped)(GVirDomain *dom);
62
63 gpointer padding[20];
64 };
65
66
67 typedef enum {
68 GVIR_DOMAIN_STATE_NONE = 0, /* no state */
69 GVIR_DOMAIN_STATE_RUNNING = 1, /* the domain is running */
70 GVIR_DOMAIN_STATE_BLOCKED = 2, /* the domain is blocked on resource */
71 GVIR_DOMAIN_STATE_PAUSED = 3, /* the domain is paused by user */
72 GVIR_DOMAIN_STATE_SHUTDOWN= 4, /* the domain is being shut down */
73 GVIR_DOMAIN_STATE_SHUTOFF = 5, /* the domain is shut off */
74 GVIR_DOMAIN_STATE_CRASHED = 6 /* the domain is crashed */
75 } GVirDomainState;
76
77
78 typedef struct _GVirDomainInfo GVirDomainInfo;
79 struct _GVirDomainInfo
80 {
81 GVirDomainState state; /* the running state */
82 guint64 maxMem; /* the maximum memory in KBytes allowed */
83 guint64 memory; /* the memory in KBytes used by the domain */
84 guint16 nrVirtCpu; /* the number of virtual CPUs for the domain */
85 guint64 cpuTime; /* the CPU time used in nanoseconds */
86 };
87
88 GType gvir_domain_get_type(void);
89 GType gvir_domain_info_get_type(void);
90 GType gvir_domain_handle_get_type(void);
91
92 const gchar *gvir_domain_get_name(GVirDomain *dom);
93 gchar *gvir_domain_get_uuid(GVirDomain *dom);
94 gint gvir_domain_get_id(GVirDomain *dom,
95 GError **err);
96
97 gboolean gvir_domain_start(GVirDomain *dom,
98 guint64 flags,
99 GError **err);
100 gboolean gvir_domain_stop(GVirDomain *dom,
101 guint64 flags,
102 GError **err);
103 gboolean gvir_domain_delete(GVirDomain *dom,
104 guint64 flags,
105 GError **err);
106 gboolean gvir_domain_shutdown(GVirDomain *dom,
107 guint64 flags,
108 GError **err);
109 gboolean gvir_domain_reboot(GVirDomain *dom,
110 guint64 flags,
111 GError **err);
112
113 GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
114 GError **err);
115
116 GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom,
117 guint64 flags,
118 GError **err);
119
120 gchar *gvir_domain_screenshot(GVirDomain *dom,
121 GVirStream *stream,
122 guint64 monitor_id,
123 guint64 flags,
124 GError **err);
125
126 G_END_DECLS
127
128 #endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */
0 /*
1 * libvirt-gobject-interface.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_INTERFACE_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_INTERFACE, GVirInterfacePrivate))
37
38 struct _GVirInterfacePrivate
39 {
40 virInterfacePtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirInterface, gvir_interface, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_INTERFACE_ERROR gvir_interface_error_quark()
53
54
55 static GQuark
56 gvir_interface_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-interface");
59 }
60
61 static void gvir_interface_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirInterface *conn = GVIR_INTERFACE(object);
67 GVirInterfacePrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_interface_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirInterface *conn = GVIR_INTERFACE(object);
86 GVirInterfacePrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virInterfaceFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_interface_finalize(GObject *object)
102 {
103 GVirInterface *conn = GVIR_INTERFACE(object);
104 GVirInterfacePrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirInterface=%p", conn);
107
108 virInterfaceFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_interface_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_interface_class_init(GVirInterfaceClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_interface_finalize;
119 object_class->get_property = gvir_interface_get_property;
120 object_class->set_property = gvir_interface_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The interface handle",
127 GVIR_TYPE_INTERFACE_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirInterfacePrivate));
136 }
137
138
139 static void gvir_interface_init(GVirInterface *conn)
140 {
141 GVirInterfacePrivate *priv;
142
143 DEBUG("Init GVirInterface=%p", conn);
144
145 priv = conn->priv = GVIR_INTERFACE_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_interface_handle_copy(gpointer src)
152 {
153 virInterfaceRef(src);
154 return src;
155 }
156
157
158 GType gvir_interface_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirInterfaceHandle",
165 gvir_interface_handle_copy,
166 (GBoxedFreeFunc)virInterfaceFree);
167
168 return handle_type;
169 }
170
171
172 const gchar *gvir_interface_get_name(GVirInterface *iface)
173 {
174 GVirInterfacePrivate *priv = iface->priv;
175 const char *name;
176
177 if (!(name = virInterfaceGetName(priv->handle))) {
178 g_error("Failed to get interface name on %p", priv->handle);
179 }
180
181 return name;
182 }
183
184
185 /**
186 * gvir_interface_get_config:
187 * @iface: the interface
188 * @flags: the flags
189 * Returns: (transfer full): the config
190 */
191 GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface,
192 guint64 flags,
193 GError **err)
194 {
195 GVirInterfacePrivate *priv = iface->priv;
196 gchar *xml;
197
198 if (!(xml = virInterfaceGetXMLDesc(priv->handle, flags))) {
199 *err = gvir_error_new_literal(GVIR_INTERFACE_ERROR,
200 0,
201 "Unable to get interface XML config");
202 return NULL;
203 }
204
205 GVirConfigInterface *conf = gvir_config_interface_new(xml);
206
207 g_free(xml);
208 return conf;
209 }
0 /*
1 * libvirt-gobject-interface.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_INTERFACE_H__
27 #define __LIBVIRT_GOBJECT_INTERFACE_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_INTERFACE (gvir_interface_get_type ())
32 #define GVIR_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_INTERFACE, GVirInterface))
33 #define GVIR_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_INTERFACE, GVirInterfaceClass))
34 #define GVIR_IS_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_INTERFACE))
35 #define GVIR_IS_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_INTERFACE))
36 #define GVIR_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_INTERFACE, GVirInterfaceClass))
37
38 #define GVIR_TYPE_INTERFACE_HANDLE (gvir_interface_handle_get_type())
39
40 typedef struct _GVirInterface GVirInterface;
41 typedef struct _GVirInterfacePrivate GVirInterfacePrivate;
42 typedef struct _GVirInterfaceClass GVirInterfaceClass;
43
44 struct _GVirInterface
45 {
46 GObject parent;
47
48 GVirInterfacePrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirInterfaceClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60
61 GType gvir_interface_get_type(void);
62 GType gvir_interface_handle_get_type(void);
63
64 const gchar *gvir_interface_get_name(GVirInterface *iface);
65
66 GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface,
67 guint64 flags,
68 GError **err);
69
70 G_END_DECLS
71
72 #endif /* __LIBVIRT_GOBJECT_INTERFACE_H__ */
0 /*
1 * libvirt-gobject-main.c: libvirt gobject integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <stdlib.h>
26
27 #include "libvirt-glib/libvirt-glib.h"
28 #include "libvirt-gobject/libvirt-gobject.h"
29
30 gboolean debugFlag = FALSE;
31
32 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
33
34 /**
35 * gvir_init_object:
36 * @argc: (inout): pointer to application's argc
37 * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
38 */
39 void gvir_init_object(int *argc,
40 char ***argv)
41 {
42 GError *err = NULL;
43 if (!gvir_init_object_check(argc, argv, &err)) {
44 g_error("Could not initialize libvirt-gobject: %s\n",
45 err->message);
46 }
47 }
48
49
50 /**
51 * gvir_init_object_check:
52 * @argc: (inout): pointer to application's argc
53 * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
54 * @err: pointer to a #GError to which a message will be posted on error
55 */
56 gboolean gvir_init_object_check(int *argc,
57 char ***argv,
58 GError **err)
59 {
60 char *debugEnv = getenv("LIBVIRT_GOBJECT_DEBUG");
61 if (debugEnv && *debugEnv && *debugEnv != '0')
62 debugFlag = 1;
63
64 g_type_init();
65
66 gvir_event_register();
67
68 if (!gvir_init_check(argc, argv, err))
69 return FALSE;
70
71 return TRUE;
72 }
73
0 /*
1 * libvirt-gobject-main.c: libvirt gobject integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
24 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
25 #endif
26
27 #ifndef __LIBVIRT_GOBJECT_MAIN_H__
28 #define __LIBVIRT_GOBJECT_MAIN_H__
29
30 G_BEGIN_DECLS
31
32 void gvir_init_object(int *argc,
33 char ***argv);
34 gboolean gvir_init_object_check(int *argc,
35 char ***argv,
36 GError **err);
37
38 G_END_DECLS
39
40 #endif /* __LIBVIRT_GOBJECT_MAIN_H__ */
0 /*
1 * libvirt-gobject-manager.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/libvirt.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_MANAGER_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_MANAGER, GVirManagerPrivate))
37
38 struct _GVirManagerPrivate
39 {
40 GMutex *lock;
41 GList *connections;
42 };
43
44 G_DEFINE_TYPE(GVirManager, gvir_manager, G_TYPE_OBJECT);
45
46
47 enum {
48 PROP_0,
49 };
50
51
52 #define GVIR_MANAGER_ERROR gvir_manager_error_quark()
53
54 #if 0
55 static GQuark
56 gvir_manager_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-manager");
59 }
60 #endif
61
62
63 static void gvir_manager_finalize(GObject *object)
64 {
65 GVirManager *man = GVIR_MANAGER(object);
66 GVirManagerPrivate *priv = man->priv;
67
68 DEBUG("Finalize GVirManager=%p", man);
69
70 GList *tmp = priv->connections;
71 while (tmp) {
72 GVirConnection *conn = tmp->data;
73 g_object_unref(conn);
74 tmp = tmp->next;
75 }
76 g_list_free(priv->connections);
77
78 g_mutex_free(priv->lock);
79
80 G_OBJECT_CLASS(gvir_manager_parent_class)->finalize(object);
81 }
82
83
84 static void gvir_manager_class_init(GVirManagerClass *klass)
85 {
86 GObjectClass *object_class = G_OBJECT_CLASS (klass);
87
88 object_class->finalize = gvir_manager_finalize;
89
90 g_signal_new("vir-connection-added",
91 G_OBJECT_CLASS_TYPE(object_class),
92 G_SIGNAL_RUN_FIRST,
93 G_STRUCT_OFFSET(GVirManagerClass, vir_connection_added),
94 NULL, NULL,
95 g_cclosure_marshal_VOID__OBJECT,
96 G_TYPE_NONE,
97 1,
98 GVIR_TYPE_CONNECTION);
99 g_signal_new("vir-connection-removed",
100 G_OBJECT_CLASS_TYPE(object_class),
101 G_SIGNAL_RUN_FIRST,
102 G_STRUCT_OFFSET(GVirManagerClass, vir_connection_removed),
103 NULL, NULL,
104 g_cclosure_marshal_VOID__OBJECT,
105 G_TYPE_NONE,
106 1,
107 GVIR_TYPE_CONNECTION);
108
109 g_type_class_add_private(klass, sizeof(GVirManagerPrivate));
110 }
111
112
113 static void gvir_manager_init(GVirManager *conn)
114 {
115 GVirManagerPrivate *priv;
116
117 DEBUG("Init GVirManager=%p", conn);
118
119 priv = conn->priv = GVIR_MANAGER_GET_PRIVATE(conn);
120
121 memset(priv, 0, sizeof(*priv));
122
123 priv->lock = g_mutex_new();
124 }
125
126
127 GVirManager *gvir_manager_new(void)
128 {
129 return GVIR_MANAGER(g_object_new(GVIR_TYPE_MANAGER,
130 NULL));
131 }
132
133
134
135 void gvir_manager_add_connection(GVirManager *man,
136 GVirConnection *conn)
137 {
138 GVirManagerPrivate *priv = man->priv;
139
140 g_mutex_lock(priv->lock);
141 g_object_ref(conn);
142 priv->connections = g_list_append(priv->connections, conn);
143
144 /* Hold extra reference while emitting signal */
145 g_object_ref(conn);
146 g_mutex_unlock(priv->lock);
147 g_signal_emit_by_name(man, "vir-connection-added", conn);
148 g_object_unref(conn);
149 }
150
151 void gvir_manager_remove_connection(GVirManager *man,
152 GVirConnection *conn)
153 {
154 GVirManagerPrivate *priv = man->priv;
155
156 g_mutex_lock(priv->lock);
157 priv->connections = g_list_remove(priv->connections, conn);
158 g_mutex_unlock(priv->lock);
159
160 g_signal_emit_by_name(man, "vir-connection-removed", conn);
161 g_object_unref(conn);
162 }
163
164
165 /**
166 * gvir_manager_get_connections:
167 * Returns: (transfer full)(element-type GVirConnection): the connections
168 */
169 GList *gvir_manager_get_connections(GVirManager *man)
170 {
171 GVirManagerPrivate *priv = man->priv;
172
173 GList *tmp = priv->connections;
174 while (tmp) {
175 GVirConnection *conn = tmp->data;
176 g_object_ref(conn);
177 tmp = tmp->next;
178 }
179
180 return g_list_copy(priv->connections);
181 }
182
183
184 /**
185 * gvir_manager_find_connection_by_uri:
186 * Returns: (transfer full)(allow-none): the connection,or NULL
187 */
188 GVirConnection *gvir_manager_find_connection_by_uri(GVirManager *man,
189 const gchar *uri)
190 {
191 GVirManagerPrivate *priv = man->priv;
192
193 GList *tmp = priv->connections;
194 while (tmp) {
195 GVirConnection *conn = tmp->data;
196 if (g_strcmp0(gvir_connection_get_uri(conn), uri) == 0)
197 return conn;
198 tmp = tmp->next;
199 }
200 return NULL;
201 }
202
0 /*
1 * libvirt-gobject-manager.h: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_MANAGER_H__
27 #define __LIBVIRT_GOBJECT_MANAGER_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_MANAGER (gvir_manager_get_type ())
32 #define GVIR_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_MANAGER, GVirManager))
33 #define GVIR_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_MANAGER, GVirManagerClass))
34 #define GVIR_IS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_MANAGER))
35 #define GVIR_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_MANAGER))
36 #define GVIR_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_MANAGER, GVirManagerClass))
37
38
39 typedef struct _GVirManager GVirManager;
40 typedef struct _GVirManagerPrivate GVirManagerPrivate;
41 typedef struct _GVirManagerClass GVirManagerClass;
42
43 struct _GVirManager
44 {
45 GObject parent;
46
47 GVirManagerPrivate *priv;
48
49 /* Do not add fields to this struct */
50 };
51
52 struct _GVirManagerClass
53 {
54 GObjectClass parent_class;
55
56 /* Signals */
57 void (*vir_connection_added)(GVirManager *man, GVirConnection *conn);
58 void (*vir_connection_removed)(GVirManager *man, GVirConnection *conn);
59
60 gpointer padding[20];
61 };
62
63 GType gvir_manager_get_type(void);
64
65 GVirManager *gvir_manager_new(void);
66
67 void gvir_manager_add_connection(GVirManager *man,
68 GVirConnection *conn);
69
70 void gvir_manager_remove_connection(GVirManager *man,
71 GVirConnection *conn);
72
73 GList *gvir_manager_get_connections(GVirManager *man);
74
75 GVirConnection *gvir_manager_find_connection_by_uri(GVirManager *man,
76 const gchar *uri);
77
78 G_END_DECLS
79
80 #endif /* __LIBVIRT_GOBJECT_MANAGER_H__ */
0 /*
1 * libvirt-gobject-network_filter.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_NETWORK_FILTER_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK_FILTER, GVirNetworkFilterPrivate))
37
38 struct _GVirNetworkFilterPrivate
39 {
40 virNWFilterPtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirNetworkFilter, gvir_network_filter, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_NETWORK_FILTER_ERROR gvir_network_filter_error_quark()
53
54
55 static GQuark
56 gvir_network_filter_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-network_filter");
59 }
60
61 static void gvir_network_filter_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirNetworkFilter *conn = GVIR_NETWORK_FILTER(object);
67 GVirNetworkFilterPrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_network_filter_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirNetworkFilter *conn = GVIR_NETWORK_FILTER(object);
86 GVirNetworkFilterPrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virNWFilterFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_network_filter_finalize(GObject *object)
102 {
103 GVirNetworkFilter *conn = GVIR_NETWORK_FILTER(object);
104 GVirNetworkFilterPrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirNetworkFilter=%p", conn);
107
108 virNWFilterFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_network_filter_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_network_filter_class_init(GVirNetworkFilterClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_network_filter_finalize;
119 object_class->get_property = gvir_network_filter_get_property;
120 object_class->set_property = gvir_network_filter_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The network_filter handle",
127 GVIR_TYPE_NETWORK_FILTER_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirNetworkFilterPrivate));
136 }
137
138
139 static void gvir_network_filter_init(GVirNetworkFilter *conn)
140 {
141 GVirNetworkFilterPrivate *priv;
142
143 DEBUG("Init GVirNetworkFilter=%p", conn);
144
145 priv = conn->priv = GVIR_NETWORK_FILTER_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_network_filter_handle_copy(gpointer src)
152 {
153 virNWFilterRef(src);
154 return src;
155 }
156
157
158 GType gvir_network_filter_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirNetworkFilterHandle",
165 gvir_network_filter_handle_copy,
166 (GBoxedFreeFunc)virNWFilterFree);
167
168 return handle_type;
169 }
170
171
172 const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter)
173 {
174 GVirNetworkFilterPrivate *priv = filter->priv;
175 const char *name;
176
177 if (!(name = virNWFilterGetName(priv->handle))) {
178 g_error("Failed to get network_filter name on %p", priv->handle);
179 }
180
181 return name;
182 }
183
184
185 gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter)
186 {
187 GVirNetworkFilterPrivate *priv = filter->priv;
188 char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN);
189
190 if (virNWFilterGetUUIDString(priv->handle, uuid) < 0) {
191 g_error("Failed to get network_filter UUID on %p", priv->handle);
192 }
193 return uuid;
194 }
195
196
197 /**
198 * gvir_network_filter_get_config:
199 * @filter: the network_filter
200 * @flags: the flags
201 * Returns: (transfer full): the config
202 */
203 GVirConfigNetworkFilter *gvir_network_filter_get_config
204 (GVirNetworkFilter *filter,
205 guint64 flags,
206 GError **err)
207 {
208 GVirNetworkFilterPrivate *priv = filter->priv;
209 gchar *xml;
210
211 if (!(xml = virNWFilterGetXMLDesc(priv->handle, flags))) {
212 *err = gvir_error_new_literal(GVIR_NETWORK_FILTER_ERROR,
213 0,
214 "Unable to get network_filter XML config");
215 return NULL;
216 }
217
218 GVirConfigNetworkFilter *conf = gvir_config_network_filter_new(xml);
219
220 g_free(xml);
221 return conf;
222 }
0 /*
1 * libvirt-gobject-network_filter.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_NETWORK_FILTER_H__
27 #define __LIBVIRT_GOBJECT_NETWORK_FILTER_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_NETWORK_FILTER (gvir_network_filter_get_type ())
32 #define GVIR_NETWORK_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_NETWORK_FILTER, GVirNetworkFilter))
33 #define GVIR_NETWORK_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_NETWORK_FILTER, GVirNetworkFilterClass))
34 #define GVIR_IS_NETWORK_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_NETWORK_FILTER))
35 #define GVIR_IS_NETWORK_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_NETWORK_FILTER))
36 #define GVIR_NETWORK_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_NETWORK_FILTER, GVirNetworkFilterClass))
37
38 #define GVIR_TYPE_NETWORK_FILTER_HANDLE (gvir_network_filter_handle_get_type())
39
40 typedef struct _GVirNetworkFilter GVirNetworkFilter;
41 typedef struct _GVirNetworkFilterPrivate GVirNetworkFilterPrivate;
42 typedef struct _GVirNetworkFilterClass GVirNetworkFilterClass;
43
44 struct _GVirNetworkFilter
45 {
46 GObject parent;
47
48 GVirNetworkFilterPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirNetworkFilterClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60 GType gvir_network_filter_get_type(void);
61 GType gvir_network_filter_handle_get_type(void);
62
63 const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter);
64 gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter);
65
66 GVirConfigNetworkFilter *gvir_network_filter_get_config
67 (GVirNetworkFilter *filter,
68 guint64 flags,
69 GError **err);
70
71 G_END_DECLS
72
73 #endif /* __LIBVIRT_GOBJECT_NETWORK_FILTER_H__ */
0 /*
1 * libvirt-gobject-network.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_NETWORK_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, GVirNetworkPrivate))
37
38 struct _GVirNetworkPrivate
39 {
40 virNetworkPtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirNetwork, gvir_network, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_NETWORK_ERROR gvir_network_error_quark()
53
54
55 static GQuark
56 gvir_network_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-network");
59 }
60
61 static void gvir_network_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirNetwork *conn = GVIR_NETWORK(object);
67 GVirNetworkPrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_network_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirNetwork *conn = GVIR_NETWORK(object);
86 GVirNetworkPrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virNetworkFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_network_finalize(GObject *object)
102 {
103 GVirNetwork *conn = GVIR_NETWORK(object);
104 GVirNetworkPrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirNetwork=%p", conn);
107
108 virNetworkFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_network_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_network_class_init(GVirNetworkClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_network_finalize;
119 object_class->get_property = gvir_network_get_property;
120 object_class->set_property = gvir_network_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The network handle",
127 GVIR_TYPE_NETWORK_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirNetworkPrivate));
136 }
137
138
139 static void gvir_network_init(GVirNetwork *conn)
140 {
141 GVirNetworkPrivate *priv;
142
143 DEBUG("Init GVirNetwork=%p", conn);
144
145 priv = conn->priv = GVIR_NETWORK_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_network_handle_copy(gpointer src)
152 {
153 virNetworkRef(src);
154 return src;
155 }
156
157
158 GType gvir_network_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirNetworkHandle",
165 gvir_network_handle_copy,
166 (GBoxedFreeFunc)virNetworkFree);
167
168 return handle_type;
169 }
170
171
172 const gchar *gvir_network_get_name(GVirNetwork *network)
173 {
174 GVirNetworkPrivate *priv = network->priv;
175 const char *name;
176
177 if (!(name = virNetworkGetName(priv->handle))) {
178 g_error("Failed to get network name on %p", priv->handle);
179 }
180
181 return name;
182 }
183
184
185 gchar *gvir_network_get_uuid(GVirNetwork *network)
186 {
187 GVirNetworkPrivate *priv = network->priv;
188 char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN);
189
190 if (virNetworkGetUUIDString(priv->handle, uuid) < 0) {
191 g_error("Failed to get network UUID on %p", priv->handle);
192 }
193 return uuid;
194 }
195
196 /**
197 * gvir_network_get_config:
198 * @network: the network
199 * @flags: the flags
200 * Returns: (transfer full): the config
201 */
202 GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network,
203 guint64 flags,
204 GError **err)
205 {
206 GVirNetworkPrivate *priv = network->priv;
207 gchar *xml;
208
209 if (!(xml = virNetworkGetXMLDesc(priv->handle, flags))) {
210 *err = gvir_error_new_literal(GVIR_NETWORK_ERROR,
211 0,
212 "Unable to get network XML config");
213 return NULL;
214 }
215
216 GVirConfigNetwork *conf = gvir_config_network_new(xml);
217
218 g_free(xml);
219 return conf;
220 }
0 /*
1 * libvirt-gobject-network.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_NETWORK_H__
27 #define __LIBVIRT_GOBJECT_NETWORK_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_NETWORK (gvir_network_get_type ())
32 #define GVIR_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_NETWORK, GVirNetwork))
33 #define GVIR_NETWORK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_NETWORK, GVirNetworkClass))
34 #define GVIR_IS_NETWORK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_NETWORK))
35 #define GVIR_IS_NETWORK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_NETWORK))
36 #define GVIR_NETWORK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_NETWORK, GVirNetworkClass))
37
38 #define GVIR_TYPE_NETWORK_HANDLE (gvir_network_handle_get_type())
39
40 typedef struct _GVirNetwork GVirNetwork;
41 typedef struct _GVirNetworkPrivate GVirNetworkPrivate;
42 typedef struct _GVirNetworkClass GVirNetworkClass;
43
44 struct _GVirNetwork
45 {
46 GObject parent;
47
48 GVirNetworkPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirNetworkClass
54 {
55 GObjectClass parent_class;
56
57 void (*vir_network_started)(GVirNetwork *net);
58 void (*vir_network_stopped)(GVirNetwork *net);
59
60 gpointer padding[20];
61 };
62
63
64 GType gvir_network_get_type(void);
65 GType gvir_network_handle_get_type(void);
66
67 const gchar *gvir_network_get_name(GVirNetwork *network);
68 gchar *gvir_network_get_uuid(GVirNetwork *network);
69
70 GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network,
71 guint64 flags,
72 GError **err);
73
74 G_END_DECLS
75
76 #endif /* __LIBVIRT_GOBJECT_NETWORK_H__ */
0 /*
1 * libvirt-gobject-node_device.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_NODE_DEVICE_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NODE_DEVICE, GVirNodeDevicePrivate))
37
38 struct _GVirNodeDevicePrivate
39 {
40 virNodeDevicePtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirNodeDevice, gvir_node_device, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_NODE_DEVICE_ERROR gvir_node_device_error_quark()
53
54
55 static GQuark
56 gvir_node_device_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-node_device");
59 }
60
61 static void gvir_node_device_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirNodeDevice *conn = GVIR_NODE_DEVICE(object);
67 GVirNodeDevicePrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_node_device_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirNodeDevice *conn = GVIR_NODE_DEVICE(object);
86 GVirNodeDevicePrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virNodeDeviceFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_node_device_finalize(GObject *object)
102 {
103 GVirNodeDevice *conn = GVIR_NODE_DEVICE(object);
104 GVirNodeDevicePrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirNodeDevice=%p", conn);
107
108 virNodeDeviceFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_node_device_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_node_device_class_init(GVirNodeDeviceClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_node_device_finalize;
119 object_class->get_property = gvir_node_device_get_property;
120 object_class->set_property = gvir_node_device_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The node_device handle",
127 GVIR_TYPE_NODE_DEVICE_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirNodeDevicePrivate));
136 }
137
138
139 static void gvir_node_device_init(GVirNodeDevice *conn)
140 {
141 GVirNodeDevicePrivate *priv;
142
143 DEBUG("Init GVirNodeDevice=%p", conn);
144
145 priv = conn->priv = GVIR_NODE_DEVICE_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_node_device_handle_copy(gpointer src)
152 {
153 virNodeDeviceRef(src);
154 return src;
155 }
156
157
158 GType gvir_node_device_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirNodeDeviceHandle",
165 gvir_node_device_handle_copy,
166 (GBoxedFreeFunc)virNodeDeviceFree);
167
168 return handle_type;
169 }
170
171
172 const gchar *gvir_node_device_get_name(GVirNodeDevice *device)
173 {
174 GVirNodeDevicePrivate *priv = device->priv;
175 const char *name;
176
177 if (!(name = virNodeDeviceGetName(priv->handle))) {
178 g_error("Failed to get node_device name on %p", priv->handle);
179 }
180
181 return name;
182 }
183
184
185 /**
186 * gvir_node_device_get_config:
187 * @device: the node_device
188 * @flags: the flags
189 * Returns: (transfer full): the config
190 */
191 GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device,
192 guint64 flags,
193 GError **err)
194 {
195 GVirNodeDevicePrivate *priv = device->priv;
196 gchar *xml;
197
198 if (!(xml = virNodeDeviceGetXMLDesc(priv->handle, flags))) {
199 *err = gvir_error_new_literal(GVIR_NODE_DEVICE_ERROR,
200 0,
201 "Unable to get node_device XML config");
202 return NULL;
203 }
204
205 GVirConfigNodeDevice *conf = gvir_config_node_device_new(xml);
206
207 g_free(xml);
208 return conf;
209 }
0 /*
1 * libvirt-gobject-node_device.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_NODE_DEVICE_H__
27 #define __LIBVIRT_GOBJECT_NODE_DEVICE_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_NODE_DEVICE (gvir_node_device_get_type ())
32 #define GVIR_NODE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_NODE_DEVICE, GVirNodeDevice))
33 #define GVIR_NODE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_NODE_DEVICE, GVirNodeDeviceClass))
34 #define GVIR_IS_NODE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_NODE_DEVICE))
35 #define GVIR_IS_NODE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_NODE_DEVICE))
36 #define GVIR_NODE_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_NODE_DEVICE, GVirNodeDeviceClass))
37
38 #define GVIR_TYPE_NODE_DEVICE_HANDLE (gvir_node_device_handle_get_type())
39
40 typedef struct _GVirNodeDevice GVirNodeDevice;
41 typedef struct _GVirNodeDevicePrivate GVirNodeDevicePrivate;
42 typedef struct _GVirNodeDeviceClass GVirNodeDeviceClass;
43
44 struct _GVirNodeDevice
45 {
46 GObject parent;
47
48 GVirNodeDevicePrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirNodeDeviceClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60 GType gvir_node_device_get_type(void);
61 GType gvir_node_device_handle_get_type(void);
62
63 const gchar *gvir_node_device_get_name(GVirNodeDevice *device);
64
65 GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device,
66 guint64 flags,
67 GError **err);
68
69 G_END_DECLS
70
71 #endif /* __LIBVIRT_GOBJECT_NODE_DEVICE_H__ */
0 /*
1 * libvirt-gobject-secret.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_SECRET_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_SECRET, GVirSecretPrivate))
37
38 struct _GVirSecretPrivate
39 {
40 virSecretPtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirSecret, gvir_secret, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_SECRET_ERROR gvir_secret_error_quark()
53
54
55 static GQuark
56 gvir_secret_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-secret");
59 }
60
61 static void gvir_secret_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirSecret *conn = GVIR_SECRET(object);
67 GVirSecretPrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_secret_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirSecret *conn = GVIR_SECRET(object);
86 GVirSecretPrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virSecretFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_secret_finalize(GObject *object)
102 {
103 GVirSecret *conn = GVIR_SECRET(object);
104 GVirSecretPrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirSecret=%p", conn);
107
108 virSecretFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_secret_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_secret_class_init(GVirSecretClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_secret_finalize;
119 object_class->get_property = gvir_secret_get_property;
120 object_class->set_property = gvir_secret_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The secret handle",
127 GVIR_TYPE_SECRET_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirSecretPrivate));
136 }
137
138
139 static void gvir_secret_init(GVirSecret *conn)
140 {
141 GVirSecretPrivate *priv;
142
143 DEBUG("Init GVirSecret=%p", conn);
144
145 priv = conn->priv = GVIR_SECRET_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_secret_handle_copy(gpointer src)
152 {
153 virSecretRef(src);
154 return src;
155 }
156
157
158 GType gvir_secret_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirSecretHandle",
165 gvir_secret_handle_copy,
166 (GBoxedFreeFunc)virSecretFree);
167
168 return handle_type;
169 }
170
171
172 gchar *gvir_secret_get_uuid(GVirSecret *secret)
173 {
174 GVirSecretPrivate *priv = secret->priv;
175 char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN);
176
177 if (virSecretGetUUIDString(priv->handle, uuid) < 0) {
178 g_error("Failed to get secret UUID on %p", priv->handle);
179 }
180 return uuid;
181 }
182
183
184 /**
185 * gvir_secret_get_config:
186 * @secret: the secret
187 * @flags: the flags
188 * Returns: (transfer full): the config
189 */
190 GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret,
191 guint64 flags,
192 GError **err)
193 {
194 GVirSecretPrivate *priv = secret->priv;
195 gchar *xml;
196
197 if (!(xml = virSecretGetXMLDesc(priv->handle, flags))) {
198 *err = gvir_error_new_literal(GVIR_SECRET_ERROR,
199 0,
200 "Unable to get secret XML config");
201 return NULL;
202 }
203
204 GVirConfigSecret *conf = gvir_config_secret_new(xml);
205
206 g_free(xml);
207 return conf;
208 }
0 /*
1 * libvirt-gobject-secret.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_SECRET_H__
27 #define __LIBVIRT_GOBJECT_SECRET_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_SECRET (gvir_secret_get_type ())
32 #define GVIR_SECRET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_SECRET, GVirSecret))
33 #define GVIR_SECRET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_SECRET, GVirSecretClass))
34 #define GVIR_IS_SECRET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_SECRET))
35 #define GVIR_IS_SECRET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_SECRET))
36 #define GVIR_SECRET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_SECRET, GVirSecretClass))
37
38 #define GVIR_TYPE_SECRET_HANDLE (gvir_secret_handle_get_type())
39
40 typedef struct _GVirSecret GVirSecret;
41 typedef struct _GVirSecretPrivate GVirSecretPrivate;
42 typedef struct _GVirSecretClass GVirSecretClass;
43
44 struct _GVirSecret
45 {
46 GObject parent;
47
48 GVirSecretPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirSecretClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60
61 GType gvir_secret_get_type(void);
62 GType gvir_secret_handle_get_type(void);
63
64 const gchar *gvir_secret_get_name(GVirSecret *secret);
65 gchar *gvir_secret_get_uuid(GVirSecret *secret);
66
67 GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret,
68 guint64 flags,
69 GError **err);
70
71 G_END_DECLS
72
73 #endif /* __LIBVIRT_GOBJECT_SECRET_H__ */
0 /*
1 * libvirt-gobject-storage_pool.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_STORAGE_POOL_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_STORAGE_POOL, GVirStoragePoolPrivate))
37
38 struct _GVirStoragePoolPrivate
39 {
40 GMutex *lock;
41 virStoragePoolPtr handle;
42
43 GHashTable *volumes;
44 };
45
46 G_DEFINE_TYPE(GVirStoragePool, gvir_storage_pool, G_TYPE_OBJECT);
47
48
49 enum {
50 PROP_0,
51 PROP_HANDLE,
52 };
53
54
55 #define GVIR_STORAGE_POOL_ERROR gvir_storage_pool_error_quark()
56
57
58 static GQuark
59 gvir_storage_pool_error_quark(void)
60 {
61 return g_quark_from_static_string("gvir-storage-pool");
62 }
63
64 static void gvir_storage_pool_get_property(GObject *object,
65 guint prop_id,
66 GValue *value,
67 GParamSpec *pspec)
68 {
69 GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
70 GVirStoragePoolPrivate *priv = pool->priv;
71
72 switch (prop_id) {
73 case PROP_HANDLE:
74 g_value_set_boxed(value, priv->handle);
75 break;
76
77 default:
78 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
79 }
80 }
81
82
83 static void gvir_storage_pool_set_property(GObject *object,
84 guint prop_id,
85 const GValue *value,
86 GParamSpec *pspec)
87 {
88 GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
89 GVirStoragePoolPrivate *priv = pool->priv;
90
91 switch (prop_id) {
92 case PROP_HANDLE:
93 if (priv->handle)
94 virStoragePoolFree(priv->handle);
95 priv->handle = g_value_dup_boxed(value);
96 break;
97
98 default:
99 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
100 }
101 }
102
103
104 static void gvir_storage_pool_finalize(GObject *object)
105 {
106 GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
107 GVirStoragePoolPrivate *priv = pool->priv;
108
109 DEBUG("Finalize GVirStoragePool=%p", pool);
110
111 if (priv->volumes) {
112 g_hash_table_unref(priv->volumes);
113 priv->volumes = NULL;
114 }
115
116 virStoragePoolFree(priv->handle);
117
118 g_mutex_free(priv->lock);
119
120 G_OBJECT_CLASS(gvir_storage_pool_parent_class)->finalize(object);
121 }
122
123
124 static void gvir_storage_pool_class_init(GVirStoragePoolClass *klass)
125 {
126 GObjectClass *object_class = G_OBJECT_CLASS (klass);
127
128 object_class->finalize = gvir_storage_pool_finalize;
129 object_class->get_property = gvir_storage_pool_get_property;
130 object_class->set_property = gvir_storage_pool_set_property;
131
132 g_object_class_install_property(object_class,
133 PROP_HANDLE,
134 g_param_spec_boxed("handle",
135 "Handle",
136 "The storage_pool handle",
137 GVIR_TYPE_STORAGE_POOL_HANDLE,
138 G_PARAM_READABLE |
139 G_PARAM_WRITABLE |
140 G_PARAM_CONSTRUCT_ONLY |
141 G_PARAM_STATIC_NAME |
142 G_PARAM_STATIC_NICK |
143 G_PARAM_STATIC_BLURB));
144
145 g_type_class_add_private(klass, sizeof(GVirStoragePoolPrivate));
146 }
147
148
149 static void gvir_storage_pool_init(GVirStoragePool *pool)
150 {
151 GVirStoragePoolPrivate *priv;
152
153 DEBUG("Init GVirStoragePool=%p", pool);
154
155 priv = pool->priv = GVIR_STORAGE_POOL_GET_PRIVATE(pool);
156
157 memset(priv, 0, sizeof(*priv));
158
159 priv->lock = g_mutex_new();
160 }
161
162 static gpointer
163 gvir_storage_pool_handle_copy(gpointer src)
164 {
165 virStoragePoolRef(src);
166 return src;
167 }
168
169
170 GType gvir_storage_pool_handle_get_type(void)
171 {
172 static GType handle_type = 0;
173
174 if (G_UNLIKELY(handle_type == 0))
175 handle_type = g_boxed_type_register_static
176 ("GVirStoragePoolHandle",
177 gvir_storage_pool_handle_copy,
178 (GBoxedFreeFunc)virStoragePoolFree);
179
180 return handle_type;
181 }
182
183
184 const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool)
185 {
186 GVirStoragePoolPrivate *priv = pool->priv;
187 const char *name;
188
189 if (!(name = virStoragePoolGetName(priv->handle))) {
190 g_error("Failed to get storage_pool name on %p", priv->handle);
191 }
192
193 return name;
194 }
195
196
197 gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool)
198 {
199 GVirStoragePoolPrivate *priv = pool->priv;
200 char *uuid = g_new(gchar, VIR_UUID_STRING_BUFLEN);
201
202 if (virStoragePoolGetUUIDString(priv->handle, uuid) < 0) {
203 g_error("Failed to get storage_pool UUID on %p", priv->handle);
204 }
205 return uuid;
206 }
207
208
209 /**
210 * gvir_storage_pool_get_config:
211 * @pool: the storage_pool
212 * @flags: the flags
213 * Returns: (transfer full): the config
214 */
215 GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
216 guint64 flags,
217 GError **err)
218 {
219 GVirStoragePoolPrivate *priv = pool->priv;
220 gchar *xml;
221
222 if (!(xml = virStoragePoolGetXMLDesc(priv->handle, flags))) {
223 *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR,
224 0,
225 "Unable to get storage_pool XML config");
226 return NULL;
227 }
228
229 GVirConfigStoragePool *conf = gvir_config_storage_pool_new(xml);
230
231 g_free(xml);
232 return conf;
233 }
234
235 typedef gint (* CountFunction) (virStoragePoolPtr vpool);
236 typedef gint (* ListFunction) (virStoragePoolPtr vpool, gchar **lst, gint max);
237
238 static gchar ** fetch_list(virStoragePoolPtr vpool,
239 const char *name,
240 CountFunction count_func,
241 ListFunction list_func,
242 GCancellable *cancellable,
243 gint *length,
244 GError **err)
245 {
246 gchar **lst = NULL;
247 gint n = 0;
248 gint i;
249
250 if ((n = count_func(vpool)) < 0) {
251 *err = gvir_error_new(GVIR_STORAGE_POOL_ERROR,
252 0,
253 "Unable to count %s", name);
254 goto error;
255 }
256
257 if (n) {
258 if (g_cancellable_set_error_if_cancelled(cancellable, err))
259 goto error;
260
261 lst = g_new(gchar *, n);
262 if ((n = list_func(vpool, lst, n)) < 0) {
263 *err = gvir_error_new(GVIR_STORAGE_POOL_ERROR,
264 0,
265 "Unable to list %s %d", name, n);
266 goto error;
267 }
268 }
269
270 *length = n;
271 return lst;
272
273 error:
274 for (i = 0 ; i < n; i++)
275 g_free(lst[i]);
276 g_free(lst);
277 return NULL;
278 }
279
280 /**
281 * gvir_storage_pool_refresh:
282 * @pool: the storage pool
283 * @cancellable: (allow-none)(transfer none): cancellation object
284 */
285 gboolean gvir_storage_pool_refresh(GVirStoragePool *pool,
286 GCancellable *cancellable,
287 GError **err)
288 {
289 GVirStoragePoolPrivate *priv = pool->priv;
290 GHashTable *vol_hash;
291 gchar **volumes = NULL;
292 gint nvolumes = 0;
293 gboolean ret = FALSE;
294 gint i;
295 virStoragePoolPtr vpool = NULL;
296
297 vpool = priv->handle;
298
299 if (virStoragePoolRefresh(vpool, 0) < 0) {
300 *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR,
301 0,
302 "Unable to refresh storage pool");
303 goto cleanup;
304 }
305
306 volumes = fetch_list(vpool,
307 "Storage Volumes",
308 virStoragePoolNumOfVolumes,
309 virStoragePoolListVolumes,
310 cancellable,
311 &nvolumes,
312 err);
313 if (*err != NULL)
314 goto cleanup;
315
316 if (g_cancellable_set_error_if_cancelled(cancellable, err))
317 goto cleanup;
318
319 vol_hash = g_hash_table_new_full(g_str_hash,
320 g_str_equal,
321 g_free,
322 g_object_unref);
323
324 for (i = 0 ; i < nvolumes ; i++) {
325 if (g_cancellable_set_error_if_cancelled(cancellable, err))
326 goto cleanup;
327
328 virStorageVolPtr vvolume;
329 GVirStorageVol *volume;
330
331 vvolume = virStorageVolLookupByName(vpool, volumes[i]);
332 if (!vvolume)
333 continue;
334
335 volume = GVIR_STORAGE_VOL(g_object_new(GVIR_TYPE_STORAGE_VOL,
336 "handle", vvolume,
337 NULL));
338
339 g_hash_table_insert(vol_hash, g_strdup(volumes[i]), volume);
340 }
341
342 g_mutex_lock(priv->lock);
343 if (priv->volumes)
344 g_hash_table_unref(priv->volumes);
345 priv->volumes = vol_hash;
346 g_mutex_unlock(priv->lock);
347
348 ret = TRUE;
349
350 cleanup:
351 for (i = 0 ; i < nvolumes ; i++)
352 g_free(volumes[i]);
353 g_free(volumes);
354 return ret;
355 }
356
357 static void
358 gvir_storage_pool_refresh_helper(GSimpleAsyncResult *res,
359 GObject *object,
360 GCancellable *cancellable)
361 {
362 GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
363 GError *err = NULL;
364
365 if (!gvir_storage_pool_refresh(pool, cancellable, &err)) {
366 g_simple_async_result_set_from_error(res, err);
367 g_error_free(err);
368 }
369 }
370
371 /**
372 * gvir_storage_pool_refresh_async:
373 * @pool: the storage pool
374 * @cancellable: (allow-none)(transfer none): cancellation object
375 * @callback: (transfer none): completion callback
376 * @opaque: (transfer none)(allow-none): opaque data for callback
377 */
378 void gvir_storage_pool_refresh_async(GVirStoragePool *pool,
379 GCancellable *cancellable,
380 GAsyncReadyCallback callback,
381 gpointer opaque)
382 {
383 GSimpleAsyncResult *res;
384
385 res = g_simple_async_result_new(G_OBJECT(pool),
386 callback,
387 opaque,
388 gvir_storage_pool_refresh);
389 g_simple_async_result_run_in_thread(res,
390 gvir_storage_pool_refresh_helper,
391 G_PRIORITY_DEFAULT,
392 cancellable);
393 g_object_unref(res);
394 }
395
396 /**
397 * gvir_storage_pool_refresh_finish:
398 * @pool: the storage pool
399 * @result: (transfer none): async method result
400 */
401 gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool,
402 GAsyncResult *result,
403 GError **err)
404 {
405 g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
406 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
407
408 if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
409 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
410 g_warn_if_fail (g_simple_async_result_get_source_tag(simple) ==
411 gvir_storage_pool_refresh);
412 if (g_simple_async_result_propagate_error(simple, err))
413 return FALSE;
414 }
415
416 return TRUE;
417 }
418
419 static void gvir_storage_vol_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
420 {
421 g_object_ref(obj);
422 }
423
424 /**
425 * gvir_storage_pool_get_volumes:
426 * @pool: the storage pool
427 *
428 * Return value: (element-type LibvirtGObject.StoragePool) (transfer full): List
429 * of #GVirStorageVol
430 */
431 GList *gvir_storage_pool_get_volumes(GVirStoragePool *pool)
432 {
433 GVirStoragePoolPrivate *priv = pool->priv;
434 GList *volumes;
435
436 g_mutex_lock(priv->lock);
437 volumes = g_hash_table_get_values(priv->volumes);
438 g_list_foreach(volumes, gvir_storage_vol_ref, NULL);
439 g_mutex_unlock(priv->lock);
440
441 return volumes;
442 }
443
444 /**
445 * gvir_storage_pool_get_volume:
446 * @pool: the storage pool
447 * @name: Name of the requested storage volume
448 *
449 * Return value: (transfer full): the #GVirStorageVol, or NULL
450 */
451 GVirStoragePool *gvir_storage_pool_get_volume(GVirStoragePool *pool,
452 const gchar *name)
453 {
454 GVirStoragePoolPrivate *priv = pool->priv;
455 GVirStoragePool *volume;
456
457 g_mutex_lock(priv->lock);
458 volume = g_hash_table_lookup(priv->volumes, name);
459 if (volume)
460 g_object_ref(volume);
461 g_mutex_unlock(priv->lock);
462
463 return volume;
464 }
465
466 /**
467 * gvir_storage_pool_create_volume:
468 * @pool: the storage pool in which to create the volume
469 * @conf: the configuration for the new volume
470 * Returns: (transfer full): the newly created volume
471 */
472 GVirStorageVol *gvir_storage_pool_create_volume
473 (GVirStoragePool *pool,
474 GVirConfigStorageVol *conf,
475 GError **err)
476 {
477 const gchar *xml;
478 virStorageVolPtr handle;
479 GVirStoragePoolPrivate *priv = pool->priv;
480
481 xml = gvir_config_object_get_doc(GVIR_CONFIG_OBJECT(conf));
482
483 g_return_val_if_fail(xml != NULL, NULL);
484
485 if (!(handle = virStorageVolCreateXML(priv->handle, xml, 0))) {
486 *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR,
487 0,
488 "Failed to create volume");
489 return NULL;
490 }
491
492 GVirStorageVol *volume;
493
494 volume = GVIR_STORAGE_VOL(g_object_new(GVIR_TYPE_STORAGE_VOL,
495 "handle", handle,
496 NULL));
497
498 g_mutex_lock(priv->lock);
499 g_hash_table_insert(priv->volumes,
500 g_strdup(gvir_storage_vol_get_name(volume)),
501 volume);
502 g_mutex_unlock(priv->lock);
503
504 return g_object_ref(volume);
505 }
0 /*
1 * libvirt-gobject-storage_pool.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_STORAGE_POOL_H__
27 #define __LIBVIRT_GOBJECT_STORAGE_POOL_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_STORAGE_POOL (gvir_storage_pool_get_type ())
32 #define GVIR_STORAGE_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_STORAGE_POOL, GVirStoragePool))
33 #define GVIR_STORAGE_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_STORAGE_POOL, GVirStoragePoolClass))
34 #define GVIR_IS_STORAGE_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_STORAGE_POOL))
35 #define GVIR_IS_STORAGE_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_STORAGE_POOL))
36 #define GVIR_STORAGE_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_STORAGE_POOL, GVirStoragePoolClass))
37
38 #define GVIR_TYPE_STORAGE_POOL_HANDLE (gvir_storage_pool_handle_get_type())
39
40 typedef struct _GVirStoragePool GVirStoragePool;
41 typedef struct _GVirStoragePoolPrivate GVirStoragePoolPrivate;
42 typedef struct _GVirStoragePoolClass GVirStoragePoolClass;
43
44 struct _GVirStoragePool
45 {
46 GObject parent;
47
48 GVirStoragePoolPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirStoragePoolClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60
61 GType gvir_storage_pool_get_type(void);
62 GType gvir_storage_pool_handle_get_type(void);
63
64 const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool);
65 gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool);
66
67 GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
68 guint64 flags,
69 GError **err);
70
71 gboolean gvir_storage_pool_refresh(GVirStoragePool *pool,
72 GCancellable *cancellable,
73 GError **err);
74 void gvir_storage_pool_refresh_async(GVirStoragePool *pool,
75 GCancellable *cancellable,
76 GAsyncReadyCallback callback,
77 gpointer opaque);
78 gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool,
79 GAsyncResult *result,
80 GError **err);
81
82 GList *gvir_storage_pool_get_volumes(GVirStoragePool *pool);
83 GVirStoragePool *gvir_storage_pool_get_volume(GVirStoragePool *pool,
84 const gchar *name);
85 GVirStorageVol *gvir_storage_pool_create_volume
86 (GVirStoragePool *pool,
87 GVirConfigStorageVol *conf,
88 GError **err);
89
90 G_END_DECLS
91
92 #endif /* __LIBVIRT_GOBJECT_STORAGE_POOL_H__ */
0 /*
1 * libvirt-gobject-storage_vol.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Daniel P. Berrange <berrange@redhat.com>
21 */
22
23 #include <config.h>
24
25 #include <libvirt/virterror.h>
26 #include <string.h>
27
28 #include "libvirt-glib/libvirt-glib.h"
29 #include "libvirt-gobject/libvirt-gobject.h"
30
31 extern gboolean debugFlag;
32
33 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
34
35 #define GVIR_STORAGE_VOL_GET_PRIVATE(obj) \
36 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_STORAGE_VOL, GVirStorageVolPrivate))
37
38 struct _GVirStorageVolPrivate
39 {
40 virStorageVolPtr handle;
41 };
42
43 G_DEFINE_TYPE(GVirStorageVol, gvir_storage_vol, G_TYPE_OBJECT);
44
45
46 enum {
47 PROP_0,
48 PROP_HANDLE,
49 };
50
51
52 #define GVIR_STORAGE_VOL_ERROR gvir_storage_vol_error_quark()
53
54
55 static GQuark
56 gvir_storage_vol_error_quark(void)
57 {
58 return g_quark_from_static_string("gvir-storage-vol");
59 }
60
61 static void gvir_storage_vol_get_property(GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec)
65 {
66 GVirStorageVol *conn = GVIR_STORAGE_VOL(object);
67 GVirStorageVolPrivate *priv = conn->priv;
68
69 switch (prop_id) {
70 case PROP_HANDLE:
71 g_value_set_boxed(value, priv->handle);
72 break;
73
74 default:
75 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
76 }
77 }
78
79
80 static void gvir_storage_vol_set_property(GObject *object,
81 guint prop_id,
82 const GValue *value,
83 GParamSpec *pspec)
84 {
85 GVirStorageVol *conn = GVIR_STORAGE_VOL(object);
86 GVirStorageVolPrivate *priv = conn->priv;
87
88 switch (prop_id) {
89 case PROP_HANDLE:
90 if (priv->handle)
91 virStorageVolFree(priv->handle);
92 priv->handle = g_value_dup_boxed(value);
93 break;
94
95 default:
96 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
97 }
98 }
99
100
101 static void gvir_storage_vol_finalize(GObject *object)
102 {
103 GVirStorageVol *conn = GVIR_STORAGE_VOL(object);
104 GVirStorageVolPrivate *priv = conn->priv;
105
106 DEBUG("Finalize GVirStorageVol=%p", conn);
107
108 virStorageVolFree(priv->handle);
109
110 G_OBJECT_CLASS(gvir_storage_vol_parent_class)->finalize(object);
111 }
112
113
114 static void gvir_storage_vol_class_init(GVirStorageVolClass *klass)
115 {
116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
117
118 object_class->finalize = gvir_storage_vol_finalize;
119 object_class->get_property = gvir_storage_vol_get_property;
120 object_class->set_property = gvir_storage_vol_set_property;
121
122 g_object_class_install_property(object_class,
123 PROP_HANDLE,
124 g_param_spec_boxed("handle",
125 "Handle",
126 "The storage_vol handle",
127 GVIR_TYPE_STORAGE_VOL_HANDLE,
128 G_PARAM_READABLE |
129 G_PARAM_WRITABLE |
130 G_PARAM_CONSTRUCT_ONLY |
131 G_PARAM_STATIC_NAME |
132 G_PARAM_STATIC_NICK |
133 G_PARAM_STATIC_BLURB));
134
135 g_type_class_add_private(klass, sizeof(GVirStorageVolPrivate));
136 }
137
138
139 static void gvir_storage_vol_init(GVirStorageVol *conn)
140 {
141 GVirStorageVolPrivate *priv;
142
143 DEBUG("Init GVirStorageVol=%p", conn);
144
145 priv = conn->priv = GVIR_STORAGE_VOL_GET_PRIVATE(conn);
146
147 memset(priv, 0, sizeof(*priv));
148 }
149
150 static gpointer
151 gvir_storage_vol_handle_copy(gpointer src)
152 {
153 virStorageVolRef(src);
154 return src;
155 }
156
157
158 GType gvir_storage_vol_handle_get_type(void)
159 {
160 static GType handle_type = 0;
161
162 if (G_UNLIKELY(handle_type == 0))
163 handle_type = g_boxed_type_register_static
164 ("GVirStorageVolHandle",
165 gvir_storage_vol_handle_copy,
166 (GBoxedFreeFunc)virStorageVolFree);
167
168 return handle_type;
169 }
170
171
172 const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol)
173 {
174 GVirStorageVolPrivate *priv = vol->priv;
175 const char *name;
176
177 if (!(name = virStorageVolGetName(priv->handle))) {
178 g_error("Failed to get storage_vol name on %p", priv->handle);
179 }
180
181 return name;
182 }
183
184 const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol)
185 {
186 GVirStorageVolPrivate *priv = vol->priv;
187 const char *path;
188
189 if (!(path = virStorageVolGetPath(priv->handle))) {
190 g_error("Failed to get storage_vol path on %p", priv->handle);
191 }
192
193 return path;
194 }
195
196 /**
197 * gvir_storage_vol_get_config:
198 * @vol: the storage_vol
199 * @flags: the flags
200 * Returns: (transfer full): the config
201 */
202 GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
203 guint64 flags,
204 GError **err)
205 {
206 GVirStorageVolPrivate *priv = vol->priv;
207 gchar *xml;
208
209 if (!(xml = virStorageVolGetXMLDesc(priv->handle, flags))) {
210 *err = gvir_error_new_literal(GVIR_STORAGE_VOL_ERROR,
211 0,
212 "Unable to get storage_vol XML config");
213 return NULL;
214 }
215
216 GVirConfigStorageVol *conf = gvir_config_storage_vol_new(xml);
217
218 g_free(xml);
219 return conf;
220 }
0 /*
1 * libvirt-gobject-storage_vol.c: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
23 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
24 #endif
25
26 #ifndef __LIBVIRT_GOBJECT_STORAGE_VOL_H__
27 #define __LIBVIRT_GOBJECT_STORAGE_VOL_H__
28
29 G_BEGIN_DECLS
30
31 #define GVIR_TYPE_STORAGE_VOL (gvir_storage_vol_get_type ())
32 #define GVIR_STORAGE_VOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_STORAGE_VOL, GVirStorageVol))
33 #define GVIR_STORAGE_VOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_STORAGE_VOL, GVirStorageVolClass))
34 #define GVIR_IS_STORAGE_VOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_STORAGE_VOL))
35 #define GVIR_IS_STORAGE_VOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_STORAGE_VOL))
36 #define GVIR_STORAGE_VOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_STORAGE_VOL, GVirStorageVolClass))
37
38 #define GVIR_TYPE_STORAGE_VOL_HANDLE (gvir_storage_vol_handle_get_type())
39
40 typedef struct _GVirStorageVol GVirStorageVol;
41 typedef struct _GVirStorageVolPrivate GVirStorageVolPrivate;
42 typedef struct _GVirStorageVolClass GVirStorageVolClass;
43
44 struct _GVirStorageVol
45 {
46 GObject parent;
47
48 GVirStorageVolPrivate *priv;
49
50 /* Do not add fields to this struct */
51 };
52
53 struct _GVirStorageVolClass
54 {
55 GObjectClass parent_class;
56
57 gpointer padding[20];
58 };
59
60 GType gvir_storage_vol_get_type(void);
61 GType gvir_storage_vol_handle_get_type(void);
62
63 const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol);
64 const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol);
65
66 GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol,
67 guint64 flags,
68 GError **err);
69
70 G_END_DECLS
71
72 #endif /* __LIBVIRT_GOBJECT_STORAGE_VOL_H__ */
0 /*
1 * libvirt-gobject-stream.c: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 * Copyright (C) 2010 Red Hat
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Authors: Daniel P. Berrange <berrange@redhat.com>
21 * Marc-André Lureau <marcandre.lureau@redhat.com>
22 */
23
24 #include <config.h>
25
26 #include <libvirt/virterror.h>
27 #include <string.h>
28
29 #include "libvirt-glib/libvirt-glib.h"
30 #include "libvirt-gobject/libvirt-gobject.h"
31
32 extern gboolean debugFlag;
33
34 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
35
36 #define GVIR_STREAM_GET_PRIVATE(obj) \
37 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_STREAM, GVirStreamPrivate))
38
39 struct _GVirStreamPrivate
40 {
41 virStreamPtr handle;
42 };
43
44 G_DEFINE_TYPE(GVirStream, gvir_stream, G_TYPE_OBJECT);
45
46
47 enum {
48 PROP_0,
49 PROP_HANDLE,
50 };
51
52
53 #define GVIR_STREAM_ERROR gvir_stream_error_quark()
54
55
56 static GQuark
57 gvir_stream_error_quark(void)
58 {
59 return g_quark_from_static_string("vir-g-stream");
60 }
61
62 static void gvir_stream_get_property(GObject *object,
63 guint prop_id,
64 GValue *value,
65 GParamSpec *pspec)
66 {
67 GVirStream *self = GVIR_STREAM(object);
68 GVirStreamPrivate *priv = self->priv;
69
70 switch (prop_id) {
71 case PROP_HANDLE:
72 g_value_set_boxed(value, priv->handle);
73 break;
74
75 default:
76 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
77 }
78 }
79
80
81 static void gvir_stream_set_property(GObject *object,
82 guint prop_id,
83 const GValue *value,
84 GParamSpec *pspec)
85 {
86 GVirStream *self = GVIR_STREAM(object);
87 GVirStreamPrivate *priv = self->priv;
88
89 switch (prop_id) {
90 case PROP_HANDLE:
91 if (priv->handle)
92 virStreamFree(priv->handle);
93 priv->handle = g_value_dup_boxed(value);
94 break;
95
96 default:
97 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
98 }
99 }
100
101
102 static void gvir_stream_finalize(GObject *object)
103 {
104 GVirStream *self = GVIR_STREAM(object);
105 GVirStreamPrivate *priv = self->priv;
106
107 DEBUG("Finalize GVirStream=%p", self);
108
109 if (priv->handle) {
110 if (virStreamFinish(priv->handle) < 0)
111 g_critical("cannot finish stream");
112
113 virStreamFree(priv->handle);
114 }
115
116 G_OBJECT_CLASS(gvir_stream_parent_class)->finalize(object);
117 }
118
119
120 static void gvir_stream_class_init(GVirStreamClass *klass)
121 {
122 GObjectClass *object_class = G_OBJECT_CLASS (klass);
123
124 object_class->finalize = gvir_stream_finalize;
125 object_class->get_property = gvir_stream_get_property;
126 object_class->set_property = gvir_stream_set_property;
127
128 g_object_class_install_property(object_class,
129 PROP_HANDLE,
130 g_param_spec_boxed("handle",
131 "Handle",
132 "The stream handle",
133 GVIR_TYPE_STREAM_HANDLE,
134 G_PARAM_READABLE |
135 G_PARAM_WRITABLE |
136 G_PARAM_CONSTRUCT_ONLY |
137 G_PARAM_STATIC_NAME |
138 G_PARAM_STATIC_NICK |
139 G_PARAM_STATIC_BLURB));
140
141 g_type_class_add_private(klass, sizeof(GVirStreamPrivate));
142 }
143
144
145 static void gvir_stream_init(GVirStream *self)
146 {
147 self->priv = GVIR_STREAM_GET_PRIVATE(self);
148 }
149
150
151 static gpointer
152 gvir_stream_handle_copy(gpointer src)
153 {
154 virStreamRef(src);
155 return src;
156 }
157
158
159 GType gvir_stream_handle_get_type(void)
160 {
161 static GType handle_type = 0;
162
163 if (G_UNLIKELY(handle_type == 0))
164 handle_type = g_boxed_type_register_static
165 ("GVirStreamHandle",
166 gvir_stream_handle_copy,
167 (GBoxedFreeFunc)virStreamFree);
168
169 return handle_type;
170 }
171
172
173 struct stream_sink_helper {
174 GVirStream *self;
175 GVirStreamSinkFunc func;
176 gpointer user_data;
177 };
178
179 static int
180 stream_sink(virStreamPtr st G_GNUC_UNUSED,
181 const char *bytes, size_t nbytes, void *opaque)
182 {
183 struct stream_sink_helper *helper = opaque;
184
185 return helper->func(helper->self, bytes, nbytes, helper->user_data);
186 }
187
188 /**
189 * gvir_stream_receive_all:
190 * @stream: the stream
191 * @func: (scope notified): the callback for writing data to application
192 * @user_data: (closure): data to be passed to @callback
193 *
194 * Receive the entire data stream, sending the data to the
195 * requested data sink. This is simply a convenient alternative
196 * to virStreamRecv, for apps that do blocking-I/o.
197 */
198 gint
199 gvir_stream_receive_all(GVirStream *self, GVirStreamSinkFunc func, gpointer user_data, GError **err)
200 {
201 struct stream_sink_helper helper = {
202 .self = self,
203 .func = func,
204 .user_data = user_data
205 };
206 int r;
207
208 g_return_val_if_fail(GVIR_IS_STREAM(self), -1);
209 g_return_val_if_fail(func != NULL, -1);
210
211 r = virStreamRecvAll(self->priv->handle, stream_sink, &helper);
212 if (r < 0) {
213 if (err != NULL)
214 *err = gvir_error_new_literal(GVIR_STREAM_ERROR,
215 0,
216 "Unable to perform RecvAll");
217 }
218
219 return r;
220 }
0 /*
1 * libvirt-gobject-stream.h: libvirt gobject integration
2 *
3 * Copyright (C) 2011 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors: Daniel P. Berrange <berrange@redhat.com>
20 * Marc-André Lureau <marcandre.lureau@redhat.com>
21 */
22
23 #if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD)
24 #error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly."
25 #endif
26
27 #ifndef __LIBVIRT_GOBJECT_STREAM_H__
28 #define __LIBVIRT_GOBJECT_STREAM_H__
29
30 G_BEGIN_DECLS
31
32 #define GVIR_TYPE_STREAM (gvir_stream_get_type ())
33 #define GVIR_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_STREAM, GVirStream))
34 #define GVIR_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_STREAM, GVirStreamClass))
35 #define GVIR_IS_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_STREAM))
36 #define GVIR_IS_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_STREAM))
37 #define GVIR_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_STREAM, GVirStreamClass))
38
39 #define GVIR_TYPE_STREAM_HANDLE (gvir_stream_handle_get_type())
40
41 typedef struct _GVirStream GVirStream;
42 typedef struct _GVirStreamPrivate GVirStreamPrivate;
43 typedef struct _GVirStreamClass GVirStreamClass;
44
45 struct _GVirStream
46 {
47 GObject parent;
48
49 GVirStreamPrivate *priv;
50
51 /* Do not add fields to this struct */
52 };
53
54 struct _GVirStreamClass
55 {
56 GObjectClass parent_class;
57
58 gpointer padding[20];
59 };
60
61 /**
62 * GVirStreamSinkFunc:
63 * @stream: a #GVirStream
64 * @buf: data pointer
65 * @nbytes: data size
66 * @user_data: user data passed to the function
67 */
68 typedef gint (* GVirStreamSinkFunc) (GVirStream *stream,
69 const gchar *buf,
70 gsize nbytes,
71 gpointer user_data);
72
73 GType gvir_stream_get_type(void);
74 GType gvir_stream_handle_get_type(void);
75
76 gint gvir_stream_receive_all(GVirStream *stream, GVirStreamSinkFunc func, gpointer user_data, GError **err);
77
78 G_END_DECLS
79
80 #endif /* __LIBVIRT_GOBJECT_STREAM_H__ */
0 /*
1 * libvirt-gobject.h: libvirt gobject integration
2 *
3 * Copyright (C) 2010 Red Hat
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22 #ifndef __LIBVIRT_GOBJECT_H__
23 #define __LIBVIRT_GOBJECT_H__
24
25 #include <glib-object.h>
26 #include <gio/gio.h>
27 #include <libvirt-gconfig/libvirt-gconfig.h>
28
29 #include <libvirt-gobject/libvirt-gobject-main.h>
30 #include <libvirt-gobject/libvirt-gobject-enums.h>
31 #include <libvirt-gobject/libvirt-gobject-stream.h>
32 #include <libvirt-gobject/libvirt-gobject-domain-snapshot.h>
33 #include <libvirt-gobject/libvirt-gobject-domain.h>
34 #include <libvirt-gobject/libvirt-gobject-interface.h>
35 #include <libvirt-gobject/libvirt-gobject-network.h>
36 #include <libvirt-gobject/libvirt-gobject-network-filter.h>
37 #include <libvirt-gobject/libvirt-gobject-node-device.h>
38 #include <libvirt-gobject/libvirt-gobject-secret.h>
39 #include <libvirt-gobject/libvirt-gobject-storage-vol.h>
40 #include <libvirt-gobject/libvirt-gobject-storage-pool.h>
41 #include <libvirt-gobject/libvirt-gobject-connection.h>
42 #include <libvirt-gobject/libvirt-gobject-manager.h>
43
44 #endif /* __LIBVIRT_GOBJECT_H__ */
0 LIBVIRT_GOBJECT_0.0.1 {
1 global:
2 gvir_init_object;
3 gvir_init_object_check;
4
5 gvir_connection_get_type;
6 gvir_connection_new;
7 gvir_connection_open;
8 gvir_connection_open_async;
9 gvir_connection_open_finish;
10 gvir_connection_is_open;
11 gvir_connection_close;
12 gvir_connection_get_uri;
13 gvir_connection_get_stream;
14
15 gvir_connection_fetch_domains;
16 gvir_connection_fetch_storage_pools;
17 gvir_connection_fetch_storage_pools_async;
18 gvir_connection_fetch_storage_pools_finish;
19 gvir_connection_get_domains;
20 gvir_connection_get_storage_pools;
21 gvir_connection_get_domain;
22 gvir_connection_get_storage_pool;
23 gvir_connection_find_domain_by_id;
24 gvir_connection_find_domain_by_name;
25 gvir_connection_find_storage_pool_by_name;
26 gvir_connection_create_domain;
27
28 gvir_domain_get_type;
29 gvir_domain_handle_get_type;
30 gvir_domain_info_get_type;
31 gvir_domain_state_get_type;
32 gvir_domain_get_name;
33 gvir_domain_get_uuid;
34 gvir_domain_get_id;
35 gvir_domain_start;
36 gvir_domain_stop;
37 gvir_domain_delete;
38 gvir_domain_shutdown;
39 gvir_domain_reboot;
40 gvir_domain_get_config;
41 gvir_domain_get_info;
42 gvir_domain_screenshot;
43
44 gvir_domain_snapshot_get_type;
45 gvir_domain_snapshot_handle_get_type;
46 gvir_domain_snapshot_get_name;
47 gvir_domain_snapshot_get_config;
48
49 gvir_network_get_type;
50 gvir_network_handle_get_type;
51 gvir_network_get_name;
52 gvir_network_get_uuid;
53 gvir_network_get_config;
54
55 gvir_network_filter_get_type;
56 gvir_network_filter_handle_get_type;
57 gvir_network_filter_get_name;
58 gvir_network_filter_get_uuid;
59 gvir_network_filter_get_config;
60
61 gvir_node_device_get_type;
62 gvir_node_device_handle_get_type;
63 gvir_node_device_get_name;
64 gvir_node_device_get_config;
65
66 gvir_interface_get_type;
67 gvir_interface_handle_get_type;
68 gvir_interface_get_name;
69 gvir_interface_get_config;
70
71 gvir_secret_get_type;
72 gvir_secret_handle_get_type;
73 gvir_secret_get_uuid;
74 gvir_secret_get_config;
75
76 gvir_storage_pool_get_type;
77 gvir_storage_pool_handle_get_type;
78 gvir_storage_pool_get_name;
79 gvir_storage_pool_get_uuid;
80 gvir_storage_pool_get_config;
81 gvir_storage_pool_refresh;
82 gvir_storage_pool_refresh_async;
83 gvir_storage_pool_refresh_finish;
84 gvir_storage_pool_get_volumes;
85 gvir_storage_pool_get_volume;
86 gvir_storage_pool_create_volume;
87
88 gvir_storage_vol_get_type;
89 gvir_storage_vol_handle_get_type;
90 gvir_storage_vol_get_name;
91 gvir_storage_vol_get_path;
92 gvir_storage_vol_get_config;
93
94 gvir_connection_handle_get_type;
95
96 gvir_manager_get_type;
97 gvir_manager_new;
98 gvir_manager_add_connection;
99 gvir_manager_remove_connection;
100 gvir_manager_get_connections;
101 gvir_manager_find_connection_by_uri;
102
103 gvir_stream_get_type;
104 gvir_stream_receive_all;
105 gvir_stream_handle_get_type;
106
107 local:
108 *;
109 };
110
111 # .... define new API here using predicted next version number ....
0 prefix=@prefix@
1 exec_prefix=@exec_prefix@
2 libdir=@libdir@
3 includedir=@includedir@
4
5 Name: libvirt-gobject
6 Version: @VERSION@
7 Description: libvirt GObject library
8 Requires: gobject-2.0 libvirt-gconfig-1.0
9 Libs: -L${libdir} -lvirt-gobject-1.0
10 Libs.private: @LIBVIRT_LIBS
11 Cflags: -I${includedir}/libvirt-gobject-1.0
2121
2222 BuildArch: noarch
2323
24 %package -n mingw32-libvirt-gconfig
25 Summary: MingwGW Windows libvirt-gconfig virtualization library
26 Group: Development/Libraries
27
28 %package -n mingw32-libvirt-gobject
29 Summary: MingwGW Windows libvirt-gobject virtualization library
30 Group: Development/Libraries
2431
2532 %description
2633 MinGW Windows libvirt-glib virtualization library.
34
35 %description -n mingw32-libvirt-gconfig
36 MinGW Windows libvirt-gconfig virtualization library.
37
38 %description -n mingw32-libvirt-gobject
39 MinGW Windows libvirt-gobject virtualization library.
2740
2841
2942 %prep
4154
4255 make DESTDIR=$RPM_BUILD_ROOT install
4356
44 rm $RPM_BUILD_ROOT%{_mingw32_libdir}/libvirt-glib.a
57 rm $RPM_BUILD_ROOT%{_mingw32_libdir}/libvirt-glib-1.0.a
58 rm $RPM_BUILD_ROOT%{_mingw32_libdir}/libvirt-gconfig-1.0.a
59 rm $RPM_BUILD_ROOT%{_mingw32_libdir}/libvirt-gobject-1.0.a
4560
4661
4762 %clean
5065
5166 %files
5267 %defattr(-,root,root)
53 %{_mingw32_bindir}/libvirt-glib-0.dll
68 %{_mingw32_bindir}/libvirt-glib-1.0-0.dll
5469
55 %{_mingw32_libdir}/libvirt-glib.dll.a
56 %{_mingw32_libdir}/libvirt-glib.la
57 %{_mingw32_libdir}/pkgconfig/libvirt-glib.pc
70 %{_mingw32_libdir}/libvirt-glib-1.0.dll.a
71 %{_mingw32_libdir}/libvirt-glib-1.0.la
5872
59 %dir %{_mingw32_includedir}/libvirt-glib
60 %{_mingw32_includedir}/libvirt-glib/libvirt-glib.h
73 %{_mingw32_libdir}/pkgconfig/libvirt-glib-1.0.pc
74
75 %dir %{_mingw32_includedir}/libvirt-glib-1.0
76 %dir %{_mingw32_includedir}/libvirt-glib-1.0/libvirt-glib
77 %{_mingw32_includedir}/libvirt-glib-1.0/libvirt-glib/libvirt-glib.h
78 %{_mingw32_includedir}/libvirt-glib-1.0/libvirt-glib/libvirt-glib-*.h
79
80 %files -n mingw32-libvirt-gconfig
81 %defattr(-,root,root)
82 %{_mingw32_bindir}/libvirt-gconfig-1.0-0.dll
83
84 %{_mingw32_libdir}/libvirt-gconfig-1.0.dll.a
85 %{_mingw32_libdir}/libvirt-gconfig-1.0.la
86
87 %{_mingw32_libdir}/pkgconfig/libvirt-gconfig-1.0.pc
88
89 %dir %{_mingw32_includedir}/libvirt-gconfig-1.0
90 %dir %{_mingw32_includedir}/libvirt-gconfig-1.0/libvirt-gconfig
91 %{_mingw32_includedir}/libvirt-gconfig-1.0/libvirt-gconfig/libvirt-gconfig.h
92 %{_mingw32_includedir}/libvirt-gconfig-1.0/libvirt-gconfig/libvirt-gconfig-*.h
93
94 %files -n mingw32-libvirt-gobject
95 %defattr(-,root,root)
96 %{_mingw32_bindir}/libvirt-gobject-1.0-0.dll
97
98 %{_mingw32_libdir}/libvirt-gobject-1.0.dll.a
99 %{_mingw32_libdir}/libvirt-gobject-1.0.la
100
101 %{_mingw32_libdir}/pkgconfig/libvirt-gobject-1.0.pc
102
103 %dir %{_mingw32_includedir}/libvirt-gobject-1.0
104 %dir %{_mingw32_includedir}/libvirt-gobject-1.0/libvirt-gobject
105 %{_mingw32_includedir}/libvirt-gobject-1.0/libvirt-gobject/libvirt-gobject.h
106 %{_mingw32_includedir}/libvirt-gobject-1.0/libvirt-gobject/libvirt-gobject-*.h
61107
62108
63109 %changelog
22 INCLUDES = \
33 $(WARN_CFLAGS) \
44 -I$(PYTHON_INCLUDES) \
5 -I$(top_srcdir)/include \
6 -I$(top_builddir)/include \
7 -I$(top_builddir)/$(subdir) \
5 -I$(top_srcdir) \
86 $(GLIB2_CFLAGS)
97
108 EXTRA_DIST = libvirtglib.py
1816
1917 libvirtglibmod_la_LDFLAGS = -module -avoid-version \
2018 $(CYGWIN_EXTRA_LDFLAGS)
21 libvirtglibmod_la_LIBADD = ../src/libvirt-glib.la
19 libvirtglibmod_la_LIBADD = ../libvirt-glib/libvirt-glib-1.0.la
2220 $(CYGWIN_EXTRA_LIBADD) $(CYGWIN_EXTRA_PYTHON_LIBADD)
2321
2422
2525 #define VIR_PY_NONE (Py_INCREF (Py_None), Py_None)
2626
2727 static PyObject *
28 libvirt_virEventRegisterGLib(PyObject *self G_GNUC_UNUSED, PyObject *args G_GNUC_UNUSED) {
29 virEventRegisterGLib();
28 libvirt_gvir_event_register(PyObject *self G_GNUC_UNUSED, PyObject *args G_GNUC_UNUSED) {
29 gvir_event_register();
3030
3131 return VIR_PY_NONE;
3232 }
3333
3434
3535 static PyMethodDef libvirtGLibMethods[] = {
36 {(char *) "virEventRegisterGLib", libvirt_virEventRegisterGLib, METH_VARARGS, NULL},
36 {(char *) "event_register", libvirt_gvir_event_register, METH_VARARGS, NULL},
3737 {NULL, NULL, 0, NULL}
3838 };
3939
4545 #endif
4646 (void)
4747 {
48 gvir_init(NULL, NULL);
4849 /* initialize the python extension module */
4950 Py_InitModule((char *)
5051 #ifndef __CYGWIN__
55 import cygvirtglibmod as libvirtglibmod
66
77
8 def eventRegister():
9 libvirtglibmod.virEventRegisterGLib()
8 def event_register():
9 libvirtglibmod.event_register()
1010
+0
-21
src/Makefile.am less more
0
1 EXTRA_DIST = libvirt_glib.sym
2
3 lib_LTLIBRARIES = libvirt-glib.la
4
5 libvirt_glib_la_SOURCES = events.c
6 libvirt_glib_la_CFLAGS = \
7 $(COVERAGE_CFLAGS) \
8 -I$(top_srcdir)/include \
9 ../include \
10 $(LIBVIRT_CFLAGS) \
11 $(GLIB2_CFLAGS)
12 libvirt_glib_la_LIBADD = \
13 $(LIBVIRT_LIBS) \
14 $(GLIB2_LIBS) \
15 $(CYGWIN_EXTRA_LIBADD)
16 libvirt_glib_la_LDFLAGS = \
17 $(COVERAGE_CFLAGS:-f%=-Wc,f%) \
18 $(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS) \
19 -Wl,--version-script=$(srcdir)/libvirt_glib.sym \
20 -version-info $(LIBVIRT_GLIB_VERSION_INFO)
+0
-318
src/events.c less more
0 /*
1 * libvirt-glib.h: libvirt glib integration
2 *
3 * Copyright (C) 2008 Daniel P. Berrange
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Daniel P. Berrange <berrange@redhat.com>
20 */
21
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <glib.h>
27 #include <libvirt/libvirt.h>
28
29 static gboolean debugFlag = FALSE;
30
31 #define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0)
32
33 struct virHandleGLib
34 {
35 int watch;
36 int fd;
37 int events;
38 int enabled;
39 GIOChannel *channel;
40 guint source;
41 virEventHandleCallback cb;
42 void *opaque;
43 virFreeCallback ff;
44 };
45
46 static int nextwatch = 1;
47 static unsigned int nhandles = 0;
48 static struct virHandleGLib **handles = NULL;
49
50 static gboolean
51 virEventDispatchHandleGLib(GIOChannel *source,
52 GIOCondition condition,
53 gpointer opaque)
54 {
55 struct virHandleGLib *data = opaque;
56 int events = 0;
57
58 if (condition & G_IO_IN)
59 events |= VIR_EVENT_HANDLE_READABLE;
60 if (condition & G_IO_OUT)
61 events |= VIR_EVENT_HANDLE_WRITABLE;
62 if (condition & G_IO_HUP)
63 events |= VIR_EVENT_HANDLE_HANGUP;
64 if (condition & G_IO_ERR)
65 events |= VIR_EVENT_HANDLE_ERROR;
66
67 DEBUG("Dispatch handler %d %d %p\n", data->fd, events, data->opaque);
68
69 (data->cb)(data->watch, data->fd, events, data->opaque);
70
71 return TRUE;
72 }
73
74
75 int virEventAddHandleGLib(int fd,
76 int events,
77 virEventHandleCallback cb,
78 void *opaque,
79 virFreeCallback ff)
80 {
81 struct virHandleGLib *data;
82 GIOCondition cond = 0;
83
84 handles = g_realloc(handles, sizeof(*handles)*(nhandles+1));
85 data = g_malloc(sizeof(*data));
86 memset(data, 0, sizeof(*data));
87
88 if (events & VIR_EVENT_HANDLE_READABLE)
89 cond |= G_IO_IN;
90 if (events & VIR_EVENT_HANDLE_WRITABLE)
91 cond |= G_IO_OUT;
92
93 data->watch = nextwatch++;
94 data->fd = fd;
95 data->events = events;
96 data->cb = cb;
97 data->opaque = opaque;
98 data->channel = g_io_channel_unix_new(fd);
99 data->ff = ff;
100
101 DEBUG("Add handle %d %d %p\n", data->fd, events, data->opaque);
102
103 data->source = g_io_add_watch(data->channel,
104 cond,
105 virEventDispatchHandleGLib,
106 data);
107
108 handles[nhandles++] = data;
109
110 return data->watch;
111 }
112
113 static struct virHandleGLib *
114 virEventFindHandle(int watch)
115 {
116 unsigned int i;
117 for (i = 0 ; i < nhandles ; i++)
118 if (handles[i]->watch == watch)
119 return handles[i];
120
121 return NULL;
122 }
123
124 void virEventUpdateHandleGLib(int watch,
125 int events)
126 {
127 struct virHandleGLib *data = virEventFindHandle(watch);
128
129 if (!data) {
130 DEBUG("Update for missing handle watch %d", watch);
131 return;
132 }
133
134 if (events) {
135 GIOCondition cond = 0;
136 if (events == data->events)
137 return;
138
139 if (data->source)
140 g_source_remove(data->source);
141
142 cond |= G_IO_HUP;
143 if (events & VIR_EVENT_HANDLE_READABLE)
144 cond |= G_IO_IN;
145 if (events & VIR_EVENT_HANDLE_WRITABLE)
146 cond |= G_IO_OUT;
147 data->source = g_io_add_watch(data->channel,
148 cond,
149 virEventDispatchHandleGLib,
150 data);
151 data->events = events;
152 } else {
153 if (!data->source)
154 return;
155
156 g_source_remove(data->source);
157 data->source = 0;
158 data->events = 0;
159 }
160 }
161
162 int virEventRemoveHandleGLib(int watch)
163 {
164 struct virHandleGLib *data = virEventFindHandle(watch);
165
166 if (!data) {
167 DEBUG("Remove of missing watch %d", watch);
168 return -1;
169 }
170
171 DEBUG("Remove handle %d %d\n", watch, data->fd);
172
173 g_source_remove(data->source);
174 data->source = 0;
175 data->events = 0;
176 if (data->ff)
177 (data->ff)(data->opaque);
178 free(data);
179
180 return 0;
181 }
182
183 struct virTimeoutGLib
184 {
185 int timer;
186 int interval;
187 guint source;
188 virEventTimeoutCallback cb;
189 void *opaque;
190 virFreeCallback ff;
191 };
192
193
194 static int nexttimer = 1;
195 static unsigned int ntimeouts = 0;
196 static struct virTimeoutGLib **timeouts = NULL;
197
198 static gboolean
199 virEventDispatchTimeoutGLib(void *opaque)
200 {
201 struct virTimeoutGLib *data = opaque;
202 DEBUG("Dispatch timeout %p %p %p %p\n", data, data->cb, data->timer, data->opaque);
203 (data->cb)(data->timer, data->opaque);
204
205 return TRUE;
206 }
207
208 static int
209 virEventAddTimeoutGLib(int interval,
210 virEventTimeoutCallback cb,
211 void *opaque,
212 virFreeCallback ff)
213 {
214 struct virTimeoutGLib *data;
215
216 timeouts = g_realloc(timeouts, sizeof(*timeouts)*(ntimeouts+1));
217 data = g_malloc(sizeof(*data));
218 memset(data, 0, sizeof(*data));
219
220 data->timer = nexttimer++;
221 data->interval = interval;
222 data->cb = cb;
223 data->opaque = opaque;
224 data->ff = ff;
225 if (interval >= 0)
226 data->source = g_timeout_add(interval,
227 virEventDispatchTimeoutGLib,
228 data);
229
230 timeouts[ntimeouts++] = data;
231
232 DEBUG("Add timeout %p %d %p %p %d\n", data, interval, cb, opaque, data->timer);
233
234 return data->timer;
235 }
236
237
238 static struct virTimeoutGLib *
239 virEventFindTimer(int timer)
240 {
241 unsigned int i;
242 for (i = 0 ; i < ntimeouts ; i++)
243 if (timeouts[i]->timer == timer)
244 return timeouts[i];
245
246 return NULL;
247 }
248
249
250 void virEventUpdateTimeoutGLib(int timer,
251 int interval)
252 {
253 struct virTimeoutGLib *data = virEventFindTimer(timer);
254
255 if (!data) {
256 DEBUG("Update of missing timer %d", timer);
257 return;
258 }
259
260 DEBUG("Update timeout %p %d %d\n", data, timer, interval);
261
262 if (interval >= 0) {
263 if (data->source)
264 return;
265
266 data->interval = interval;
267 data->source = g_timeout_add(data->interval,
268 virEventDispatchTimeoutGLib,
269 data);
270 } else {
271 if (!data->source)
272 return;
273
274 g_source_remove(data->source);
275 data->source = 0;
276 }
277 }
278
279 int virEventRemoveTimeoutGLib(int timer)
280 {
281 struct virTimeoutGLib *data = virEventFindTimer(timer);
282
283 if (!data) {
284 DEBUG("Remove of missing timer %d", timer);
285 return -1;
286 }
287
288 DEBUG("Remove timeout %p %d\n", data, timer);
289
290 if (!data->source)
291 return -1;
292
293 g_source_remove(data->source);
294 data->source = 0;
295
296 if (data->ff)
297 (data->ff)(data->opaque);
298
299 free(data);
300
301 return 0;
302 }
303
304
305 void virEventRegisterGLib(void) {
306 char *debugEnv = getenv("LIBVIRT_GLIB_DEBUG");
307 if (debugEnv && *debugEnv && *debugEnv != '0')
308 debugFlag = 1;
309
310 virEventRegisterImpl(virEventAddHandleGLib,
311 virEventUpdateHandleGLib,
312 virEventRemoveHandleGLib,
313 virEventAddTimeoutGLib,
314 virEventUpdateTimeoutGLib,
315 virEventRemoveTimeoutGLib);
316 }
317
+0
-7
src/libvirt_glib.sym less more
0 {
1 global:
2 virEventRegisterGLib;
3
4 local:
5 *;
6 };