2011/4/14 Matthias Bolte <matthias.bolte(a)googlemail.com>
2011/4/14 kadir yüceer <kadiryuceer(a)gmail.com>:
> Hi all,
>
> Quick question:
> When the hypervisor triggers a callback which is registered for generic
> events, (assuming I'm connected through qemu+tcp) where exactly is the
> callback triggered? On the hypervisor host or on my host?
>
> Regards
> Kadir
>
The event system is more complex.
The hypervisor/connection driver add events to a queue. The events
from this queue are transported to the client and can trigger you
registered callbacks.
In order to have your callbacks called you need to register an "event
implementation" that is responsible for driving the event delivery.
Recent libvirt exposed it's default "event implementation" via
virEventRegisterDefaultImpl().
In order to have events delivered to your callbacks you need to call
virEventRegisterDefaultImpl() or virEventRegisterImpl() with your own
"event implementation".
I assume you're still talking about the Java bindings here then you
hit the problem that the bindings are incomplete and don't export
virEventRegisterImpl() nor virEventRegisterDefaultImpl() yet. This
means that the event related part of the libvirt API can not be used
from the Java bindings yet.
A totally untested patch to add virEventRegisterDefaultImpl() looks like
this:
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java
b/src/main/java/org/libvirt/jna/Libvirt.java
index 2c8c03d..5b73859 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -373,4 +373,7 @@ public interface Libvirt extends Library {
public int virNWFilterGetUUID(NetworkFilterPointer
virNWFilterPtr, byte[] uuidString);
public int virNWFilterGetUUIDString(NetworkFilterPointer
virNWFilterPtr, byte[] uuidString);
public int virNWFilterUndefine(NetworkFilterPointer virNWFilterPtr);
+
+ // Event Methods
+ public int virEventRegisterDefaultImpl(void);
}
Then import org.libvirt.jna.Libvirt in your code and call:
Libvirt.INSTANCE.virEventRegisterDefaultImpl()
This _should_ register the default event implementation and make
events work for you assuming the rest of your event related code is
correct.
Matthias
First of all, thanks for the answer Matthias, I've been looking for help for
some time.
I had already tried your suggestion, I added the function just as the same
way you did above, and I have this error:
Exception in thread "main"* java.lang.UnsatisfiedLinkError: Error looking up
function 'virEventRegisterDefaultImpl': /usr/local/lib/libvirt.so: undefined
symbol: virEventRegisterDefaultImpl*
at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:345)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:325)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at $Proxy0.virEventRegisterDefaultImpl(Unknown Source)
at novatest_v03.MainFrame.main(MainFrame.java:168)
I did not post not go too technical. I have the feeling that I need to
arrange one more step to satisfy the link to java bindings, because I've
tested event-driving in C and it works fine. Since I could not figure out if
I can do it on binding side or it should be done originally by the driver,
I've posted my question.
So, any comments about how can I complete the link to C API? Maybe how to
edit this "libvirt.so"?
Regards
Kadir
PS: Everything else works fine, libvirtd running, I can command to domains,
etc. I can even register my own callback and register it via
Connect.setErrorCallback(). I assume only missing thing is the link.