-
Notifications
You must be signed in to change notification settings - Fork 0
add graphics event handling and undefine flags support #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -570,6 +570,22 @@ public static extern int StoragePoolEventRegisterAny(IntPtr conn, IntPtr pool, i | |
| [MarshalAs(UnmanagedType.FunctionPtr)] VirConnectStoragePoolGenericEventCallback cb, | ||
| IntPtr opaque, [MarshalAs(UnmanagedType.FunctionPtr)] VirFreeCallback ff); | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Adds a callback to receive notifications of graphics events. | ||
| /// </summary> | ||
| /// <param name="conn">pointer to the connection</param> | ||
| /// <param name="dom">pointer to the domain or NULL for any</param> | ||
| /// <param name="eventId">events to listen to</param> | ||
| /// <param name="cb">callback to the function handling domain events</param> | ||
| /// <param name="opaque">opaque data to pass on to the callback</param> | ||
| /// <param name="ff">optional function to deallocate opaque when not used anymore</param> | ||
| /// <returns>t shall take a reference to it, by calling virDomainRef. The reference can be released once the object is no longer required by calling virDomainFree. Returns 0 on success, -1 on failure</returns> | ||
| [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virConnectDomainEventRegisterAny")] | ||
| public static extern int DomainEventGraphicsRegisterAny(IntPtr conn, IntPtr pool, VirDomainEventID eventId, | ||
|
||
| [MarshalAs(UnmanagedType.FunctionPtr)] VirConnectDomainEventGraphicsCallback cb, | ||
| IntPtr opaque, [MarshalAs(UnmanagedType.FunctionPtr)] VirFreeCallback ff); | ||
|
|
||
| /// <summary> | ||
| /// Adds a callback to receive notifications of storage pool events. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -744,6 +744,16 @@ public static int InterfaceStats(IntPtr dom, string path, out VirDomainInterface | |||||||||||||||||||||||||||||||||||||
| [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDomainUndefine")] | ||||||||||||||||||||||||||||||||||||||
| public static extern int Undefine(IntPtr domain); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||
| /// Undefine a domain. If the domain is running, it's converted to transient domain, without stopping it. If the domain is inactive, the domain configuration is removed. | ||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||
| /// <param name="domain">pointer to a defined domain</param> | ||||||||||||||||||||||||||||||||||||||
| /// <param name="flags">an OR'ed set of virDomainUndefineFlags</param> | ||||||||||||||||||||||||||||||||||||||
| /// <returns>0 in case of success, -1 in case of error | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| /// <returns>0 in case of success, -1 in case of error | |
| /// <returns>0 in case of success, -1 in case of error</returns> |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimise the use of unmanaged code.
| public static extern int UndefineFlags(IntPtr domain, VirDomainUndefineFlagsValues flags); | |
| /// <summary> | |
| private static extern int UndefineFlags(IntPtr domain, VirDomainUndefineFlagsValues flags); | |
| /// <summary> | |
| /// Managed wrapper for UndefineFlags. Undefines a domain with the specified flags. | |
| /// </summary> | |
| /// <param name="domain">Pointer to a defined domain</param> | |
| /// <param name="flags">An OR'ed set of virDomainUndefineFlags</param> | |
| /// <returns>True if successful, false otherwise</returns> | |
| public static bool UndefineDomainWithFlags(IntPtr domain, VirDomainUndefineFlagsValues flags) | |
| { | |
| int result = UndefineFlags(domain, flags); | |
| return result == 0; | |
| } | |
| /// <summary> |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,24 +31,34 @@ namespace IDNT.AppBasics.Virtualization.Libvirt.Native | |||||||||
| ///<summary> | ||||||||||
| /// class for libvirt qemu specific methods | ||||||||||
| ///</summary> | ||||||||||
| public class NativeVirQemu | ||||||||||
| public static class NativeVirQemu | ||||||||||
| { | ||||||||||
| private const int MaxStringLength = 1024; | ||||||||||
| [DllImport("libvirt-qemu.so.0", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDomainQemuMonitorCommand")] | ||||||||||
| private static extern int virDomainQemuMonitorCommand( | ||||||||||
|
||||||||||
| IntPtr domain, | ||||||||||
| [MarshalAs(UnmanagedType.LPUTF8Str)] string cmd, | ||||||||||
| out IntPtr result, | ||||||||||
| VirDomainQemuMonitorCommandFlags flags); | ||||||||||
|
|
||||||||||
| [DllImport("libvirt-qemu-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virDomainQemuMonitorCommand")] | ||||||||||
| private static extern int MonitorCommandImpl(IntPtr domain, string cmd, [Out] StringBuilder result, uint flags); | ||||||||||
| [DllImport("libvirt.so.0", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virFree")] | ||||||||||
| private static extern int virFree(IntPtr ptr); | ||||||||||
|
Comment on lines
+43
to
+44
|
||||||||||
| [DllImport("libvirt.so.0", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virFree")] | |
| private static extern int virFree(IntPtr ptr); |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this call with a call to managed code if possible.
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory allocated by libvirt should be freed using virFree (imported at line 43-44), not NativeFunctions.Free which calls the Windows C runtime's free(). Using the wrong free function can cause crashes or memory corruption. Replace with virFree(resultPtr);
| NativeFunctions.Free(resultPtr); | |
| virFree(resultPtr); |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this call with a call to managed code if possible.
| NativeFunctions.Free(resultPtr); | |
| virFree(resultPtr); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,4 +39,23 @@ namespace IDNT.AppBasics.Virtualization.Libvirt.Native | |||||
| [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||||||
| public delegate void VirConnectDomainEventCallback(IntPtr conn, IntPtr dom, [MarshalAs(UnmanagedType.I4)] VirDomainEventType evt, int detail, IntPtr opaque); | ||||||
|
|
||||||
|
|
||||||
| /// <summary> | ||||||
| /// The callback signature to use when registering for an event of type VIR_DOMAIN_EVENT_ID_GRAPHICS with virConnectDomainEventRegisterAny() | ||||||
| /// </summary> | ||||||
| /// <param name="conn">virConnect connection </param> | ||||||
| /// <param name="dom">The domain on which the event occured</param> | ||||||
|
||||||
| /// <param name="dom">The domain on which the event occured</param> | |
| /// <param name="dom">The domain on which the event occurred</param> |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||
| using System; | ||||||||
| using System.Collections.Generic; | ||||||||
| using System.Linq; | ||||||||
| using System.Threading.Tasks; | ||||||||
|
Comment on lines
+2
to
+4
|
||||||||
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||
| using System; | ||||||||
| using System.Collections.Generic; | ||||||||
| using System.Linq; | ||||||||
| using System.Threading.Tasks; | ||||||||
|
Comment on lines
+2
to
+4
|
||||||||
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value documentation appears to be copied from another method and starts with a malformed fragment 't shall take a reference...'. This should describe the return value for DomainEventGraphicsRegisterAny. Update to something like: 'Returns a callback identifier on success, -1 on failure. The callback identifier can be used to deregister the callback.'