From 0e574308e366f01221b800022b383ee0f45973eb Mon Sep 17 00:00:00 2001 From: Anton Podavalov <a.podavalov@xxxxxxxxx> Date: Wed, 15 Jun 2011 15:55:18 +0400 Subject: [PATCH] Added virStream bindings: Abort, EventAddCallback, EventRemoveCallback, EventUpdateCallback, Finish, Free, New --- Stream.cs | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- Types.cs | 8 +++++ 2 files changed, 87 insertions(+), 13 deletions(-) diff --git a/Stream.cs b/Stream.cs index bef3719..650a011 100644 --- a/Stream.cs +++ b/Stream.cs @@ -2,10 +2,14 @@ * Copyright (C) * Arnaud Champion <arnaud.champion@xxxxxxxxxx> * JaromÃr Äervenka <cervajz@xxxxxxxxxxx> + * Anton Podavalov <a.podavalov@xxxxxxxxx> * * See COPYING.LIB for the License of this software */ +using System; +using System.Runtime.InteropServices; + namespace Libvirt { /// <summary> @@ -13,24 +17,86 @@ namespace Libvirt /// </summary> public class Stream { - // TODO virStreamAbort - - // TODO virStreamEventAddCallback + /// <summary> + /// Request that the in progress data transfer be cancelled abnormally before the end of + /// the stream has been reached. For output streams this can be used to inform the driver + /// that the stream is being terminated early. For input streams this can be used to inform + /// the driver that it should stop sending data + /// </summary> + /// <param name="stream">pointer to the stream object</param> + /// <returns>0 on success, -1 upon error</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamAbort")] + public static extern int Abort(IntPtr stream); + /// <summary> + /// Register a callback to be notified when a stream becomes writable, or readable. + /// This is most commonly used in conjunction with non-blocking data streams to integrate + /// into an event loop + /// </summary> + /// <param name="stream">pointer to the stream object</param> + /// <param name="events">set of events to monitor</param> + /// <param name="cb">callback to invoke when an event occurs</param> + /// <param name="opaque">application defined data</param> + /// <param name="ff">callback to free @opaque data</param> + /// <returns>0 on success, -1 upon error</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamEventAddCallback")] + public static extern int EventAddCallback(IntPtr stream, int events, [MarshalAs(UnmanagedType.FunctionPtr)] StreamEventCallback cb, IntPtr opaque, [MarshalAs(UnmanagedType.FunctionPtr)] FreeCallback ff); // TODO virStreamEventCallback - // TODO virStreamEventRemoveCallback - - // TODO virStreamEventUpdateCallback - - // TODO virStreamFinish - - // TODO virStreamFree - - // TODO virStreamNew + /// <summary> + /// Remove an event callback from the stream + /// </summary> + /// <param name="stream">pointer to the stream object</param> + /// <returns>0 on success, -1 on error</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamEventRemoveCallback")] + public static extern int EventRemoveCallback(IntPtr stream); + /// <summary> + /// Remove an event callback from the stream + /// </summary> + /// <param name="stream">pointer to the stream object</param> + /// <param name="events">set of events to monitor</param> + /// <returns>0 on success, -1 if no callback is registered</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamEventUpdateCallback")] + public static extern int EventUpdateCallback(IntPtr stream, int events); + /// <summary> + /// Indicate that there is no further data is to be transmitted on the stream. + /// For output streams this should be called once all data has been written. + /// For input streams this should be called once <see cref="Recv" /> returns end-of-file. + /// This method is a synchronization point for all asynchronous errors, so if this + /// returns a success code the application can be sure that all data has been + /// successfully processed. + /// </summary> + /// <param name="stream">pointer to the stream object</param> + /// <returns>0 on success, -1 upon error</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamFinish")] + public static extern int Finish(IntPtr stream); + /// <summary> + /// Decrement the reference count on a stream, releasing the stream object + /// if the reference count has hit zero. There must not be an active data transfer + /// in progress when releasing the stream. If a stream needs to be disposed of prior + /// to end of stream being reached, then the virStreamAbort function should be called + /// first + /// </summary> + /// <param name="stream">pointer to the stream object</param> + /// <returns>0 upon success, -1 on error</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamFree")] + public static extern int Free(IntPtr stream); + /// <summary> + /// Creates a new stream object which can be used to perform streamed I/O with other + /// public API function. When no longer needed, a stream object must be released with + /// virStreamFree. If a data stream has been used, then the application must call + /// virStreamFinish or @Abort before free'ing to, in order to notify the driver + /// of termination. If a non-blocking data stream is required passed VIR_STREAM_NONBLOCK + /// for flags, otherwise pass 0. + /// </summary> + /// <param name="conn">pointer to the connection</param> + /// <param name="flags">control features of the stream</param> + /// <returns>the new stream, or NULL upon error</returns> + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamNew")] + public static extern int New(IntPtr conn, uint flags); // TODO virStreamRecv - + // TODO virStreamRecvAll // TODO virStreamRef diff --git a/Types.cs b/Types.cs index 723355b..67ea002 100644 --- a/Types.cs +++ b/Types.cs @@ -118,6 +118,14 @@ namespace Libvirt /// <param name="cbdata">user data passed to callback</param> /// <returns></returns> public delegate int ConnectAuthCallback(ref ConnectCredential[] creds, IntPtr cbdata); + /// <summary> + /// Callback for receiving stream events. The callback will be invoked once for each event which is pending. + /// </summary> + /// <param name="stream">stream on which the event occurred</param> + /// <param name="events">bitset of events from virEventHandleType constants</param> + /// <param name="opaque">user data registered with handle</param> + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void StreamEventCallback(IntPtr stream, int events, IntPtr opaque); #endregion #region structs -- 1.7.4.1
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list