[libvirt] Using callback under Windows compiling of libvirt library

Matthias Bolte matthias.bolte at googlemail.com
Thu Mar 18 10:39:57 UTC 2010


2010/3/18 Dev.Atom <arnaud.champion at devatom.fr>:
> Hi,
>
> I have compiled LibVirt 0.7.4 under mingw, and I want to use it with domain
> callback. Here is a a code sample of my situation (I'm using visual studio)

Did you compile it on Windows, or cross-compile it from Linux?

>
> static
>
> int domain_event(virConnectPtr conn,
>
> virDomainPtr dom,
>
> int evt,
>
> int detail,
>
> void *opaque)
>
> {
>
> bool test = true;
>
> return 0;
>
> }
>
> int
>
> _tmain(int argc, _TCHAR* argv[])
>
> {
>
> virConnectPtr conn = virConnectOpen(
>
> "qemu+tcp://192.168.220.198/session");
>
> // Set Callback
>
> int cbresult = virConnectDomainEventRegister(conn, domain_event, NULL,
> NULL);
>
> // Lookup Domain
>
> virDomainPtr dom = virDomainLookupByName(conn,
>
> "Test1");
>
> if (virDomainIsActive(dom) == 1)
>
> {
>
> // Start Domain
>
> int startDom = virDomainCreate(dom);
>
> if (startDom != 0)
>
> {
>
> virErrorPtr e = virGetLastError();
>
> bool test = true;
>
> }
>
> }
>
> else
>
> {
>
> // Stop Domain
>
> int StopDom = virDomainDestroy(dom);
>
> if (StopDom != 0)
>
> {
>
> virErrorPtr e = virGetLastError();
>
> bool test = true;
>
> }
>
> }
>
> return 0;
>
> }

This code is incomplete, you're missing the event-handling, see the
virEventRegisterImpl function.

Have you tried the domain-event example yet? See
examples/domain-events/events-c/event-test.c in the libvirt codebase.

>
> This code works well when I did'nt use callbacks, but when I use it, it
> throw an error at the virDomainCreate or virDomainDestroy call. In the
> application windows (console) I have an "unmarshaling msg", I have study the
> case it comme from the call of "xdr_string" method in the
> "xdr_remote_nonull_string" method (remote_protocol.c).
>
> I think, the xdr_string method is unable to marshall strings from the XDR*
> object to a char**.
>

Where did you get your XDR lib from? I'm using libportablexdr [1]
version 4.9.1 on Windows, but had to patch it to get it compile
correctly with MinGW.

This may be a bug in your XDR lib, or may be a problem in the way
libvirt uses XDR, or it's just a symptom of that fact that you try to
use domain events without registering event-handling first.

[1] http://people.redhat.com/~rjones/portablexdr/

Matthias




More information about the libvir-list mailing list