[libvirt] [libvirt-csharp][PATCH] Make examples works on mono compiled in 64 bits, simply the ConnectOpenAuth process, and finalise renaming

?Hi, I have finally find the problem with examples on mono compiled in 64 bits. The problem was the "ToInt32" method of an IntPtr which failed on mono 64 bits (have to use ToInt64 instead). This path solve this problem. Also, I have put marshaling complexity of the ConnectOpenAuth callback in bindings, this make the callback of ConnectOpenAuth more simple to achieve the authentification. In the example, the callback is treated like this : private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata) { AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData)); foreach (ConnectCredential cred in creds) { switch (cred.type) { case ConnectCredentialType.VIR_CRED_AUTHNAME: // Fill the user name cred.Result = authData.user_name; break; case ConnectCredentialType.VIR_CRED_PASSPHRASE: // Fill the password cred.Result = authData.password; break; default: return -1; } } return 0; } The bindings user has no marshaling to do, and believe me, it's simpler. Finally, this patch finalize renaming. Best regards, Arnaud Champion

?Oops, I have made a little mistake that make the example not compiling. This patch make it works, sorry :S From: arnaud.champion@devatom.fr Sent: Wednesday, October 27, 2010 1:50 PM To: libvir-list@redhat.com Subject: [libvirt] [libvirt-csharp][PATCH] Make examples works on monocompiled in 64 bits, simply the ConnectOpenAuth process,and finalise renaming Hi, I have finally find the problem with examples on mono compiled in 64 bits. The problem was the "ToInt32" method of an IntPtr which failed on mono 64 bits (have to use ToInt64 instead). This path solve this problem. Also, I have put marshaling complexity of the ConnectOpenAuth callback in bindings, this make the callback of ConnectOpenAuth more simple to achieve the authentification. In the example, the callback is treated like this : private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata) { AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData)); foreach (ConnectCredential cred in creds) { switch (cred.type) { case ConnectCredentialType.VIR_CRED_AUTHNAME: // Fill the user name cred.Result = authData.user_name; break; case ConnectCredentialType.VIR_CRED_PASSPHRASE: // Fill the password cred.Result = authData.password; break; default: return -1; } } return 0; } The bindings user has no marshaling to do, and believe me, it's simpler. Finally, this patch finalize renaming. Best regards, Arnaud Champion -------------------------------------------------------------------------------- -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

?Oops again, a little mistake again :S In mono, we can't loop thru ref array objects. Sorry Arnaud From: arnaud.champion@devatom.fr Sent: Wednesday, October 27, 2010 2:05 PM To: arnaud.champion@devatom.fr ; libvir-list@redhat.com Subject: Re: [libvirt] [libvirt-csharp][PATCH] Make examples works on monocompiled in 64 bits, simply the ConnectOpenAuth process,and finalise renaming Oops, I have made a little mistake that make the example not compiling. This patch make it works, sorry :S From: arnaud.champion@devatom.fr Sent: Wednesday, October 27, 2010 1:50 PM To: libvir-list@redhat.com Subject: [libvirt] [libvirt-csharp][PATCH] Make examples works on monocompiled in 64 bits, simply the ConnectOpenAuth process,and finalise renaming Hi, I have finally find the problem with examples on mono compiled in 64 bits. The problem was the "ToInt32" method of an IntPtr which failed on mono 64 bits (have to use ToInt64 instead). This path solve this problem. Also, I have put marshaling complexity of the ConnectOpenAuth callback in bindings, this make the callback of ConnectOpenAuth more simple to achieve the authentification. In the example, the callback is treated like this : private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata) { AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData)); foreach (ConnectCredential cred in creds) { switch (cred.type) { case ConnectCredentialType.VIR_CRED_AUTHNAME: // Fill the user name cred.Result = authData.user_name; break; case ConnectCredentialType.VIR_CRED_PASSPHRASE: // Fill the password cred.Result = authData.password; break; default: return -1; } } return 0; } The bindings user has no marshaling to do, and believe me, it's simpler. Finally, this patch finalize renaming. Best regards, Arnaud Champion -------------------------------------------------------------------------------- -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

2010/10/27 <arnaud.champion@devatom.fr>:
Oops again, a little mistake again :S
In mono, we can't loop thru ref array objects.
Sorry
Arnaud From: arnaud.champion@devatom.fr Sent: Wednesday, October 27, 2010 2:05 PM To: arnaud.champion@devatom.fr ; libvir-list@redhat.com Subject: Re: [libvirt] [libvirt-csharp][PATCH] Make examples works on monocompiled in 64 bits, simply the ConnectOpenAuth process,and finalise renaming Oops, I have made a little mistake that make the example not compiling. This patch make it works, sorry :S From: arnaud.champion@devatom.fr Sent: Wednesday, October 27, 2010 1:50 PM To: libvir-list@redhat.com Subject: [libvirt] [libvirt-csharp][PATCH] Make examples works on monocompiled in 64 bits, simply the ConnectOpenAuth process,and finalise renaming Hi,
I have finally find the problem with examples on mono compiled in 64 bits. The problem was the "ToInt32" method of an IntPtr which failed on mono 64 bits (have to use ToInt64 instead). This path solve this problem. Also, I have put marshaling complexity of the ConnectOpenAuth callback in bindings, this make the callback of ConnectOpenAuth more simple to achieve the authentification. In the example, the callback is treated like this :
private static int AuthCallback(ref ConnectCredential[] creds, IntPtr cbdata) { AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData)); foreach (ConnectCredential cred in creds) { switch (cred.type) { case ConnectCredentialType.VIR_CRED_AUTHNAME: // Fill the user name cred.Result = authData.user_name; break; case ConnectCredentialType.VIR_CRED_PASSPHRASE: // Fill the password cred.Result = authData.password; break; default: return -1; } } return 0; }
The bindings user has no marshaling to do, and believe me, it's simpler.
Finally, this patch finalize renaming.
Best regards,
Arnaud Champion
Okay, I smashed all three into one patch because the later two are just incremental fixes for the first one. I also pulled this over from your "add new sample virEventRegisterImpl" patch, because it's an additional incremental fix. diff --git a/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs b/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs index 0b8bbf8..ebccb11 100644 --- a/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs +++ b/examples/MonoDevelop/virConnectOpenAuth/MainWindow.cs @@ -139,6 +139,7 @@ public partial class MainWindow : Gtk.Window AuthData authData = (AuthData)Marshal.PtrToStructure(cbdata, typeof(AuthData)); for (int i = 0; i < creds.Length; i++) { + ConnectCredential cred = creds[i]; switch (cred.type) { case ConnectCredentialType.VIR_CRED_AUTHNAME: I had to rebase your patch onto the HEAD of http://libvirt.org/git/?p=libvirt-csharp.git;a=summary and I removed some trailing white spaces. I tested it and it works on Ubuntu 64bit and I can connect to an ESX server with the virConnectOpenAuth example. I pushed the result. Matthias
participants (2)
-
arnaud.champion@devatom.fr
-
Matthias Bolte