2 #pragma warning disable CS1591
4 using System.Runtime.InteropServices;
5 using System.Collections.Generic;
7 using System.Threading;
8 using System.ComponentModel;
13 /// <summary>Generic interface for objects that can write data from a provided memory.
14 /// This interface allows external objects to transparently write data to this object and be notified whether more data can be written or if it's reached capacity.
16 /// Calls to <see cref="Efl.Io.IWriter.Write"/> may or may not block: that's not up to this interface to specify. The user can check with event "can_write,changed" or property <see cref="Efl.Io.IWriter.CanWrite"/> to known whenever a write could push more data.
17 /// (Since EFL 1.22)</summary>
18 [Efl.Io.IWriterConcrete.NativeMethods]
19 [Efl.Eo.BindingEntity]
20 public interface IWriter :
21 Efl.Eo.IWrapper, IDisposable
23 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
24 /// (Since EFL 1.22)</summary>
25 /// <returns><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</returns>
27 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
28 /// (Since EFL 1.22)</summary>
29 /// <param name="can_write"><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</param>
30 void SetCanWrite(bool can_write);
31 /// <summary>Writes data from a pre-populated buffer.
32 /// This operation will be executed immediately and may or may not block the caller thread for some time. The details of blocking behavior is defined by the implementation and may be subject to other parameters such as non-blocking flags, maximum timeout or even retry attempts.
34 /// You can understand this method as write(2) libc function.
35 /// (Since EFL 1.22)</summary>
36 /// <param name="slice">Provides a pre-populated memory to be used up to slice.len. The returned slice will be adapted as length will be set to the actually used amount of bytes, which can be smaller than the request.</param>
37 /// <param name="remaining">Convenience to output the remaining parts of slice that was not written. If the full slice was written, this will be a slice of zero-length.</param>
38 /// <returns>0 on succeed, a mapping of errno otherwise</returns>
39 Eina.Error Write(ref Eina.Slice slice, ref Eina.Slice remaining);
40 /// <summary>Notifies can_write property changed.
41 /// If <see cref="Efl.Io.IWriter.CanWrite"/> is <c>true</c> there is data to <see cref="Efl.Io.IWriter.Write"/> without blocking/error. If <see cref="Efl.Io.IWriter.CanWrite"/> is <c>false</c>, <see cref="Efl.Io.IWriter.Write"/> would either block or fail.
43 /// Note that usually this event is dispatched from inside <see cref="Efl.Io.IWriter.Write"/>, thus before it returns.
44 /// (Since EFL 1.22)</summary>
45 /// <value><see cref="Efl.Io.IWriterCanWriteChangedEvt_Args"/></value>
46 event EventHandler<Efl.Io.IWriterCanWriteChangedEvt_Args> CanWriteChangedEvt;
47 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
48 /// (Since EFL 1.22)</summary>
49 /// <value><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</value>
55 /// <summary>Event argument wrapper for event <see cref="Efl.Io.IWriter.CanWriteChangedEvt"/>.</summary>
56 [Efl.Eo.BindingEntity]
57 public class IWriterCanWriteChangedEvt_Args : EventArgs {
58 /// <summary>Actual event payload.</summary>
59 /// <value>Notifies can_write property changed.</value>
60 public bool arg { get; set; }
62 /// <summary>Generic interface for objects that can write data from a provided memory.
63 /// This interface allows external objects to transparently write data to this object and be notified whether more data can be written or if it's reached capacity.
65 /// Calls to <see cref="Efl.Io.IWriter.Write"/> may or may not block: that's not up to this interface to specify. The user can check with event "can_write,changed" or property <see cref="Efl.Io.IWriter.CanWrite"/> to known whenever a write could push more data.
66 /// (Since EFL 1.22)</summary>
67 sealed public class IWriterConcrete :
72 /// <summary>Pointer to the native class description.</summary>
73 public override System.IntPtr NativeClass
77 if (((object)this).GetType() == typeof(IWriterConcrete))
79 return GetEflClassStatic();
83 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
88 /// <summary>Subclasses should override this constructor if they are expected to be instantiated from native code.
89 /// Do not call this constructor directly.</summary>
90 /// <param name="ch">Tag struct storing the native handle of the object being constructed.</param>
91 private IWriterConcrete(ConstructingHandle ch) : base(ch)
95 [System.Runtime.InteropServices.DllImport("libefl.so.1")] internal static extern System.IntPtr
96 efl_io_writer_interface_get();
97 /// <summary>Initializes a new instance of the <see cref="IWriter"/> class.
98 /// Internal usage: This is used when interacting with C code and should not be used directly.</summary>
99 /// <param name="wh">The native pointer to be wrapped.</param>
100 private IWriterConcrete(Efl.Eo.Globals.WrappingHandle wh) : base(wh)
104 /// <summary>Notifies can_write property changed.
105 /// If <see cref="Efl.Io.IWriter.CanWrite"/> is <c>true</c> there is data to <see cref="Efl.Io.IWriter.Write"/> without blocking/error. If <see cref="Efl.Io.IWriter.CanWrite"/> is <c>false</c>, <see cref="Efl.Io.IWriter.Write"/> would either block or fail.
107 /// Note that usually this event is dispatched from inside <see cref="Efl.Io.IWriter.Write"/>, thus before it returns.
108 /// (Since EFL 1.22)</summary>
109 /// <value><see cref="Efl.Io.IWriterCanWriteChangedEvt_Args"/></value>
110 public event EventHandler<Efl.Io.IWriterCanWriteChangedEvt_Args> CanWriteChangedEvt
114 lock (eflBindingEventLock)
116 Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>
118 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
121 Efl.Io.IWriterCanWriteChangedEvt_Args args = new Efl.Io.IWriterCanWriteChangedEvt_Args();
122 args.arg = Marshal.ReadByte(evt.Info) != 0;
125 value?.Invoke(obj, args);
129 Eina.Log.Error(e.ToString());
130 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
135 string key = "_EFL_IO_WRITER_EVENT_CAN_WRITE_CHANGED";
136 AddNativeEventHandler(efl.Libs.Efl, key, callerCb, value);
142 lock (eflBindingEventLock)
144 string key = "_EFL_IO_WRITER_EVENT_CAN_WRITE_CHANGED";
145 RemoveNativeEventHandler(efl.Libs.Efl, key, value);
149 /// <summary>Method to raise event CanWriteChangedEvt.</summary>
150 public void OnCanWriteChangedEvt(Efl.Io.IWriterCanWriteChangedEvt_Args e)
152 var key = "_EFL_IO_WRITER_EVENT_CAN_WRITE_CHANGED";
153 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Efl, key);
154 if (desc == IntPtr.Zero)
156 Eina.Log.Error($"Failed to get native event {key}");
160 IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(e.arg ? (byte) 1 : (byte) 0);
163 Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, info);
167 Marshal.FreeHGlobal(info);
170 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
171 /// (Since EFL 1.22)</summary>
172 /// <returns><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</returns>
173 public bool GetCanWrite() {
174 var _ret_var = Efl.Io.IWriterConcrete.NativeMethods.efl_io_writer_can_write_get_ptr.Value.Delegate(this.NativeHandle);
175 Eina.Error.RaiseIfUnhandledException();
178 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
179 /// (Since EFL 1.22)</summary>
180 /// <param name="can_write"><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</param>
181 public void SetCanWrite(bool can_write) {
182 Efl.Io.IWriterConcrete.NativeMethods.efl_io_writer_can_write_set_ptr.Value.Delegate(this.NativeHandle,can_write);
183 Eina.Error.RaiseIfUnhandledException();
185 /// <summary>Writes data from a pre-populated buffer.
186 /// This operation will be executed immediately and may or may not block the caller thread for some time. The details of blocking behavior is defined by the implementation and may be subject to other parameters such as non-blocking flags, maximum timeout or even retry attempts.
188 /// You can understand this method as write(2) libc function.
189 /// (Since EFL 1.22)</summary>
190 /// <param name="slice">Provides a pre-populated memory to be used up to slice.len. The returned slice will be adapted as length will be set to the actually used amount of bytes, which can be smaller than the request.</param>
191 /// <param name="remaining">Convenience to output the remaining parts of slice that was not written. If the full slice was written, this will be a slice of zero-length.</param>
192 /// <returns>0 on succeed, a mapping of errno otherwise</returns>
193 public Eina.Error Write(ref Eina.Slice slice, ref Eina.Slice remaining) {
194 var _ret_var = Efl.Io.IWriterConcrete.NativeMethods.efl_io_writer_write_ptr.Value.Delegate(this.NativeHandle,ref slice, ref remaining);
195 Eina.Error.RaiseIfUnhandledException();
198 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
199 /// (Since EFL 1.22)</summary>
200 /// <value><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</value>
201 public bool CanWrite {
202 get { return GetCanWrite(); }
203 set { SetCanWrite(value); }
205 private static IntPtr GetEflClassStatic()
207 return Efl.Io.IWriterConcrete.efl_io_writer_interface_get();
209 /// <summary>Wrapper for native methods and virtual method delegates.
210 /// For internal use by generated code only.</summary>
211 public new class NativeMethods : Efl.Eo.EoWrapper.NativeMethods
213 private static Efl.Eo.NativeModule Module = new Efl.Eo.NativeModule( efl.Libs.Efl);
214 /// <summary>Gets the list of Eo operations to override.</summary>
215 /// <returns>The list of Eo operations to be overload.</returns>
216 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
218 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
219 var methods = Efl.Eo.Globals.GetUserMethods(type);
221 if (efl_io_writer_can_write_get_static_delegate == null)
223 efl_io_writer_can_write_get_static_delegate = new efl_io_writer_can_write_get_delegate(can_write_get);
226 if (methods.FirstOrDefault(m => m.Name == "GetCanWrite") != null)
228 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_writer_can_write_get"), func = Marshal.GetFunctionPointerForDelegate(efl_io_writer_can_write_get_static_delegate) });
231 if (efl_io_writer_can_write_set_static_delegate == null)
233 efl_io_writer_can_write_set_static_delegate = new efl_io_writer_can_write_set_delegate(can_write_set);
236 if (methods.FirstOrDefault(m => m.Name == "SetCanWrite") != null)
238 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_writer_can_write_set"), func = Marshal.GetFunctionPointerForDelegate(efl_io_writer_can_write_set_static_delegate) });
241 if (efl_io_writer_write_static_delegate == null)
243 efl_io_writer_write_static_delegate = new efl_io_writer_write_delegate(write);
246 if (methods.FirstOrDefault(m => m.Name == "Write") != null)
248 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_writer_write"), func = Marshal.GetFunctionPointerForDelegate(efl_io_writer_write_static_delegate) });
253 /// <summary>Returns the Eo class for the native methods of this class.</summary>
254 /// <returns>The native class pointer.</returns>
255 public override IntPtr GetEflClass()
257 return Efl.Io.IWriterConcrete.efl_io_writer_interface_get();
260 #pragma warning disable CA1707, CS1591, SA1300, SA1600
262 [return: MarshalAs(UnmanagedType.U1)]
263 private delegate bool efl_io_writer_can_write_get_delegate(System.IntPtr obj, System.IntPtr pd);
265 [return: MarshalAs(UnmanagedType.U1)]
266 public delegate bool efl_io_writer_can_write_get_api_delegate(System.IntPtr obj);
268 public static Efl.Eo.FunctionWrapper<efl_io_writer_can_write_get_api_delegate> efl_io_writer_can_write_get_ptr = new Efl.Eo.FunctionWrapper<efl_io_writer_can_write_get_api_delegate>(Module, "efl_io_writer_can_write_get");
270 private static bool can_write_get(System.IntPtr obj, System.IntPtr pd)
272 Eina.Log.Debug("function efl_io_writer_can_write_get was called");
273 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
276 bool _ret_var = default(bool);
279 _ret_var = ((IWriter)ws.Target).GetCanWrite();
283 Eina.Log.Warning($"Callback error: {e.ToString()}");
284 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
292 return efl_io_writer_can_write_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
296 private static efl_io_writer_can_write_get_delegate efl_io_writer_can_write_get_static_delegate;
299 private delegate void efl_io_writer_can_write_set_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.U1)] bool can_write);
302 public delegate void efl_io_writer_can_write_set_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool can_write);
304 public static Efl.Eo.FunctionWrapper<efl_io_writer_can_write_set_api_delegate> efl_io_writer_can_write_set_ptr = new Efl.Eo.FunctionWrapper<efl_io_writer_can_write_set_api_delegate>(Module, "efl_io_writer_can_write_set");
306 private static void can_write_set(System.IntPtr obj, System.IntPtr pd, bool can_write)
308 Eina.Log.Debug("function efl_io_writer_can_write_set was called");
309 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
315 ((IWriter)ws.Target).SetCanWrite(can_write);
319 Eina.Log.Warning($"Callback error: {e.ToString()}");
320 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
327 efl_io_writer_can_write_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), can_write);
331 private static efl_io_writer_can_write_set_delegate efl_io_writer_can_write_set_static_delegate;
334 private delegate Eina.Error efl_io_writer_write_delegate(System.IntPtr obj, System.IntPtr pd, ref Eina.Slice slice, ref Eina.Slice remaining);
337 public delegate Eina.Error efl_io_writer_write_api_delegate(System.IntPtr obj, ref Eina.Slice slice, ref Eina.Slice remaining);
339 public static Efl.Eo.FunctionWrapper<efl_io_writer_write_api_delegate> efl_io_writer_write_ptr = new Efl.Eo.FunctionWrapper<efl_io_writer_write_api_delegate>(Module, "efl_io_writer_write");
341 private static Eina.Error write(System.IntPtr obj, System.IntPtr pd, ref Eina.Slice slice, ref Eina.Slice remaining)
343 Eina.Log.Debug("function efl_io_writer_write was called");
344 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
347 remaining = default( Eina.Slice); Eina.Error _ret_var = default(Eina.Error);
350 _ret_var = ((IWriter)ws.Target).Write(ref slice, ref remaining);
354 Eina.Log.Warning($"Callback error: {e.ToString()}");
355 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
363 return efl_io_writer_write_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), ref slice, ref remaining);
367 private static efl_io_writer_write_delegate efl_io_writer_write_static_delegate;
369 #pragma warning restore CA1707, CS1591, SA1300, SA1600
378 #pragma warning disable CS1591
379 public static class Efl_IoIWriterConcrete_ExtensionMethods {
380 public static Efl.BindableProperty<bool> CanWrite<T>(this Efl.Ui.ItemFactory<T> fac, Efl.Csharp.ExtensionTag<Efl.Io.IWriter, T>magic = null) where T : Efl.Io.IWriter {
381 return new Efl.BindableProperty<bool>("can_write", fac);
385 #pragma warning restore CS1591