New upstream version 0.0.2
Guido Günther
12 years ago
0 | ||
1 | 0 | GNU LESSER GENERAL PUBLIC LICENSE |
2 | 1 | Version 2.1, February 1999 |
3 | 2 | |
4 | 3 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
4 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
6 | 5 | Everyone is permitted to copy and distribute verbatim copies |
7 | 6 | of this license document, but changing it is not allowed. |
8 | 7 | |
22 | 21 | Free Software Foundation and other authors who decide to use it. You |
23 | 22 | can use it too, but we suggest you first think carefully about whether |
24 | 23 | this license or the ordinary General Public License is the better |
25 | strategy to use in any particular case, based on the explanations | |
26 | below. | |
24 | strategy to use in any particular case, based on the explanations below. | |
27 | 25 | |
28 | 26 | When we speak of free software, we are referring to freedom of use, |
29 | 27 | not price. Our General Public Licenses are designed to make sure that |
56 | 54 | that what they have is not the original version, so that the original |
57 | 55 | author's reputation will not be affected by problems that might be |
58 | 56 | introduced by others. |
59 | ^L | |
57 | ||
60 | 58 | Finally, software patents pose a constant threat to the existence of |
61 | 59 | any free program. We wish to make sure that a company cannot |
62 | 60 | effectively restrict the users of a free program by obtaining a |
88 | 86 | special circumstances. |
89 | 87 | |
90 | 88 | For example, on rare occasions, there may be a special need to |
91 | encourage the widest possible use of a certain library, so that it | |
92 | becomes a de-facto standard. To achieve this, non-free programs must | |
93 | be allowed to use the library. A more frequent case is that a free | |
89 | encourage the widest possible use of a certain library, so that it becomes | |
90 | a de-facto standard. To achieve this, non-free programs must be | |
91 | allowed to use the library. A more frequent case is that a free | |
94 | 92 | library does the same job as widely used non-free libraries. In this |
95 | 93 | case, there is little to gain by limiting the free library to free |
96 | 94 | software only, so we use the Lesser General Public License. |
112 | 110 | "work based on the library" and a "work that uses the library". The |
113 | 111 | former contains code derived from the library, whereas the latter must |
114 | 112 | be combined with the library in order to run. |
115 | ^L | |
113 | ||
116 | 114 | GNU LESSER GENERAL PUBLIC LICENSE |
117 | 115 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
118 | 116 | |
137 | 135 | "Source code" for a work means the preferred form of the work for |
138 | 136 | making modifications to it. For a library, complete source code means |
139 | 137 | all the source code for all modules it contains, plus any associated |
140 | interface definition files, plus the scripts used to control | |
141 | compilation and installation of the library. | |
138 | interface definition files, plus the scripts used to control compilation | |
139 | and installation of the library. | |
142 | 140 | |
143 | 141 | Activities other than copying, distribution and modification are not |
144 | 142 | covered by this License; they are outside its scope. The act of |
217 | 215 | ordinary GNU General Public License has appeared, then you can specify |
218 | 216 | that version instead if you wish.) Do not make any other change in |
219 | 217 | these notices. |
220 | ^L | |
218 | ||
221 | 219 | Once this change is made in a given copy, it is irreversible for |
222 | 220 | that copy, so the ordinary GNU General Public License applies to all |
223 | 221 | subsequent copies and derivative works made from that copy. |
268 | 266 | distribute the object code for the work under the terms of Section 6. |
269 | 267 | Any executables containing that work also fall under Section 6, |
270 | 268 | whether or not they are linked directly with the Library itself. |
271 | ^L | |
269 | ||
272 | 270 | 6. As an exception to the Sections above, you may also combine or |
273 | 271 | link a "work that uses the Library" with the Library to produce a |
274 | 272 | work containing portions of the Library, and distribute that work |
304 | 302 | the user installs one, as long as the modified version is |
305 | 303 | interface-compatible with the version that the work was made with. |
306 | 304 | |
307 | c) Accompany the work with a written offer, valid for at least | |
308 | three years, to give the same user the materials specified in | |
309 | Subsection 6a, above, for a charge no more than the cost of | |
310 | performing this distribution. | |
305 | c) Accompany the work with a written offer, valid for at | |
306 | least three years, to give the same user the materials | |
307 | specified in Subsection 6a, above, for a charge no more | |
308 | than the cost of performing this distribution. | |
311 | 309 | |
312 | 310 | d) If distribution of the work is made by offering access to copy |
313 | 311 | from a designated place, offer equivalent access to copy the above |
330 | 328 | accompany the operating system. Such a contradiction means you cannot |
331 | 329 | use both them and the Library together in an executable that you |
332 | 330 | distribute. |
333 | ^L | |
331 | ||
334 | 332 | 7. You may place library facilities that are a work based on the |
335 | 333 | Library side-by-side in a single library together with other library |
336 | 334 | facilities not covered by this License, and distribute such a combined |
371 | 369 | restrictions on the recipients' exercise of the rights granted herein. |
372 | 370 | You are not responsible for enforcing compliance by third parties with |
373 | 371 | this License. |
374 | ^L | |
372 | ||
375 | 373 | 11. If, as a consequence of a court judgment or allegation of patent |
376 | 374 | infringement or for any other reason (not limited to patent issues), |
377 | 375 | conditions are imposed on you (whether by court order, agreement or |
385 | 383 | the only way you could satisfy both it and this License would be to |
386 | 384 | refrain entirely from distribution of the Library. |
387 | 385 | |
388 | If any portion of this section is held invalid or unenforceable under | |
389 | any particular circumstance, the balance of the section is intended to | |
390 | apply, and the section as a whole is intended to apply in other | |
391 | circumstances. | |
386 | If any portion of this section is held invalid or unenforceable under any | |
387 | particular circumstance, the balance of the section is intended to apply, | |
388 | and the section as a whole is intended to apply in other circumstances. | |
392 | 389 | |
393 | 390 | It is not the purpose of this section to induce you to infringe any |
394 | 391 | patents or other property right claims or to contest validity of any |
406 | 403 | |
407 | 404 | 12. If the distribution and/or use of the Library is restricted in |
408 | 405 | certain countries either by patents or by copyrighted interfaces, the |
409 | original copyright holder who places the Library under this License | |
410 | may add an explicit geographical distribution limitation excluding those | |
411 | countries, so that distribution is permitted only in or among | |
412 | countries not thus excluded. In such case, this License incorporates | |
413 | the limitation as if written in the body of this License. | |
406 | original copyright holder who places the Library under this License may add | |
407 | an explicit geographical distribution limitation excluding those countries, | |
408 | so that distribution is permitted only in or among countries not thus | |
409 | excluded. In such case, this License incorporates the limitation as if | |
410 | written in the body of this License. | |
414 | 411 | |
415 | 412 | 13. The Free Software Foundation may publish revised and/or new |
416 | 413 | versions of the Lesser General Public License from time to time. |
424 | 421 | the Free Software Foundation. If the Library does not specify a |
425 | 422 | license version number, you may choose any version ever published by |
426 | 423 | the Free Software Foundation. |
427 | ^L | |
424 | ||
428 | 425 | 14. If you wish to incorporate parts of the Library into other free |
429 | 426 | programs whose distribution conditions are incompatible with these, |
430 | 427 | write to the author to ask for permission. For software which is |
458 | 455 | DAMAGES. |
459 | 456 | |
460 | 457 | END OF TERMS AND CONDITIONS |
461 | ^L | |
458 | ||
462 | 459 | How to Apply These Terms to Your New Libraries |
463 | 460 | |
464 | 461 | If you develop a new library, and you want it to be of the greatest |
465 | 462 | possible use to the public, we recommend making it free software that |
466 | 463 | everyone can redistribute and change. You can do so by permitting |
467 | redistribution under these terms (or, alternatively, under the terms | |
468 | of the ordinary General Public License). | |
469 | ||
470 | To apply these terms, attach the following notices to the library. | |
471 | It is safest to attach them to the start of each source file to most | |
472 | effectively convey the exclusion of warranty; and each file should | |
473 | have at least the "copyright" line and a pointer to where the full | |
474 | notice is found. | |
475 | ||
464 | redistribution under these terms (or, alternatively, under the terms of the | |
465 | ordinary General Public License). | |
466 | ||
467 | To apply these terms, attach the following notices to the library. It is | |
468 | safest to attach them to the start of each source file to most effectively | |
469 | convey the exclusion of warranty; and each file should have at least the | |
470 | "copyright" line and a pointer to where the full notice is found. | |
476 | 471 | |
477 | 472 | <one line to give the library's name and a brief idea of what it does.> |
478 | 473 | Copyright (C) <year> <name of author> |
489 | 484 | |
490 | 485 | You should have received a copy of the GNU Lesser General Public |
491 | 486 | License along with this library; if not, write to the Free Software |
492 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
487 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
493 | 488 | |
494 | 489 | Also add information on how to contact you by electronic and paper mail. |
495 | 490 | |
496 | You should also get your employer (if you work as a programmer) or | |
497 | your school, if any, to sign a "copyright disclaimer" for the library, | |
498 | if necessary. Here is a sample; alter the names: | |
491 | You should also get your employer (if you work as a programmer) or your | |
492 | school, if any, to sign a "copyright disclaimer" for the library, if | |
493 | necessary. Here is a sample; alter the names: | |
499 | 494 | |
500 | 495 | Yoyodyne, Inc., hereby disclaims all copyright interest in the |
501 | library `Frob' (a library for tweaking knobs) written by James | |
502 | Random Hacker. | |
496 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. | |
503 | 497 | |
504 | 498 | <signature of Ty Coon>, 1 April 1990 |
505 | 499 | Ty Coon, President of Vice |
506 | 500 | |
507 | 501 | That's all there is to it! |
508 | ||
509 |
0 | 2011-11-22 Daniel P. Berrange <berrange@redhat.com> | |
1 | ||
2 | Update NEWs with more 0.0.2 release notes | |
3 | ||
4 | Update COPYING file to have newer FSF address | |
5 | ||
6 | Update RPM specfile with latest Fedora review feedback | |
7 | ||
8 | Don't reference GError **err parameter if it is NULL | |
9 | ||
10 | Ensure domains & pools hash tables in connection are non-NULL | |
11 | ||
12 | Add API for creating transient domains | |
13 | ||
14 | Uncomment & fix code for returning config objects | |
15 | ||
16 | Change all flags from guint64 to guint to match libvirt type | |
17 | ||
18 | Add support for writing to streams | |
19 | ||
20 | 2011-11-22 Zeeshan Ali (Khattak) <zeeshanak@gnome.org> | |
21 | ||
22 | Release 0.0.2 | |
23 | ||
24 | 2011-11-21 Zeeshan Ali (Khattak) <zeeshanak@gnome.org> | |
25 | ||
26 | Add API to redefine an existing domain | |
27 | ||
28 | 2011-11-18 Guido Günther <agx@sigxcpu.org> | |
29 | ||
30 | Adjust example to pygobject-3.0 | |
31 | which doesn't allow to "import gtk" anymore. Use the gir version | |
32 | instead. | |
33 | ||
34 | 2011-11-17 Daniel P. Berrange <berrange@redhat.com> | |
35 | ||
36 | Add libxml-2.0 to libvirt-gconfig-1.0.pc | |
37 | The libvirt-gconfig header files depend on the libxml header | |
38 | files, so this must be expressed in the pkgconfig file to | |
39 | ensure the include path for libxml2 gets added to the compiler | |
40 | args | |
41 | ||
42 | 2011-11-16 Marc-André Lureau <marcandre.lureau@redhat.com> | |
43 | ||
44 | Expicitely call virInitialize() to avoid connection races | |
45 | Credits to Daniel for pointing out the solution. | |
46 | ||
0 | 47 | 2011-11-16 Daniel P. Berrange <berrange@redhat.com> |
1 | 48 | |
2 | 49 | Fix typo in libvirt-gobject-1.0.pc.in |
0 | 0.0.2 - Nov 22, 2011 | |
1 | ==================== | |
2 | ||
3 | - Add API to redefine an existing domain. | |
4 | - Expicitely call virInitialize() to avoid connection races. | |
5 | - Adjust example to latest pygobject-3.0. | |
6 | - Add missing deps on libxml2-devel & libtool. | |
7 | - Add support for writing to streams | |
8 | - Add API for creating transient domains | |
9 | - Change all flags parameters to be guint | |
10 | - Uncomment & fix code for returning object config | |
11 | - Ensure pools & domains hashes are non-NULL to avoid SEGV | |
12 | - Don't de-reference GError instances which are NULL | |
13 | - Update COPYING file to have latest FSF address | |
14 | - Update RPM specfile to include Fedora review feedback | |
15 | ||
0 | 16 | 0.0.1 - Nov 16, 2011 |
1 | 17 | ==================== |
2 | 18 |
0 | 0 | #! /bin/sh |
1 | 1 | # Guess values for system-dependent variables and create Makefiles. |
2 | # Generated by GNU Autoconf 2.68 for libvirt-glib 0.0.1. | |
2 | # Generated by GNU Autoconf 2.68 for libvirt-glib 0.0.2. | |
3 | 3 | # |
4 | 4 | # |
5 | 5 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, |
566 | 566 | # Identity of this package. |
567 | 567 | PACKAGE_NAME='libvirt-glib' |
568 | 568 | PACKAGE_TARNAME='libvirt-glib' |
569 | PACKAGE_VERSION='0.0.1' | |
570 | PACKAGE_STRING='libvirt-glib 0.0.1' | |
569 | PACKAGE_VERSION='0.0.2' | |
570 | PACKAGE_STRING='libvirt-glib 0.0.2' | |
571 | 571 | PACKAGE_BUGREPORT='' |
572 | 572 | PACKAGE_URL='' |
573 | 573 | |
1372 | 1372 | # Omit some internal or obsolete options to make the list less imposing. |
1373 | 1373 | # This message is too long to be a string in the A/UX 3.1 sh. |
1374 | 1374 | cat <<_ACEOF |
1375 | \`configure' configures libvirt-glib 0.0.1 to adapt to many kinds of systems. | |
1375 | \`configure' configures libvirt-glib 0.0.2 to adapt to many kinds of systems. | |
1376 | 1376 | |
1377 | 1377 | Usage: $0 [OPTION]... [VAR=VALUE]... |
1378 | 1378 | |
1442 | 1442 | |
1443 | 1443 | if test -n "$ac_init_help"; then |
1444 | 1444 | case $ac_init_help in |
1445 | short | recursive ) echo "Configuration of libvirt-glib 0.0.1:";; | |
1445 | short | recursive ) echo "Configuration of libvirt-glib 0.0.2:";; | |
1446 | 1446 | esac |
1447 | 1447 | cat <<\_ACEOF |
1448 | 1448 | |
1587 | 1587 | test -n "$ac_init_help" && exit $ac_status |
1588 | 1588 | if $ac_init_version; then |
1589 | 1589 | cat <<\_ACEOF |
1590 | libvirt-glib configure 0.0.1 | |
1590 | libvirt-glib configure 0.0.2 | |
1591 | 1591 | generated by GNU Autoconf 2.68 |
1592 | 1592 | |
1593 | 1593 | Copyright (C) 2010 Free Software Foundation, Inc. |
1865 | 1865 | This file contains any messages produced by compilers while |
1866 | 1866 | running configure, to aid debugging if configure makes a mistake. |
1867 | 1867 | |
1868 | It was created by libvirt-glib $as_me 0.0.1, which was | |
1868 | It was created by libvirt-glib $as_me 0.0.2, which was | |
1869 | 1869 | generated by GNU Autoconf 2.68. Invocation command line was |
1870 | 1870 | |
1871 | 1871 | $ $0 $@ |
2684 | 2684 | |
2685 | 2685 | # Define the identity of the package. |
2686 | 2686 | PACKAGE='libvirt-glib' |
2687 | VERSION='0.0.1' | |
2687 | VERSION='0.0.2' | |
2688 | 2688 | |
2689 | 2689 | |
2690 | 2690 | cat >>confdefs.h <<_ACEOF |
13686 | 13686 | # report actual input values of CONFIG_FILES etc. instead of their |
13687 | 13687 | # values after options handling. |
13688 | 13688 | ac_log=" |
13689 | This file was extended by libvirt-glib $as_me 0.0.1, which was | |
13689 | This file was extended by libvirt-glib $as_me 0.0.2, which was | |
13690 | 13690 | generated by GNU Autoconf 2.68. Invocation command line was |
13691 | 13691 | |
13692 | 13692 | CONFIG_FILES = $CONFIG_FILES |
13752 | 13752 | cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 |
13753 | 13753 | ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" |
13754 | 13754 | ac_cs_version="\\ |
13755 | libvirt-glib config.status 0.0.1 | |
13755 | libvirt-glib config.status 0.0.2 | |
13756 | 13756 | configured by $0, generated by GNU Autoconf 2.68, |
13757 | 13757 | with options \\"\$ac_cs_config\\" |
13758 | 13758 |
0 | ||
1 | AC_INIT(libvirt-glib, 0.0.1) | |
0 | AC_INIT(libvirt-glib, 0.0.2) | |
2 | 1 | AC_CONFIG_SRCDIR(libvirt-glib/libvirt-glib-main.c) |
3 | 2 | AC_CONFIG_AUX_DIR([build-aux]) |
4 | 3 | AM_CONFIG_HEADER(config.h) |
20 | 20 | </tr></table> |
21 | 21 | <div class="chapter"> |
22 | 22 | <div class="titlepage"><div><div><h2 class="title"> |
23 | <a name="id406188"></a>Libvirt-gconfig</h2></div></div></div> | |
23 | <a name="id410353"></a>Libvirt-gconfig</h2></div></div></div> | |
24 | 24 | <span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span> |
25 | 25 | </div> |
26 | 26 | <div class="footer"> |
20 | 20 | </tr></table> |
21 | 21 | <div class="chapter"> |
22 | 22 | <div class="titlepage"><div><div><h2 class="title"> |
23 | <a name="id375025"></a>Libvirt-glib</h2></div></div></div> | |
23 | <a name="id479404"></a>Libvirt-glib</h2></div></div></div> | |
24 | 24 | <span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span> |
25 | 25 | </div> |
26 | 26 | <div class="footer"> |
20 | 20 | </tr></table> |
21 | 21 | <div class="chapter"> |
22 | 22 | <div class="titlepage"><div><div><h2 class="title"> |
23 | <a name="id464659"></a>Libvirt-gobject</h2></div></div></div> | |
23 | <a name="id382227"></a>Libvirt-gobject</h2></div></div></div> | |
24 | 24 | <span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span><span style="color: red"><xi:include></xi:include></span> |
25 | 25 | </div> |
26 | 26 | <div class="footer"> |
0 | 0 | |
1 | import gtk | |
1 | from gi.repository import Gtk | |
2 | 2 | import libvirt |
3 | 3 | import getopt |
4 | 4 | import sys |
46 | 46 | |
47 | 47 | print "Using uri:" + uri |
48 | 48 | |
49 | LibvirtGLib.init("") | |
49 | LibvirtGLib.init(0, "") | |
50 | 50 | LibvirtGLib.event_register() |
51 | # libvirtglib.eventRegister() | |
52 | 51 | vc = libvirt.open(uri) |
53 | 52 | |
54 | 53 | #Add 2 callbacks to prove this works with more than just one |
55 | 54 | vc.domainEventRegister(myDomainEventCallback1,None) |
56 | 55 | vc.domainEventRegister(myDomainEventCallback2,None) |
57 | 56 | |
58 | gtk.main() | |
57 | Gtk.main() | |
59 | 58 | |
60 | 59 | if __name__ == "__main__": |
61 | 60 | main() |
5 | 5 | Name: libvirt-gconfig |
6 | 6 | Version: @VERSION@ |
7 | 7 | Description: libvirt GConfig library |
8 | Requires: gobject-2.0 | |
8 | Requires: gobject-2.0 libxml-2.0 | |
9 | 9 | Libs: -L${libdir} -lvirt-gconfig-1.0 |
10 | 10 | Cflags: -I${includedir}/libvirt-gconfig-1.0 |
62 | 62 | if (!g_thread_supported()) |
63 | 63 | g_thread_init(NULL); |
64 | 64 | |
65 | virInitialize(); | |
66 | ||
65 | 67 | return TRUE; |
66 | 68 | } |
67 | 69 |
5 | 5 | %if 0%{?fedora} >= 15 |
6 | 6 | %define with_introspection 1 |
7 | 7 | %endif |
8 | %if 0%{?fedora} < 15 | |
8 | %if 0%{?fedora} && 0%{?fedora} < 15 | |
9 | 9 | %define with_python 1 |
10 | 10 | %endif |
11 | 11 | %if 0%{?rhel} > 6 |
12 | 12 | %define with_introspection 1 |
13 | 13 | %endif |
14 | %if 0%{?rhel} < 7 | |
14 | %if 0%{?rhel} && 0%{?rhel} < 7 | |
15 | 15 | %define with_python 1 |
16 | 16 | %endif |
17 | 17 | |
18 | 18 | |
19 | 19 | Name: libvirt-glib |
20 | Version: 0.0.1 | |
20 | Version: 0.0.2 | |
21 | 21 | Release: 1%{?dist}%{?extra_release} |
22 | 22 | Summary: libvirt glib integration for events |
23 | 23 | Group: Development/Libraries |
24 | 24 | License: LGPLv2+ |
25 | 25 | URL: http://libvirt.org/ |
26 | Source0: http://libvirt.org/%{name}/%{name}-%{version}.tar.gz | |
26 | Source0: ftp://libvirt.org/libvirt/glib/%{name}-%{version}.tar.gz | |
27 | 27 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) |
28 | 28 | |
29 | 29 | BuildRequires: glib2-devel >= 2.10.0 |
34 | 34 | %if 0%{?fedora} == 12 |
35 | 35 | BuildRequires: gir-repository-devel |
36 | 36 | %endif |
37 | BuildRequires: gjs-devel | |
38 | 37 | %endif |
39 | 38 | BuildRequires: libxml2-devel |
40 | 39 | # Hack due to https://bugzilla.redhat.com/show_bug.cgi?id=613466 |
134 | 133 | %clean |
135 | 134 | rm -rf $RPM_BUILD_ROOT |
136 | 135 | |
136 | %post -p /sbin/ldconfig | |
137 | ||
138 | %postun -p /sbin/ldconfig | |
139 | ||
140 | %post -n libvirt-gconfig -p /sbin/ldconfig | |
141 | ||
142 | %postun -n libvirt-gconfig -p /sbin/ldconfig | |
143 | ||
144 | %post -n libvirt-gobject -p /sbin/ldconfig | |
145 | ||
146 | %postun -n libvirt-gobject -p /sbin/ldconfig | |
147 | ||
137 | 148 | %files |
138 | 149 | %defattr(-,root,root,-) |
139 | 150 | %doc README COPYING AUTHORS ChangeLog NEWS |
205 | 216 | %endif |
206 | 217 | |
207 | 218 | %changelog |
208 | * Sun Oct 19 2008 Daniel P. Berrange <berrange@redhat.com> - 0.0.1-1 | |
209 | - Initial release | |
210 |
5 | 5 | %if 0%{?fedora} >= 15 |
6 | 6 | %define with_introspection 1 |
7 | 7 | %endif |
8 | %if 0%{?fedora} < 15 | |
8 | %if 0%{?fedora} && 0%{?fedora} < 15 | |
9 | 9 | %define with_python 1 |
10 | 10 | %endif |
11 | 11 | %if 0%{?rhel} > 6 |
12 | 12 | %define with_introspection 1 |
13 | 13 | %endif |
14 | %if 0%{?rhel} < 7 | |
14 | %if 0%{?rhel} && 0%{?rhel} < 7 | |
15 | 15 | %define with_python 1 |
16 | 16 | %endif |
17 | 17 | |
23 | 23 | Group: Development/Libraries |
24 | 24 | License: LGPLv2+ |
25 | 25 | URL: http://libvirt.org/ |
26 | Source0: http://libvirt.org/%{name}/%{name}-%{version}.tar.gz | |
26 | Source0: ftp://libvirt.org/libvirt/glib/%{name}-%{version}.tar.gz | |
27 | 27 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) |
28 | 28 | |
29 | 29 | BuildRequires: glib2-devel >= 2.10.0 |
34 | 34 | %if 0%{?fedora} == 12 |
35 | 35 | BuildRequires: gir-repository-devel |
36 | 36 | %endif |
37 | BuildRequires: gjs-devel | |
38 | 37 | %endif |
39 | 38 | BuildRequires: libxml2-devel |
40 | 39 | # Hack due to https://bugzilla.redhat.com/show_bug.cgi?id=613466 |
134 | 133 | %clean |
135 | 134 | rm -rf $RPM_BUILD_ROOT |
136 | 135 | |
136 | %post -p /sbin/ldconfig | |
137 | ||
138 | %postun -p /sbin/ldconfig | |
139 | ||
140 | %post -n libvirt-gconfig -p /sbin/ldconfig | |
141 | ||
142 | %postun -n libvirt-gconfig -p /sbin/ldconfig | |
143 | ||
144 | %post -n libvirt-gobject -p /sbin/ldconfig | |
145 | ||
146 | %postun -n libvirt-gobject -p /sbin/ldconfig | |
147 | ||
137 | 148 | %files |
138 | 149 | %defattr(-,root,root,-) |
139 | 150 | %doc README COPYING AUTHORS ChangeLog NEWS |
205 | 216 | %endif |
206 | 217 | |
207 | 218 | %changelog |
208 | * Sun Oct 19 2008 Daniel P. Berrange <berrange@redhat.com> - 0.0.1-1 | |
209 | - Initial release | |
210 |
44 | 44 | |
45 | 45 | libvirt_gobject_1_0_ladir = $(includedir)/libvirt-gobject-1.0/libvirt-gobject |
46 | 46 | libvirt_gobject_1_0_la_HEADERS = \ |
47 | $(GOBJECT_HEADER_FILES) \ | |
48 | libvirt-gobject-input-stream.h | |
47 | $(GOBJECT_HEADER_FILES) | |
49 | 48 | nodist_libvirt_gobject_1_0_la_HEADERS = \ |
50 | 49 | libvirt-gobject-enums.h |
51 | 50 | libvirt_gobject_1_0_la_SOURCES = \ |
53 | 52 | $(GOBJECT_SOURCE_FILES) \ |
54 | 53 | libvirt-gobject-domain-device-private.h \ |
55 | 54 | libvirt-gobject-compat.h \ |
56 | libvirt-gobject-input-stream.c | |
55 | libvirt-gobject-input-stream.h \ | |
56 | libvirt-gobject-input-stream.c \ | |
57 | libvirt-gobject-output-stream.h \ | |
58 | libvirt-gobject-output-stream.c | |
57 | 59 | nodist_libvirt_gobject_1_0_la_SOURCES = \ |
58 | 60 | $(GOBJECT_GENERATED_FILES) |
59 | 61 | libvirt_gobject_1_0_la_CFLAGS = \ |
94 | 94 | libvirt_gobject_1_0_la-libvirt-gobject-connection.lo \ |
95 | 95 | libvirt_gobject_1_0_la-libvirt-gobject-manager.lo |
96 | 96 | am_libvirt_gobject_1_0_la_OBJECTS = $(am__objects_2) $(am__objects_3) \ |
97 | libvirt_gobject_1_0_la-libvirt-gobject-input-stream.lo | |
97 | libvirt_gobject_1_0_la-libvirt-gobject-input-stream.lo \ | |
98 | libvirt_gobject_1_0_la-libvirt-gobject-output-stream.lo | |
98 | 99 | am__objects_4 = libvirt_gobject_1_0_la-libvirt-gobject-enums.lo |
99 | 100 | nodist_libvirt_gobject_1_0_la_OBJECTS = $(am__objects_4) |
100 | 101 | libvirt_gobject_1_0_la_OBJECTS = $(am_libvirt_gobject_1_0_la_OBJECTS) \ |
344 | 345 | |
345 | 346 | libvirt_gobject_1_0_ladir = $(includedir)/libvirt-gobject-1.0/libvirt-gobject |
346 | 347 | libvirt_gobject_1_0_la_HEADERS = \ |
347 | $(GOBJECT_HEADER_FILES) \ | |
348 | libvirt-gobject-input-stream.h | |
348 | $(GOBJECT_HEADER_FILES) | |
349 | 349 | |
350 | 350 | nodist_libvirt_gobject_1_0_la_HEADERS = \ |
351 | 351 | libvirt-gobject-enums.h |
355 | 355 | $(GOBJECT_SOURCE_FILES) \ |
356 | 356 | libvirt-gobject-domain-device-private.h \ |
357 | 357 | libvirt-gobject-compat.h \ |
358 | libvirt-gobject-input-stream.c | |
358 | libvirt-gobject-input-stream.h \ | |
359 | libvirt-gobject-input-stream.c \ | |
360 | libvirt-gobject-output-stream.h \ | |
361 | libvirt-gobject-output-stream.c | |
359 | 362 | |
360 | 363 | nodist_libvirt_gobject_1_0_la_SOURCES = \ |
361 | 364 | $(GOBJECT_GENERATED_FILES) |
485 | 488 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-network-filter.Plo@am__quote@ |
486 | 489 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-network.Plo@am__quote@ |
487 | 490 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-node-device.Plo@am__quote@ |
491 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-output-stream.Plo@am__quote@ | |
488 | 492 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-secret.Plo@am__quote@ |
489 | 493 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-storage-pool.Plo@am__quote@ |
490 | 494 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-storage-vol.Plo@am__quote@ |
649 | 653 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='libvirt-gobject-input-stream.c' object='libvirt_gobject_1_0_la-libvirt-gobject-input-stream.lo' libtool=yes @AMDEPBACKSLASH@ |
650 | 654 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
651 | 655 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvirt_gobject_1_0_la_CFLAGS) $(CFLAGS) -c -o libvirt_gobject_1_0_la-libvirt-gobject-input-stream.lo `test -f 'libvirt-gobject-input-stream.c' || echo '$(srcdir)/'`libvirt-gobject-input-stream.c |
656 | ||
657 | libvirt_gobject_1_0_la-libvirt-gobject-output-stream.lo: libvirt-gobject-output-stream.c | |
658 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvirt_gobject_1_0_la_CFLAGS) $(CFLAGS) -MT libvirt_gobject_1_0_la-libvirt-gobject-output-stream.lo -MD -MP -MF $(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-output-stream.Tpo -c -o libvirt_gobject_1_0_la-libvirt-gobject-output-stream.lo `test -f 'libvirt-gobject-output-stream.c' || echo '$(srcdir)/'`libvirt-gobject-output-stream.c | |
659 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-output-stream.Tpo $(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-output-stream.Plo | |
660 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | |
661 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='libvirt-gobject-output-stream.c' object='libvirt_gobject_1_0_la-libvirt-gobject-output-stream.lo' libtool=yes @AMDEPBACKSLASH@ | |
662 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | |
663 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvirt_gobject_1_0_la_CFLAGS) $(CFLAGS) -c -o libvirt_gobject_1_0_la-libvirt-gobject-output-stream.lo `test -f 'libvirt-gobject-output-stream.c' || echo '$(srcdir)/'`libvirt-gobject-output-stream.c | |
652 | 664 | |
653 | 665 | libvirt_gobject_1_0_la-libvirt-gobject-enums.lo: libvirt-gobject-enums.c |
654 | 666 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libvirt_gobject_1_0_la_CFLAGS) $(CFLAGS) -MT libvirt_gobject_1_0_la-libvirt-gobject-enums.lo -MD -MP -MF $(DEPDIR)/libvirt_gobject_1_0_la-libvirt-gobject-enums.Tpo -c -o libvirt_gobject_1_0_la-libvirt-gobject-enums.lo `test -f 'libvirt-gobject-enums.c' || echo '$(srcdir)/'`libvirt-gobject-enums.c |
233 | 233 | |
234 | 234 | priv = conn->priv = GVIR_CONNECTION_GET_PRIVATE(conn); |
235 | 235 | |
236 | memset(priv, 0, sizeof(*priv)); | |
237 | ||
238 | 236 | priv->lock = g_mutex_new(); |
237 | priv->domains = g_hash_table_new_full(g_str_hash, | |
238 | g_str_equal, | |
239 | NULL, | |
240 | g_object_unref); | |
241 | priv->pools = g_hash_table_new_full(g_str_hash, | |
242 | g_str_equal, | |
243 | NULL, | |
244 | g_object_unref); | |
239 | 245 | } |
240 | 246 | |
241 | 247 | |
382 | 388 | |
383 | 389 | g_mutex_lock(priv->lock); |
384 | 390 | if (priv->conn) { |
385 | *err = g_error_new(GVIR_CONNECTION_ERROR, | |
386 | 0, | |
387 | "Connection %s is already open", | |
388 | priv->uri); | |
391 | if (err) | |
392 | *err = g_error_new(GVIR_CONNECTION_ERROR, | |
393 | 0, | |
394 | "Connection %s is already open", | |
395 | priv->uri); | |
389 | 396 | g_mutex_unlock(priv->lock); |
390 | 397 | return FALSE; |
391 | 398 | } |
392 | 399 | |
393 | 400 | if (!(priv->conn = virConnectOpen(priv->uri))) { |
394 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
395 | 0, | |
396 | "Unable to open %s", | |
397 | priv->uri); | |
401 | if (err) | |
402 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
403 | 0, | |
404 | "Unable to open %s", | |
405 | priv->uri); | |
398 | 406 | g_mutex_unlock(priv->lock); |
399 | 407 | return FALSE; |
400 | 408 | } |
533 | 541 | gint i; |
534 | 542 | |
535 | 543 | if ((n = count_func(vconn)) < 0) { |
536 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
537 | 0, | |
538 | "Unable to count %s", name); | |
544 | if (err) | |
545 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
546 | 0, | |
547 | "Unable to count %s", name); | |
539 | 548 | goto error; |
540 | 549 | } |
541 | 550 | |
545 | 554 | |
546 | 555 | lst = g_new(gchar *, n); |
547 | 556 | if ((n = list_func(vconn, lst, n)) < 0) { |
548 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
549 | 0, | |
550 | "Unable to list %s %d", name, n); | |
557 | if (err) | |
558 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
559 | 0, | |
560 | "Unable to list %s %d", name, n); | |
551 | 561 | goto error; |
552 | 562 | } |
553 | 563 | } |
580 | 590 | gboolean ret = FALSE; |
581 | 591 | gint i; |
582 | 592 | virConnectPtr vconn = NULL; |
593 | GError *lerr = NULL; | |
583 | 594 | |
584 | 595 | g_mutex_lock(priv->lock); |
585 | 596 | if (!priv->conn) { |
586 | *err = g_error_new(GVIR_CONNECTION_ERROR, | |
587 | 0, | |
588 | "Connection is not open"); | |
597 | if (err) | |
598 | *err = g_error_new(GVIR_CONNECTION_ERROR, | |
599 | 0, | |
600 | "Connection is not open"); | |
589 | 601 | g_mutex_unlock(priv->lock); |
590 | 602 | goto cleanup; |
591 | 603 | } |
598 | 610 | goto cleanup; |
599 | 611 | |
600 | 612 | if ((nactive = virConnectNumOfDomains(vconn)) < 0) { |
601 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
602 | 0, | |
603 | "Unable to count domains"); | |
613 | if (err) | |
614 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
615 | 0, | |
616 | "Unable to count domains"); | |
604 | 617 | goto cleanup; |
605 | 618 | } |
606 | 619 | if (nactive) { |
609 | 622 | |
610 | 623 | active = g_new(gint, nactive); |
611 | 624 | if ((nactive = virConnectListDomains(vconn, active, nactive)) < 0) { |
612 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
613 | 0, | |
614 | "Unable to list domains"); | |
625 | if (err) | |
626 | *err = gvir_error_new(GVIR_CONNECTION_ERROR, | |
627 | 0, | |
628 | "Unable to list domains"); | |
615 | 629 | goto cleanup; |
616 | 630 | } |
617 | 631 | } |
625 | 639 | virConnectListDefinedDomains, |
626 | 640 | cancellable, |
627 | 641 | &ninactive, |
628 | err); | |
629 | if (*err != NULL) | |
642 | &lerr); | |
643 | if (lerr) { | |
644 | g_propagate_error(err, lerr); | |
645 | lerr = NULL; | |
630 | 646 | goto cleanup; |
647 | } | |
631 | 648 | |
632 | 649 | doms = g_hash_table_new_full(g_str_hash, |
633 | 650 | g_str_equal, |
705 | 722 | gboolean ret = FALSE; |
706 | 723 | gint i; |
707 | 724 | virConnectPtr vconn = NULL; |
725 | GError *lerr = NULL; | |
708 | 726 | |
709 | 727 | g_mutex_lock(priv->lock); |
710 | 728 | if (!priv->conn) { |
711 | *err = g_error_new(GVIR_CONNECTION_ERROR, | |
712 | 0, | |
713 | "Connection is not open"); | |
729 | if (err) | |
730 | *err = g_error_new(GVIR_CONNECTION_ERROR, | |
731 | 0, | |
732 | "Connection is not open"); | |
714 | 733 | g_mutex_unlock(priv->lock); |
715 | 734 | goto cleanup; |
716 | 735 | } |
728 | 747 | virConnectListStoragePools, |
729 | 748 | cancellable, |
730 | 749 | &nactive, |
731 | err); | |
732 | if (*err != NULL) | |
750 | &lerr); | |
751 | if (lerr) { | |
752 | g_propagate_error(err, lerr); | |
753 | lerr = NULL; | |
733 | 754 | goto cleanup; |
755 | } | |
734 | 756 | |
735 | 757 | if (g_cancellable_set_error_if_cancelled(cancellable, err)) |
736 | 758 | goto cleanup; |
741 | 763 | virConnectListDefinedStoragePools, |
742 | 764 | cancellable, |
743 | 765 | &ninactive, |
744 | err); | |
745 | if (*err != NULL) | |
766 | &lerr); | |
767 | if (lerr) { | |
768 | g_propagate_error(err, lerr); | |
769 | lerr = NULL; | |
746 | 770 | goto cleanup; |
771 | } | |
747 | 772 | |
748 | 773 | pools = g_hash_table_new_full(g_str_hash, |
749 | 774 | g_str_equal, |
1144 | 1169 | * Return value: (transfer full): a #GVirStream stream, or NULL |
1145 | 1170 | */ |
1146 | 1171 | GVirStream *gvir_connection_get_stream(GVirConnection *self, |
1147 | gint flags) | |
1172 | guint flags) | |
1148 | 1173 | { |
1149 | 1174 | GVirConnectionClass *klass; |
1150 | 1175 | |
1161 | 1186 | |
1162 | 1187 | /** |
1163 | 1188 | * gvir_connection_create_domain: |
1164 | * @conn: the connection on which to create the dmain | |
1189 | * @conn: the connection on which to create the domain | |
1165 | 1190 | * @conf: the configuration for the new domain |
1191 | * | |
1192 | * Create the configuration file for a new persistent domain. | |
1193 | * The returned domain will initially be in the shutoff state. | |
1194 | * | |
1166 | 1195 | * Returns: (transfer full): the newly created domain |
1167 | 1196 | */ |
1168 | 1197 | GVirDomain *gvir_connection_create_domain(GVirConnection *conn, |
1169 | 1198 | GVirConfigDomain *conf, |
1170 | 1199 | GError **err) |
1171 | 1200 | { |
1172 | const gchar *xml; | |
1201 | gchar *xml; | |
1173 | 1202 | virDomainPtr handle; |
1174 | 1203 | GVirConnectionPrivate *priv = conn->priv; |
1175 | 1204 | |
1177 | 1206 | |
1178 | 1207 | g_return_val_if_fail(xml != NULL, NULL); |
1179 | 1208 | |
1180 | if (!(handle = virDomainDefineXML(priv->conn, xml))) { | |
1181 | *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, | |
1182 | 0, | |
1183 | "Failed to create domain"); | |
1209 | handle = virDomainDefineXML(priv->conn, xml); | |
1210 | g_free(xml); | |
1211 | if (!handle) { | |
1212 | if (err) | |
1213 | *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, | |
1214 | 0, | |
1215 | "Failed to create domain"); | |
1184 | 1216 | return NULL; |
1185 | 1217 | } |
1186 | 1218 | |
1193 | 1225 | g_mutex_lock(priv->lock); |
1194 | 1226 | g_hash_table_insert(priv->domains, |
1195 | 1227 | (gpointer)gvir_domain_get_uuid(domain), |
1196 | domain); | |
1197 | g_mutex_unlock(priv->lock); | |
1198 | ||
1199 | return g_object_ref(domain); | |
1228 | g_object_ref(domain)); | |
1229 | g_mutex_unlock(priv->lock); | |
1230 | ||
1231 | return domain; | |
1232 | } | |
1233 | ||
1234 | /** | |
1235 | * gvir_connection_start_domain: | |
1236 | * @conn: the connection on which to create the domain | |
1237 | * @conf: the configuration for the new domain | |
1238 | * | |
1239 | * Start a new transient domain without persistent configuration. | |
1240 | * The returned domain will initially be running. | |
1241 | * | |
1242 | * Returns: (transfer full): the newly created domain | |
1243 | */ | |
1244 | GVirDomain *gvir_connection_start_domain(GVirConnection *conn, | |
1245 | GVirConfigDomain *conf, | |
1246 | guint flags, | |
1247 | GError **err) | |
1248 | { | |
1249 | gchar *xml; | |
1250 | virDomainPtr handle; | |
1251 | GVirConnectionPrivate *priv = conn->priv; | |
1252 | ||
1253 | xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf)); | |
1254 | ||
1255 | g_return_val_if_fail(xml != NULL, NULL); | |
1256 | ||
1257 | handle = virDomainCreateXML(priv->conn, xml, flags); | |
1258 | g_free(xml); | |
1259 | if (!handle) { | |
1260 | if (err) | |
1261 | *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, | |
1262 | 0, | |
1263 | "Failed to create domain"); | |
1264 | return NULL; | |
1265 | } | |
1266 | ||
1267 | GVirDomain *domain; | |
1268 | ||
1269 | domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN, | |
1270 | "handle", handle, | |
1271 | NULL)); | |
1272 | ||
1273 | g_mutex_lock(priv->lock); | |
1274 | g_hash_table_insert(priv->domains, | |
1275 | (gpointer)gvir_domain_get_uuid(domain), | |
1276 | g_object_ref(domain)); | |
1277 | g_mutex_unlock(priv->lock); | |
1278 | ||
1279 | return domain; | |
1200 | 1280 | } |
1201 | 1281 | |
1202 | 1282 | /** |
1211 | 1291 | GVirStoragePool *gvir_connection_create_storage_pool |
1212 | 1292 | (GVirConnection *conn, |
1213 | 1293 | GVirConfigStoragePool *conf, |
1214 | guint64 flags G_GNUC_UNUSED, | |
1294 | guint flags, | |
1215 | 1295 | GError **err) { |
1216 | 1296 | const gchar *xml; |
1217 | 1297 | virStoragePoolPtr handle; |
1221 | 1301 | |
1222 | 1302 | g_return_val_if_fail(xml != NULL, NULL); |
1223 | 1303 | |
1224 | if (!(handle = virStoragePoolDefineXML(priv->conn, xml, 0))) { | |
1225 | *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, | |
1226 | flags, | |
1227 | "Failed to create storage pool"); | |
1304 | if (!(handle = virStoragePoolDefineXML(priv->conn, xml, flags))) { | |
1305 | if (err) | |
1306 | *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, | |
1307 | flags, | |
1308 | "Failed to create storage pool"); | |
1228 | 1309 | return NULL; |
1229 | 1310 | } |
1230 | 1311 |
109 | 109 | GVirDomain *gvir_connection_create_domain(GVirConnection *conn, |
110 | 110 | GVirConfigDomain *conf, |
111 | 111 | GError **err); |
112 | GVirDomain *gvir_connection_start_domain(GVirConnection *conn, | |
113 | GVirConfigDomain *conf, | |
114 | guint flags, | |
115 | GError **err); | |
112 | 116 | |
113 | 117 | #if 0 |
114 | 118 | GList *gvir_connection_get_interfaces(GVirConnection *conn); |
162 | 166 | GVirStoragePool *gvir_connection_create_storage_pool |
163 | 167 | (GVirConnection *conn, |
164 | 168 | GVirConfigStoragePool *conf, |
165 | guint64 flags, | |
169 | guint flags, | |
166 | 170 | GError **err); |
167 | 171 | |
168 | 172 | |
169 | 173 | GVirStream *gvir_connection_get_stream(GVirConnection *conn, |
170 | gint flags); | |
174 | guint flags); | |
171 | 175 | |
172 | 176 | G_END_DECLS |
173 | 177 |
196 | 196 | */ |
197 | 197 | GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config |
198 | 198 | (GVirDomainSnapshot *snapshot, |
199 | guint64 flags, | |
199 | guint flags, | |
200 | 200 | GError **err) |
201 | 201 | { |
202 | 202 | GVirDomainSnapshotPrivate *priv = snapshot->priv; |
209 | 209 | return NULL; |
210 | 210 | } |
211 | 211 | |
212 | #if 0 | |
213 | GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new(xml); | |
214 | ||
215 | g_free(xml); | |
212 | GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new_from_xml(xml, err); | |
213 | ||
214 | free(xml); | |
216 | 215 | return conf; |
217 | #endif | |
218 | return NULL; | |
219 | } | |
216 | } |
65 | 65 | |
66 | 66 | GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config |
67 | 67 | (GVirDomainSnapshot *snapshot, |
68 | guint64 flags, | |
68 | guint flags, | |
69 | 69 | GError **err); |
70 | 70 | |
71 | 71 | G_END_DECLS |
286 | 286 | gint ret; |
287 | 287 | |
288 | 288 | if ((ret = virDomainGetID(priv->handle)) < 0) { |
289 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
290 | 0, | |
291 | "Unable to get ID for domain"); | |
289 | if (err) | |
290 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
291 | 0, | |
292 | "Unable to get ID for domain"); | |
292 | 293 | } |
293 | 294 | return ret; |
294 | 295 | } |
300 | 301 | * @flags: the flags |
301 | 302 | */ |
302 | 303 | gboolean gvir_domain_start(GVirDomain *dom, |
303 | guint64 flags G_GNUC_UNUSED, | |
304 | guint flags, | |
304 | 305 | GError **err) |
305 | 306 | { |
306 | 307 | GVirDomainPrivate *priv = dom->priv; |
307 | ||
308 | if (virDomainCreate(priv->handle) < 0) { | |
309 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
310 | 0, | |
311 | "Unable to start domain"); | |
308 | int ret; | |
309 | ||
310 | if (flags) | |
311 | ret = virDomainCreateWithFlags(priv->handle, flags); | |
312 | else | |
313 | ret = virDomainCreate(priv->handle); | |
314 | if (ret < 0) { | |
315 | if (err) | |
316 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
317 | 0, | |
318 | "Unable to start domain"); | |
312 | 319 | return FALSE; |
313 | 320 | } |
314 | 321 | |
327 | 334 | GVirDomainPrivate *priv = dom->priv; |
328 | 335 | |
329 | 336 | if (virDomainResume(priv->handle) < 0) { |
330 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
331 | 0, | |
332 | "Unable to resume domain"); | |
337 | if (err) | |
338 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
339 | 0, | |
340 | "Unable to resume domain"); | |
333 | 341 | return FALSE; |
334 | 342 | } |
335 | 343 | |
342 | 350 | * @flags: the flags |
343 | 351 | */ |
344 | 352 | gboolean gvir_domain_stop(GVirDomain *dom, |
345 | guint64 flags G_GNUC_UNUSED, | |
353 | guint flags, | |
346 | 354 | GError **err) |
347 | 355 | { |
348 | 356 | GVirDomainPrivate *priv = dom->priv; |
349 | ||
350 | if (virDomainDestroy(priv->handle) < 0) { | |
351 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
352 | 0, | |
353 | "Unable to stop domain"); | |
357 | int ret; | |
358 | ||
359 | if (flags) | |
360 | ret = virDomainDestroyFlags(priv->handle, flags); | |
361 | else | |
362 | ret = virDomainDestroy(priv->handle); | |
363 | if (ret < 0) { | |
364 | if (err) | |
365 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
366 | 0, | |
367 | "Unable to stop domain"); | |
354 | 368 | return FALSE; |
355 | 369 | } |
356 | 370 | |
363 | 377 | * @flags: the flags |
364 | 378 | */ |
365 | 379 | gboolean gvir_domain_delete(GVirDomain *dom, |
366 | guint64 flags G_GNUC_UNUSED, | |
380 | guint flags, | |
367 | 381 | GError **err) |
368 | 382 | { |
369 | 383 | GVirDomainPrivate *priv = dom->priv; |
370 | ||
371 | if (virDomainUndefine(priv->handle) < 0) { | |
372 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
373 | 0, | |
374 | "Unable to delete domain"); | |
384 | int ret; | |
385 | ||
386 | if (flags) | |
387 | ret = virDomainUndefineFlags(priv->handle, flags); | |
388 | else | |
389 | ret = virDomainUndefine(priv->handle); | |
390 | if (ret < 0) { | |
391 | if (err) | |
392 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
393 | 0, | |
394 | "Unable to delete domain"); | |
375 | 395 | return FALSE; |
376 | 396 | } |
377 | 397 | |
384 | 404 | * @flags: the flags |
385 | 405 | */ |
386 | 406 | gboolean gvir_domain_shutdown(GVirDomain *dom, |
387 | guint64 flags G_GNUC_UNUSED, | |
407 | guint flags G_GNUC_UNUSED, | |
388 | 408 | GError **err) |
389 | 409 | { |
390 | 410 | GVirDomainPrivate *priv = dom->priv; |
391 | 411 | |
392 | 412 | if (virDomainShutdown(priv->handle) < 0) { |
393 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
394 | 0, | |
395 | "Unable to shutdown domain"); | |
413 | if (err) | |
414 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
415 | 0, | |
416 | "Unable to shutdown domain"); | |
396 | 417 | return FALSE; |
397 | 418 | } |
398 | 419 | |
405 | 426 | * @flags: the flags |
406 | 427 | */ |
407 | 428 | gboolean gvir_domain_reboot(GVirDomain *dom, |
408 | guint64 flags, | |
429 | guint flags, | |
409 | 430 | GError **err) |
410 | 431 | { |
411 | 432 | GVirDomainPrivate *priv = dom->priv; |
412 | 433 | |
413 | 434 | if (virDomainReboot(priv->handle, flags) < 0) { |
414 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
415 | 0, | |
416 | "Unable to reboot domain"); | |
435 | if (err) | |
436 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
437 | 0, | |
438 | "Unable to reboot domain"); | |
417 | 439 | return FALSE; |
418 | 440 | } |
419 | 441 | |
427 | 449 | * Returns: (transfer full): the config |
428 | 450 | */ |
429 | 451 | GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom, |
430 | guint64 flags, | |
452 | guint flags, | |
431 | 453 | GError **err) |
432 | 454 | { |
433 | 455 | GVirDomainPrivate *priv = dom->priv; |
434 | 456 | gchar *xml; |
435 | 457 | |
436 | 458 | if (!(xml = virDomainGetXMLDesc(priv->handle, flags))) { |
437 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
438 | 0, | |
439 | "Unable to get domain XML config"); | |
459 | if (err) | |
460 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
461 | 0, | |
462 | "Unable to get domain XML config"); | |
440 | 463 | return NULL; |
441 | 464 | } |
442 | 465 | |
448 | 471 | return conf; |
449 | 472 | } |
450 | 473 | |
474 | /** | |
475 | * gvir_domain_set_config: | |
476 | * @domain: the domain | |
477 | * @conf: the new configuration for the domain | |
478 | * @err: (allow-none): Place-holder for error or NULL | |
479 | * | |
480 | * Resets configuration of an existing domain. | |
481 | * | |
482 | * Note: If domain is already running, the new configuration will not take | |
483 | * affect until domain reboots. | |
484 | * | |
485 | * Returns: TRUE on success, FALSE if an error occurred. | |
486 | */ | |
487 | gboolean gvir_domain_set_config(GVirDomain *domain, | |
488 | GVirConfigDomain *conf, | |
489 | GError **err) | |
490 | { | |
491 | gchar *xml; | |
492 | virConnectPtr conn; | |
493 | virDomainPtr handle; | |
494 | gchar uuid[VIR_UUID_STRING_BUFLEN]; | |
495 | GVirDomainPrivate *priv = domain->priv; | |
496 | ||
497 | g_return_val_if_fail(GVIR_IS_DOMAIN (domain), FALSE); | |
498 | g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN (conf), FALSE); | |
499 | g_return_val_if_fail(err == NULL || *err == NULL, FALSE); | |
500 | ||
501 | xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf)); | |
502 | ||
503 | g_return_val_if_fail(xml != NULL, FALSE); | |
504 | ||
505 | if ((conn = virDomainGetConnect(priv->handle)) == NULL) { | |
506 | if (err != NULL) | |
507 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
508 | 0, | |
509 | "Failed to get domain connection"); | |
510 | g_free (xml); | |
511 | ||
512 | return FALSE; | |
513 | } | |
514 | ||
515 | handle = virDomainDefineXML(conn, xml); | |
516 | g_free (xml); | |
517 | ||
518 | if (handle == NULL) { | |
519 | if (err != NULL) | |
520 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
521 | 0, | |
522 | "Failed to set " | |
523 | "domain configuration"); | |
524 | return FALSE; | |
525 | } | |
526 | ||
527 | virDomainGetUUIDString(handle, uuid); | |
528 | virDomainFree(handle); | |
529 | ||
530 | if (g_strcmp0 (uuid, priv->uuid) != 0) { | |
531 | if (err != NULL) | |
532 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
533 | 0, | |
534 | "Failed to set " | |
535 | "domain configuration"); | |
536 | ||
537 | return FALSE; | |
538 | } | |
539 | ||
540 | return TRUE; | |
541 | } | |
451 | 542 | |
452 | 543 | /** |
453 | 544 | * gvir_domain_get_info: |
462 | 553 | GVirDomainInfo *ret; |
463 | 554 | |
464 | 555 | if (virDomainGetInfo(priv->handle, &info) < 0) { |
465 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
466 | 0, | |
467 | "Unable to get domain info"); | |
556 | if (err) | |
557 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
558 | 0, | |
559 | "Unable to get domain info"); | |
468 | 560 | return NULL; |
469 | 561 | } |
470 | 562 | |
488 | 580 | */ |
489 | 581 | gchar *gvir_domain_screenshot(GVirDomain *dom, |
490 | 582 | GVirStream *stream, |
491 | guint64 monitor_id, | |
492 | guint64 flags, | |
583 | guint monitor_id, | |
584 | guint flags, | |
493 | 585 | GError **err) |
494 | 586 | { |
495 | 587 | GVirDomainPrivate *priv; |
506 | 598 | st, |
507 | 599 | monitor_id, |
508 | 600 | flags))) { |
509 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
510 | 0, | |
511 | "Unable to take a screenshot"); | |
601 | if (err) | |
602 | *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, | |
603 | 0, | |
604 | "Unable to take a screenshot"); | |
512 | 605 | goto end; |
513 | 606 | } |
514 | 607 | end: |
99 | 99 | GError **err); |
100 | 100 | |
101 | 101 | gboolean gvir_domain_start(GVirDomain *dom, |
102 | guint64 flags, | |
102 | guint flags, | |
103 | 103 | GError **err); |
104 | 104 | gboolean gvir_domain_resume(GVirDomain *dom, |
105 | 105 | GError **err); |
106 | 106 | gboolean gvir_domain_stop(GVirDomain *dom, |
107 | guint64 flags, | |
107 | guint flags, | |
108 | 108 | GError **err); |
109 | 109 | gboolean gvir_domain_delete(GVirDomain *dom, |
110 | guint64 flags, | |
110 | guint flags, | |
111 | 111 | GError **err); |
112 | 112 | gboolean gvir_domain_shutdown(GVirDomain *dom, |
113 | guint64 flags, | |
113 | guint flags, | |
114 | 114 | GError **err); |
115 | 115 | gboolean gvir_domain_reboot(GVirDomain *dom, |
116 | guint64 flags, | |
116 | guint flags, | |
117 | 117 | GError **err); |
118 | 118 | |
119 | 119 | GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom, |
120 | 120 | GError **err); |
121 | 121 | |
122 | 122 | GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom, |
123 | guint64 flags, | |
123 | guint flags, | |
124 | 124 | GError **err); |
125 | gboolean gvir_domain_set_config(GVirDomain *domain, | |
126 | GVirConfigDomain *conf, | |
127 | GError **err); | |
125 | 128 | |
126 | 129 | gchar *gvir_domain_screenshot(GVirDomain *dom, |
127 | 130 | GVirStream *stream, |
128 | guint64 monitor_id, | |
129 | guint64 flags, | |
131 | guint monitor_id, | |
132 | guint flags, | |
130 | 133 | GError **err); |
131 | 134 | |
132 | 135 | G_END_DECLS |
185 | 185 | * Returns: (transfer full): the config |
186 | 186 | */ |
187 | 187 | GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, |
188 | guint64 flags, | |
188 | guint flags, | |
189 | 189 | GError **err) |
190 | 190 | { |
191 | 191 | GVirInterfacePrivate *priv = iface->priv; |
192 | 192 | gchar *xml; |
193 | 193 | |
194 | 194 | if (!(xml = virInterfaceGetXMLDesc(priv->handle, flags))) { |
195 | *err = gvir_error_new_literal(GVIR_INTERFACE_ERROR, | |
196 | 0, | |
197 | "Unable to get interface XML config"); | |
195 | if (err) | |
196 | *err = gvir_error_new_literal(GVIR_INTERFACE_ERROR, | |
197 | 0, | |
198 | "Unable to get interface XML config"); | |
198 | 199 | return NULL; |
199 | 200 | } |
200 | 201 | |
201 | #if 0 | |
202 | GVirConfigInterface *conf = gvir_config_interface_new(xml); | |
203 | ||
204 | g_free(xml); | |
202 | GVirConfigInterface *conf = gvir_config_interface_new_from_xml(xml, err); | |
203 | ||
204 | free(xml); | |
205 | 205 | return conf; |
206 | #endif | |
207 | return NULL; | |
208 | } | |
206 | } |
64 | 64 | const gchar *gvir_interface_get_name(GVirInterface *iface); |
65 | 65 | |
66 | 66 | GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, |
67 | guint64 flags, | |
67 | guint flags, | |
68 | 68 | GError **err); |
69 | 69 | |
70 | 70 | G_END_DECLS |
211 | 211 | */ |
212 | 212 | GVirConfigNetworkFilter *gvir_network_filter_get_config |
213 | 213 | (GVirNetworkFilter *filter, |
214 | guint64 flags, | |
214 | guint flags, | |
215 | 215 | GError **err) |
216 | 216 | { |
217 | 217 | GVirNetworkFilterPrivate *priv = filter->priv; |
218 | 218 | gchar *xml; |
219 | 219 | |
220 | 220 | if (!(xml = virNWFilterGetXMLDesc(priv->handle, flags))) { |
221 | *err = gvir_error_new_literal(GVIR_NETWORK_FILTER_ERROR, | |
222 | 0, | |
223 | "Unable to get network_filter XML config"); | |
221 | if (err) | |
222 | *err = gvir_error_new_literal(GVIR_NETWORK_FILTER_ERROR, | |
223 | 0, | |
224 | "Unable to get network_filter XML config"); | |
224 | 225 | return NULL; |
225 | 226 | } |
226 | 227 | |
227 | #if 0 | |
228 | GVirConfigNetworkFilter *conf = gvir_config_network_filter_new(xml); | |
229 | ||
230 | g_free(xml); | |
228 | GVirConfigNetworkFilter *conf = gvir_config_network_filter_new_from_xml(xml, err); | |
229 | ||
230 | free(xml); | |
231 | 231 | return conf; |
232 | #endif | |
233 | return NULL; | |
234 | } | |
232 | } |
65 | 65 | |
66 | 66 | GVirConfigNetworkFilter *gvir_network_filter_get_config |
67 | 67 | (GVirNetworkFilter *filter, |
68 | guint64 flags, | |
68 | guint flags, | |
69 | 69 | GError **err); |
70 | 70 | |
71 | 71 | G_END_DECLS |
207 | 207 | * Returns: (transfer full): the config |
208 | 208 | */ |
209 | 209 | GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, |
210 | guint64 flags, | |
210 | guint flags, | |
211 | 211 | GError **err) |
212 | 212 | { |
213 | 213 | GVirNetworkPrivate *priv = network->priv; |
214 | 214 | gchar *xml; |
215 | 215 | |
216 | 216 | if (!(xml = virNetworkGetXMLDesc(priv->handle, flags))) { |
217 | *err = gvir_error_new_literal(GVIR_NETWORK_ERROR, | |
218 | 0, | |
219 | "Unable to get network XML config"); | |
217 | if (err) | |
218 | *err = gvir_error_new_literal(GVIR_NETWORK_ERROR, | |
219 | 0, | |
220 | "Unable to get network XML config"); | |
220 | 221 | return NULL; |
221 | 222 | } |
222 | 223 | |
223 | #if 0 | |
224 | GVirConfigNetwork *conf = gvir_config_network_new(xml); | |
225 | ||
226 | g_free(xml); | |
224 | GVirConfigNetwork *conf = gvir_config_network_new_from_xml(xml, err); | |
225 | ||
226 | free(xml); | |
227 | 227 | return conf; |
228 | #endif | |
229 | return NULL; | |
230 | } | |
228 | } |
68 | 68 | const gchar *gvir_network_get_uuid(GVirNetwork *network); |
69 | 69 | |
70 | 70 | GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, |
71 | guint64 flags, | |
71 | guint flags, | |
72 | 72 | GError **err); |
73 | 73 | |
74 | 74 | G_END_DECLS |
186 | 186 | * Returns: (transfer full): the config |
187 | 187 | */ |
188 | 188 | GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, |
189 | guint64 flags, | |
189 | guint flags, | |
190 | 190 | GError **err) |
191 | 191 | { |
192 | 192 | GVirNodeDevicePrivate *priv = device->priv; |
193 | 193 | gchar *xml; |
194 | 194 | |
195 | 195 | if (!(xml = virNodeDeviceGetXMLDesc(priv->handle, flags))) { |
196 | *err = gvir_error_new_literal(GVIR_NODE_DEVICE_ERROR, | |
197 | 0, | |
198 | "Unable to get node_device XML config"); | |
196 | if (err) | |
197 | *err = gvir_error_new_literal(GVIR_NODE_DEVICE_ERROR, | |
198 | 0, | |
199 | "Unable to get node_device XML config"); | |
199 | 200 | return NULL; |
200 | 201 | } |
201 | 202 | |
202 | #if 0 | |
203 | GVirConfigNodeDevice *conf = gvir_config_node_device_new(xml); | |
204 | ||
205 | g_free(xml); | |
203 | GVirConfigNodeDevice *conf = gvir_config_node_device_new_from_xml(xml, err); | |
204 | ||
205 | free(xml); | |
206 | 206 | return conf; |
207 | #endif | |
208 | ||
209 | return NULL; | |
210 | } | |
207 | } |
63 | 63 | const gchar *gvir_node_device_get_name(GVirNodeDevice *device); |
64 | 64 | |
65 | 65 | GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, |
66 | guint64 flags, | |
66 | guint flags, | |
67 | 67 | GError **err); |
68 | 68 | |
69 | 69 | G_END_DECLS |
0 | /* | |
1 | * libvirt-gobject-output-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 | #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 | #include "libvirt-gobject-output-stream.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_output_stream_get_type _gvir_output_stream_get_type | |
37 | G_DEFINE_TYPE(GVirOutputStream, gvir_output_stream, G_TYPE_OUTPUT_STREAM); | |
38 | ||
39 | enum | |
40 | { | |
41 | PROP_0, | |
42 | PROP_STREAM | |
43 | }; | |
44 | ||
45 | struct _GVirOutputStreamPrivate | |
46 | { | |
47 | GVirStream *stream; | |
48 | ||
49 | /* pending operation metadata */ | |
50 | GSimpleAsyncResult *result; | |
51 | GCancellable *cancellable; | |
52 | const void * buffer; | |
53 | gsize count; | |
54 | }; | |
55 | ||
56 | static void gvir_output_stream_get_property(GObject *object, | |
57 | guint prop_id, | |
58 | GValue *value, | |
59 | GParamSpec *pspec) | |
60 | { | |
61 | GVirOutputStream *stream = GVIR_OUTPUT_STREAM(object); | |
62 | ||
63 | switch (prop_id) { | |
64 | case PROP_STREAM: | |
65 | g_value_set_object(value, stream->priv->stream); | |
66 | break; | |
67 | ||
68 | default: | |
69 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); | |
70 | } | |
71 | } | |
72 | ||
73 | static void gvir_output_stream_set_property(GObject *object, | |
74 | guint prop_id, | |
75 | const GValue *value, | |
76 | GParamSpec *pspec) | |
77 | { | |
78 | GVirOutputStream *stream = GVIR_OUTPUT_STREAM(object); | |
79 | ||
80 | switch (prop_id) { | |
81 | case PROP_STREAM: | |
82 | stream->priv->stream = g_value_get_object(value); | |
83 | break; | |
84 | ||
85 | default: | |
86 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); | |
87 | } | |
88 | } | |
89 | ||
90 | static void gvir_output_stream_finalize(GObject *object) | |
91 | { | |
92 | GVirOutputStream *stream = GVIR_OUTPUT_STREAM(object); | |
93 | ||
94 | DEBUG("Finalize output stream GVirStream=%p", stream->priv->stream); | |
95 | stream->priv->stream = NULL; // unowned | |
96 | ||
97 | if (G_OBJECT_CLASS(gvir_output_stream_parent_class)->finalize) | |
98 | (*G_OBJECT_CLASS(gvir_output_stream_parent_class)->finalize)(object); | |
99 | } | |
100 | ||
101 | static void | |
102 | gvir_output_stream_write_ready(virStreamPtr st G_GNUC_UNUSED, | |
103 | int events, | |
104 | void *opaque) | |
105 | { | |
106 | GVirOutputStream *stream = GVIR_OUTPUT_STREAM(opaque); | |
107 | GVirOutputStreamPrivate *priv = stream->priv; | |
108 | GSimpleAsyncResult *simple; | |
109 | GError *error = NULL; | |
110 | gssize result; | |
111 | ||
112 | g_return_if_fail(events & VIR_STREAM_EVENT_WRITABLE); | |
113 | ||
114 | result = gvir_stream_send(priv->stream, priv->buffer, priv->count, | |
115 | priv->cancellable, &error); | |
116 | ||
117 | if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { | |
118 | g_warn_if_reached(); | |
119 | return; | |
120 | } | |
121 | ||
122 | simple = stream->priv->result; | |
123 | stream->priv->result = NULL; | |
124 | ||
125 | if (result >= 0) | |
126 | g_simple_async_result_set_op_res_gssize(simple, result); | |
127 | ||
128 | if (error) | |
129 | g_simple_async_result_take_error(simple, error); | |
130 | ||
131 | if (priv->cancellable) { | |
132 | g_object_unref(stream->priv->cancellable); | |
133 | priv->cancellable = NULL; | |
134 | } | |
135 | ||
136 | g_simple_async_result_complete(simple); | |
137 | g_object_unref(simple); | |
138 | ||
139 | return; | |
140 | } | |
141 | ||
142 | static void gvir_output_stream_write_async(GOutputStream *stream, | |
143 | const void *buffer, | |
144 | gsize count, | |
145 | int io_priority G_GNUC_UNUSED, | |
146 | GCancellable *cancellable, | |
147 | GAsyncReadyCallback callback, | |
148 | gpointer user_data) | |
149 | { | |
150 | GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); | |
151 | virStreamPtr handle; | |
152 | ||
153 | g_return_if_fail(GVIR_IS_OUTPUT_STREAM(stream)); | |
154 | g_return_if_fail(output_stream->priv->result == NULL); | |
155 | ||
156 | g_object_get(output_stream->priv->stream, "handle", &handle, NULL); | |
157 | ||
158 | if (virStreamEventAddCallback(handle, VIR_STREAM_EVENT_WRITABLE, | |
159 | gvir_output_stream_write_ready, stream, NULL) < 0) { | |
160 | g_simple_async_report_error_in_idle(G_OBJECT(stream), | |
161 | callback, | |
162 | user_data, | |
163 | G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, | |
164 | "Couldn't add event callback %s", | |
165 | G_STRFUNC); | |
166 | goto end; | |
167 | } | |
168 | ||
169 | output_stream->priv->result = | |
170 | g_simple_async_result_new(G_OBJECT(stream), callback, user_data, | |
171 | gvir_output_stream_write_async); | |
172 | if (cancellable) | |
173 | g_object_ref(cancellable); | |
174 | output_stream->priv->cancellable = cancellable; | |
175 | output_stream->priv->buffer = buffer; | |
176 | output_stream->priv->count = count; | |
177 | ||
178 | end: | |
179 | virStreamFree(handle); | |
180 | } | |
181 | ||
182 | ||
183 | static gssize gvir_output_stream_write_finish(GOutputStream *stream, | |
184 | GAsyncResult *result, | |
185 | GError **error G_GNUC_UNUSED) | |
186 | { | |
187 | GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); | |
188 | GSimpleAsyncResult *simple; | |
189 | virStreamPtr handle; | |
190 | gssize count; | |
191 | ||
192 | g_return_val_if_fail(GVIR_IS_OUTPUT_STREAM(stream), -1); | |
193 | g_object_get(output_stream->priv->stream, "handle", &handle, NULL); | |
194 | ||
195 | simple = G_SIMPLE_ASYNC_RESULT(result); | |
196 | ||
197 | g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == gvir_output_stream_write_async); | |
198 | ||
199 | count = g_simple_async_result_get_op_res_gssize(simple); | |
200 | ||
201 | virStreamEventRemoveCallback(handle); | |
202 | virStreamFree(handle); | |
203 | ||
204 | return count; | |
205 | } | |
206 | ||
207 | ||
208 | static void gvir_output_stream_class_init(GVirOutputStreamClass *klass) | |
209 | { | |
210 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); | |
211 | GOutputStreamClass *goutputstream_class = G_OUTPUT_STREAM_CLASS(klass); | |
212 | ||
213 | g_type_class_add_private(klass, sizeof(GVirOutputStreamPrivate)); | |
214 | ||
215 | gobject_class->finalize = gvir_output_stream_finalize; | |
216 | gobject_class->get_property = gvir_output_stream_get_property; | |
217 | gobject_class->set_property = gvir_output_stream_set_property; | |
218 | ||
219 | goutputstream_class->write_fn = NULL; | |
220 | goutputstream_class->write_async = gvir_output_stream_write_async; | |
221 | goutputstream_class->write_finish = gvir_output_stream_write_finish; | |
222 | ||
223 | g_object_class_install_property(gobject_class, PROP_STREAM, | |
224 | g_param_spec_object("stream", | |
225 | "stream", | |
226 | "GVirStream", | |
227 | GVIR_TYPE_STREAM, G_PARAM_CONSTRUCT_ONLY | | |
228 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | |
229 | } | |
230 | ||
231 | static void gvir_output_stream_init(GVirOutputStream *stream) | |
232 | { | |
233 | stream->priv = G_TYPE_INSTANCE_GET_PRIVATE(stream, GVIR_TYPE_OUTPUT_STREAM, GVirOutputStreamPrivate); | |
234 | } | |
235 | ||
236 | GVirOutputStream* _gvir_output_stream_new(GVirStream *stream) | |
237 | { | |
238 | return GVIR_OUTPUT_STREAM(g_object_new(GVIR_TYPE_OUTPUT_STREAM, "stream", stream, NULL)); | |
239 | } |
0 | /* | |
1 | * libvirt-gobject-output-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_OUTPUT_STREAM_H__ | |
28 | #define __LIBVIRT_GOBJECT_OUTPUT_STREAM_H__ | |
29 | ||
30 | #include <gio/gio.h> | |
31 | #include "libvirt-gobject-stream.h" | |
32 | ||
33 | G_BEGIN_DECLS | |
34 | ||
35 | #define GVIR_TYPE_OUTPUT_STREAM (_gvir_output_stream_get_type ()) | |
36 | #define GVIR_OUTPUT_STREAM(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ | |
37 | GVIR_TYPE_OUTPUT_STREAM, GVirOutputStream)) | |
38 | #define GVIR_OUTPUT_STREAM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \ | |
39 | GVIR_TYPE_OUTPUT_STREAM, GVirOutputStreamClass)) | |
40 | #define GVIR_IS_OUTPUT_STREAM(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \ | |
41 | GVIR_TYPE_OUTPUT_STREAM)) | |
42 | #define GVIR_IS_OUTPUT_STREAM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \ | |
43 | GVIR_TYPE_OUTPUT_STREAM)) | |
44 | #define GVIR_OUTPUT_STREAM_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \ | |
45 | GVIR_TYPE_OUTPUT_STREAM, GVirOutputStreamClass)) | |
46 | ||
47 | typedef struct _GVirOutputStreamPrivate GVirOutputStreamPrivate; | |
48 | typedef struct _GVirOutputStreamClass GVirOutputStreamClass; | |
49 | typedef struct _GVirOutputStream GVirOutputStream; | |
50 | ||
51 | struct _GVirOutputStreamClass | |
52 | { | |
53 | GOutputStreamClass parent_class; | |
54 | }; | |
55 | ||
56 | struct _GVirOutputStream | |
57 | { | |
58 | GOutputStream parent_instance; | |
59 | GVirOutputStreamPrivate *priv; | |
60 | }; | |
61 | ||
62 | GType _gvir_output_stream_get_type (void) G_GNUC_CONST; | |
63 | GVirOutputStream * _gvir_output_stream_new (GVirStream *stream); | |
64 | ||
65 | G_END_DECLS | |
66 | ||
67 | #endif /* __LIBVIRT_GOBJECT_OUTPUT_STREAM_H__ */ |
197 | 197 | * Returns: (transfer full): the config |
198 | 198 | */ |
199 | 199 | GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, |
200 | guint64 flags, | |
200 | guint flags, | |
201 | 201 | GError **err) |
202 | 202 | { |
203 | 203 | GVirSecretPrivate *priv = secret->priv; |
204 | 204 | gchar *xml; |
205 | 205 | |
206 | 206 | if (!(xml = virSecretGetXMLDesc(priv->handle, flags))) { |
207 | *err = gvir_error_new_literal(GVIR_SECRET_ERROR, | |
208 | 0, | |
209 | "Unable to get secret XML config"); | |
207 | if (err) | |
208 | *err = gvir_error_new_literal(GVIR_SECRET_ERROR, | |
209 | 0, | |
210 | "Unable to get secret XML config"); | |
210 | 211 | return NULL; |
211 | 212 | } |
212 | 213 | |
213 | #if 0 | |
214 | GVirConfigSecret *conf = gvir_config_secret_new(xml); | |
215 | ||
216 | g_free(xml); | |
214 | GVirConfigSecret *conf = gvir_config_secret_new_from_xml(xml, err); | |
215 | ||
216 | free(xml); | |
217 | 217 | return conf; |
218 | #endif | |
219 | ||
220 | return NULL; | |
221 | } | |
218 | } |
65 | 65 | const gchar *gvir_secret_get_uuid(GVirSecret *secret); |
66 | 66 | |
67 | 67 | GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, |
68 | guint64 flags, | |
68 | guint flags, | |
69 | 69 | GError **err); |
70 | 70 | |
71 | 71 | G_END_DECLS |
222 | 222 | * Returns: (transfer full): the config |
223 | 223 | */ |
224 | 224 | GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, |
225 | guint64 flags, | |
225 | guint flags, | |
226 | 226 | GError **err) |
227 | 227 | { |
228 | 228 | GVirStoragePoolPrivate *priv = pool->priv; |
229 | 229 | gchar *xml; |
230 | 230 | |
231 | 231 | if (!(xml = virStoragePoolGetXMLDesc(priv->handle, flags))) { |
232 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
233 | 0, | |
234 | "Unable to get storage_pool XML config"); | |
232 | if (err) | |
233 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
234 | 0, | |
235 | "Unable to get storage_pool XML config"); | |
235 | 236 | return NULL; |
236 | 237 | } |
237 | 238 | |
238 | #if 0 | |
239 | GVirConfigStoragePool *conf = gvir_config_storage_pool_new(xml); | |
240 | ||
241 | g_free(xml); | |
239 | GVirConfigStoragePool *conf = gvir_config_storage_pool_new_from_xml(xml, err); | |
240 | ||
241 | free(xml); | |
242 | 242 | return conf; |
243 | #endif | |
244 | return NULL; | |
245 | 243 | } |
246 | 244 | |
247 | 245 | typedef gint (* CountFunction) (virStoragePoolPtr vpool); |
305 | 303 | gboolean ret = FALSE; |
306 | 304 | gint i; |
307 | 305 | virStoragePoolPtr vpool = NULL; |
306 | GError *lerr = NULL; | |
308 | 307 | |
309 | 308 | vpool = priv->handle; |
310 | 309 | |
311 | 310 | if (virStoragePoolRefresh(vpool, 0) < 0) { |
312 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
313 | 0, | |
314 | "Unable to refresh storage pool"); | |
311 | if (err) | |
312 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
313 | 0, | |
314 | "Unable to refresh storage pool"); | |
315 | 315 | goto cleanup; |
316 | 316 | } |
317 | 317 | |
318 | 318 | volumes = fetch_list(vpool, |
319 | "Storage Volumes", | |
320 | virStoragePoolNumOfVolumes, | |
321 | virStoragePoolListVolumes, | |
322 | cancellable, | |
323 | &nvolumes, | |
324 | err); | |
325 | if (*err != NULL) | |
319 | "Storage Volumes", | |
320 | virStoragePoolNumOfVolumes, | |
321 | virStoragePoolListVolumes, | |
322 | cancellable, | |
323 | &nvolumes, | |
324 | &lerr); | |
325 | if (lerr) { | |
326 | g_propagate_error(err, lerr); | |
327 | lerr = NULL; | |
326 | 328 | goto cleanup; |
329 | } | |
327 | 330 | |
328 | 331 | if (g_cancellable_set_error_if_cancelled(cancellable, err)) |
329 | 332 | goto cleanup; |
497 | 500 | g_return_val_if_fail(xml != NULL, NULL); |
498 | 501 | |
499 | 502 | if (!(handle = virStorageVolCreateXML(priv->handle, xml, 0))) { |
500 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
501 | 0, | |
502 | "Failed to create volume"); | |
503 | if (err) | |
504 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
505 | 0, | |
506 | "Failed to create volume"); | |
503 | 507 | return NULL; |
504 | 508 | } |
505 | 509 | |
527 | 531 | * Return value: #True on success, #False otherwise. |
528 | 532 | */ |
529 | 533 | gboolean gvir_storage_pool_build (GVirStoragePool *pool, |
530 | guint64 flags, | |
534 | guint flags, | |
531 | 535 | GError **err) |
532 | 536 | { |
533 | 537 | if (virStoragePoolBuild(pool->priv->handle, flags)) { |
534 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
535 | 0, | |
536 | "Failed to build storage pool"); | |
538 | if (err) | |
539 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
540 | 0, | |
541 | "Failed to build storage pool"); | |
537 | 542 | return FALSE; |
538 | 543 | } |
539 | 544 | |
541 | 546 | } |
542 | 547 | |
543 | 548 | typedef struct { |
544 | guint64 flags; | |
549 | guint flags; | |
545 | 550 | } StoragePoolBuildData; |
546 | 551 | |
547 | 552 | static void |
573 | 578 | * @user_data: (closure): opaque data for callback |
574 | 579 | */ |
575 | 580 | void gvir_storage_pool_build_async (GVirStoragePool *pool, |
576 | guint64 flags, | |
581 | guint flags, | |
577 | 582 | GCancellable *cancellable, |
578 | 583 | GAsyncReadyCallback callback, |
579 | 584 | gpointer user_data) |
631 | 636 | * Return value: #True on success, #False otherwise. |
632 | 637 | */ |
633 | 638 | gboolean gvir_storage_pool_start (GVirStoragePool *pool, |
634 | guint64 flags, | |
639 | guint flags, | |
635 | 640 | GError **err) |
636 | 641 | { |
637 | 642 | if (virStoragePoolCreate(pool->priv->handle, flags)) { |
638 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
639 | 0, | |
640 | "Failed to start storage pool"); | |
643 | if (err) | |
644 | *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, | |
645 | 0, | |
646 | "Failed to start storage pool"); | |
641 | 647 | return FALSE; |
642 | 648 | } |
643 | 649 | |
673 | 679 | * @user_data: (closure): opaque data for callback |
674 | 680 | */ |
675 | 681 | void gvir_storage_pool_start_async (GVirStoragePool *pool, |
676 | guint64 flags, | |
682 | guint flags, | |
677 | 683 | GCancellable *cancellable, |
678 | 684 | GAsyncReadyCallback callback, |
679 | 685 | gpointer user_data) |
65 | 65 | const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool); |
66 | 66 | |
67 | 67 | GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, |
68 | guint64 flags, | |
68 | guint flags, | |
69 | 69 | GError **err); |
70 | 70 | |
71 | 71 | gboolean gvir_storage_pool_refresh(GVirStoragePool *pool, |
88 | 88 | GError **err); |
89 | 89 | |
90 | 90 | gboolean gvir_storage_pool_build (GVirStoragePool *pool, |
91 | guint64 flags, | |
91 | guint flags, | |
92 | 92 | GError **err); |
93 | 93 | void gvir_storage_pool_build_async (GVirStoragePool *pool, |
94 | guint64 flags, | |
94 | guint flags, | |
95 | 95 | GCancellable *cancellable, |
96 | 96 | GAsyncReadyCallback callback, |
97 | 97 | gpointer user_data); |
100 | 100 | GError **err); |
101 | 101 | |
102 | 102 | gboolean gvir_storage_pool_start (GVirStoragePool *pool, |
103 | guint64 flags, | |
103 | guint flags, | |
104 | 104 | GError **err); |
105 | 105 | void gvir_storage_pool_start_async (GVirStoragePool *pool, |
106 | guint64 flags, | |
106 | guint flags, | |
107 | 107 | GCancellable *cancellable, |
108 | 108 | GAsyncReadyCallback callback, |
109 | 109 | gpointer user_data); |
197 | 197 | * Returns: (transfer full): the config |
198 | 198 | */ |
199 | 199 | GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, |
200 | guint64 flags, | |
200 | guint flags, | |
201 | 201 | GError **err) |
202 | 202 | { |
203 | 203 | GVirStorageVolPrivate *priv = vol->priv; |
204 | 204 | gchar *xml; |
205 | 205 | |
206 | 206 | if (!(xml = virStorageVolGetXMLDesc(priv->handle, flags))) { |
207 | *err = gvir_error_new_literal(GVIR_STORAGE_VOL_ERROR, | |
208 | 0, | |
209 | "Unable to get storage_vol XML config"); | |
207 | if (err) | |
208 | *err = gvir_error_new_literal(GVIR_STORAGE_VOL_ERROR, | |
209 | 0, | |
210 | "Unable to get storage_vol XML config"); | |
210 | 211 | return NULL; |
211 | 212 | } |
212 | 213 | |
213 | #if 0 | |
214 | GVirConfigStorageVol *conf = gvir_config_storage_vol_new(xml); | |
215 | ||
216 | g_free(xml); | |
214 | GVirConfigStorageVol *conf = gvir_config_storage_vol_new_from_xml(xml, err); | |
215 | ||
216 | free(xml); | |
217 | 217 | return conf; |
218 | #endif | |
219 | return NULL; | |
220 | } | |
218 | } |
64 | 64 | const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol); |
65 | 65 | |
66 | 66 | GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, |
67 | guint64 flags, | |
67 | guint flags, | |
68 | 68 | GError **err); |
69 | 69 | |
70 | 70 | G_END_DECLS |
31 | 31 | #include "libvirt-gobject-compat.h" |
32 | 32 | |
33 | 33 | #include "libvirt-gobject/libvirt-gobject-input-stream.h" |
34 | #include "libvirt-gobject/libvirt-gobject-output-stream.h" | |
34 | 35 | |
35 | 36 | extern gboolean debugFlag; |
36 | 37 | |
43 | 44 | { |
44 | 45 | virStreamPtr handle; |
45 | 46 | GInputStream *input_stream; |
46 | gboolean in_dispose; | |
47 | GOutputStream *output_stream; | |
47 | 48 | }; |
48 | 49 | |
49 | 50 | G_DEFINE_TYPE(GVirStream, gvir_stream, G_TYPE_IO_STREAM); |
76 | 77 | } |
77 | 78 | |
78 | 79 | |
80 | static GOutputStream* gvir_stream_get_output_stream(GIOStream *io_stream) | |
81 | { | |
82 | GVirStream *self = GVIR_STREAM(io_stream); | |
83 | ||
84 | if (self->priv->output_stream == NULL) | |
85 | self->priv->output_stream = (GOutputStream *)_gvir_output_stream_new(self); | |
86 | ||
87 | return self->priv->output_stream; | |
88 | } | |
89 | ||
90 | ||
79 | 91 | static gboolean gvir_stream_close(GIOStream *io_stream, |
80 | 92 | GCancellable *cancellable, G_GNUC_UNUSED GError **error) |
81 | 93 | { |
84 | 96 | if (self->priv->input_stream) |
85 | 97 | g_input_stream_close(self->priv->input_stream, cancellable, NULL); |
86 | 98 | |
87 | if (self->priv->in_dispose) | |
88 | return TRUE; | |
99 | if (self->priv->output_stream) | |
100 | g_output_stream_close(self->priv->output_stream, cancellable, NULL); | |
89 | 101 | |
90 | 102 | return TRUE; /* FIXME: really close the stream? */ |
91 | 103 | } |
200 | 212 | object_class->set_property = gvir_stream_set_property; |
201 | 213 | |
202 | 214 | stream_class->get_input_stream = gvir_stream_get_input_stream; |
215 | stream_class->get_output_stream = gvir_stream_get_output_stream; | |
203 | 216 | stream_class->close_fn = gvir_stream_close; |
204 | 217 | stream_class->close_async = gvir_stream_close_async; |
205 | 218 | stream_class->close_finish = gvir_stream_close_finish; |
338 | 351 | |
339 | 352 | return r; |
340 | 353 | } |
354 | ||
355 | ||
356 | /** | |
357 | * gvir_stream_send: | |
358 | * @stream: the stream | |
359 | * @buffer: a buffer to write data from (which should be at least @size | |
360 | * bytes long). | |
361 | * @size: the number of bytes you want to write to the stream | |
362 | * @cancellable: (allow-none): a %GCancellable or %NULL | |
363 | * @error: #GError for error reporting, or %NULL to ignore. | |
364 | * | |
365 | * Send data (up to @size bytes) from a stream. | |
366 | * On error -1 is returned and @error is set accordingly. | |
367 | * | |
368 | * gvir_stream_send() can return any number of bytes, up to | |
369 | * @size. If more than @size bytes have been sendd, the additional | |
370 | * data will be returned in future calls to gvir_stream_send(). | |
371 | * | |
372 | * If there is no data available, a %G_IO_ERROR_WOULD_BLOCK error will be | |
373 | * returned. | |
374 | * | |
375 | * Returns: Number of bytes read, or 0 if the end of stream reached, | |
376 | * or -1 on error. | |
377 | */ | |
378 | gssize gvir_stream_send(GVirStream *self, const gchar *buffer, gsize size, | |
379 | GCancellable *cancellable, GError **error) | |
380 | { | |
381 | int got; | |
382 | ||
383 | g_return_val_if_fail(GVIR_IS_STREAM(self), -1); | |
384 | g_return_val_if_fail(buffer != NULL, -1); | |
385 | ||
386 | if (g_cancellable_set_error_if_cancelled (cancellable, error)) | |
387 | return -1; | |
388 | ||
389 | got = virStreamSend(self->priv->handle, buffer, size); | |
390 | ||
391 | if (got == -2) { /* blocking */ | |
392 | g_set_error(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK, NULL); | |
393 | } else if (got < 0) { | |
394 | g_set_error(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, | |
395 | "Got virStreamRecv error in %s", G_STRFUNC); | |
396 | } | |
397 | ||
398 | return got; | |
399 | } | |
400 | ||
401 | struct stream_source_helper { | |
402 | GVirStream *self; | |
403 | GVirStreamSourceFunc func; | |
404 | gpointer user_data; | |
405 | }; | |
406 | ||
407 | static int | |
408 | stream_source(virStreamPtr st G_GNUC_UNUSED, | |
409 | char *bytes, size_t nbytes, void *opaque) | |
410 | { | |
411 | struct stream_source_helper *helper = opaque; | |
412 | ||
413 | return helper->func(helper->self, bytes, nbytes, helper->user_data); | |
414 | } | |
415 | ||
416 | /** | |
417 | * gvir_stream_send_all: | |
418 | * @stream: the stream | |
419 | * @func: (scope notified): the callback for writing data to application | |
420 | * @user_data: (closure): data to be passed to @callback | |
421 | * Returns: the number of bytes consumed or -1 upon error | |
422 | * | |
423 | * Send the entire data stream, sending the data to the | |
424 | * requested data source. This is simply a convenient alternative | |
425 | * to virStreamRecv, for apps that do blocking-I/o. | |
426 | */ | |
427 | gssize | |
428 | gvir_stream_send_all(GVirStream *self, GVirStreamSourceFunc func, gpointer user_data, GError **err) | |
429 | { | |
430 | struct stream_source_helper helper = { | |
431 | .self = self, | |
432 | .func = func, | |
433 | .user_data = user_data | |
434 | }; | |
435 | int r; | |
436 | ||
437 | g_return_val_if_fail(GVIR_IS_STREAM(self), -1); | |
438 | g_return_val_if_fail(func != NULL, -1); | |
439 | ||
440 | r = virStreamSendAll(self->priv->handle, stream_source, &helper); | |
441 | if (r < 0) { | |
442 | if (err != NULL) | |
443 | *err = gvir_error_new_literal(GVIR_STREAM_ERROR, | |
444 | 0, | |
445 | "Unable to perform SendAll"); | |
446 | } | |
447 | ||
448 | return r; | |
449 | } |
70 | 70 | * Returns: the number of bytes filled, 0 upon end |
71 | 71 | * of file, or -1 upon error |
72 | 72 | */ |
73 | typedef gint (* GVirStreamSinkFunc) (GVirStream *stream, | |
74 | const gchar *buf, | |
75 | gsize nbytes, | |
76 | gpointer user_data); | |
73 | typedef gint (* GVirStreamSinkFunc)(GVirStream *stream, | |
74 | const gchar *buf, | |
75 | gsize nbytes, | |
76 | gpointer user_data); | |
77 | ||
78 | /** | |
79 | * GVirStreamSourceFunc: | |
80 | * @stream: a #GVirStream | |
81 | * @buf: (out) (array length=nbytes) (transfer none): data pointer | |
82 | * @nbytes: data size | |
83 | * @user_data: user data passed to the function | |
84 | * Returns: the number of bytes filled, 0 upon end | |
85 | * of file, or -1 upon error | |
86 | */ | |
87 | typedef gint (* GVirStreamSourceFunc)(GVirStream *stream, | |
88 | gchar *buf, | |
89 | gsize nbytes, | |
90 | gpointer user_data); | |
77 | 91 | |
78 | 92 | GType gvir_stream_get_type(void); |
79 | 93 | GType gvir_stream_handle_get_type(void); |
80 | 94 | |
81 | gssize gvir_stream_receive_all(GVirStream *stream, GVirStreamSinkFunc func, gpointer user_data, GError **err); | |
95 | gssize gvir_stream_receive_all(GVirStream *stream, GVirStreamSinkFunc func, gpointer user_data, GError **error); | |
82 | 96 | gssize gvir_stream_receive(GVirStream *stream, gchar *buffer, gsize size, GCancellable *cancellable, GError **error); |
97 | ||
98 | gssize gvir_stream_send_all(GVirStream *stream, GVirStreamSourceFunc func, gpointer user_data, GError **error); | |
99 | gssize gvir_stream_send(GVirStream *stream, const gchar *buffer, gsize size, GCancellable *cancellable, GError **error); | |
83 | 100 | |
84 | 101 | G_END_DECLS |
85 | 102 |
27 | 27 | gvir_connection_find_storage_pool_by_name; |
28 | 28 | gvir_connection_create_domain; |
29 | 29 | gvir_connection_create_storage_pool; |
30 | gvir_connection_start_domain; | |
30 | 31 | |
31 | 32 | gvir_domain_device_get_type; |
32 | 33 | |
52 | 53 | gvir_domain_shutdown; |
53 | 54 | gvir_domain_reboot; |
54 | 55 | gvir_domain_get_config; |
56 | gvir_domain_set_config; | |
55 | 57 | gvir_domain_get_info; |
56 | 58 | gvir_domain_screenshot; |
57 | 59 |