1 #pragma warning disable CS1591
3 using System.Runtime.InteropServices;
4 using System.Collections.Generic;
6 using System.Threading;
7 using System.ComponentModel;
12 /// <summary>Generic interface for objects that can write data from a provided memory.
13 /// 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.
15 /// 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.
16 /// (Since EFL 1.22)</summary>
17 [Efl.Io.IWriterConcrete.NativeMethods]
18 public interface IWriter :
19 Efl.Eo.IWrapper, IDisposable
21 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
22 /// (Since EFL 1.22)</summary>
23 /// <returns><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</returns>
25 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
26 /// (Since EFL 1.22)</summary>
27 /// <param name="can_write"><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</param>
28 void SetCanWrite(bool can_write);
29 /// <summary>Writes data from a pre-populated buffer.
30 /// 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.
32 /// You can understand this method as write(2) libc function.
33 /// (Since EFL 1.22)</summary>
34 /// <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>
35 /// <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>
36 /// <returns>0 on succeed, a mapping of errno otherwise</returns>
37 Eina.Error Write(ref Eina.Slice slice, ref Eina.Slice remaining);
38 /// <summary>Notifies can_write property changed.
39 /// 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.
41 /// Note that usually this event is dispatched from inside <see cref="Efl.Io.IWriter.Write"/>, thus before it returns.
42 /// (Since EFL 1.22)</summary>
43 event EventHandler<Efl.Io.IWriterCanWriteChangedEvt_Args> CanWriteChangedEvt;
44 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
45 /// (Since EFL 1.22)</summary>
46 /// <value><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</value>
52 ///<summary>Event argument wrapper for event <see cref="Efl.Io.IWriter.CanWriteChangedEvt"/>.</summary>
53 public class IWriterCanWriteChangedEvt_Args : EventArgs {
54 ///<summary>Actual event payload.</summary>
55 public bool arg { get; set; }
57 /// <summary>Generic interface for objects that can write data from a provided memory.
58 /// 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.
60 /// 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.
61 /// (Since EFL 1.22)</summary>
62 sealed public class IWriterConcrete :
67 ///<summary>Pointer to the native class description.</summary>
68 public override System.IntPtr NativeClass
72 if (((object)this).GetType() == typeof(IWriterConcrete))
74 return GetEflClassStatic();
78 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
83 [System.Runtime.InteropServices.DllImport(efl.Libs.Efl)] internal static extern System.IntPtr
84 efl_io_writer_interface_get();
85 /// <summary>Initializes a new instance of the <see cref="IWriter"/> class.
86 /// Internal usage: This is used when interacting with C code and should not be used directly.</summary>
87 private IWriterConcrete(System.IntPtr raw) : base(raw)
91 /// <summary>Notifies can_write property changed.
92 /// 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.
94 /// Note that usually this event is dispatched from inside <see cref="Efl.Io.IWriter.Write"/>, thus before it returns.
95 /// (Since EFL 1.22)</summary>
96 public event EventHandler<Efl.Io.IWriterCanWriteChangedEvt_Args> CanWriteChangedEvt
102 Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>
104 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
107 Efl.Io.IWriterCanWriteChangedEvt_Args args = new Efl.Io.IWriterCanWriteChangedEvt_Args();
108 args.arg = Marshal.ReadByte(evt.Info) != 0;
111 value?.Invoke(obj, args);
115 Eina.Log.Error(e.ToString());
116 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
121 string key = "_EFL_IO_WRITER_EVENT_CAN_WRITE_CHANGED";
122 AddNativeEventHandler(efl.Libs.Efl, key, callerCb, value);
130 string key = "_EFL_IO_WRITER_EVENT_CAN_WRITE_CHANGED";
131 RemoveNativeEventHandler(efl.Libs.Efl, key, value);
135 ///<summary>Method to raise event CanWriteChangedEvt.</summary>
136 public void OnCanWriteChangedEvt(Efl.Io.IWriterCanWriteChangedEvt_Args e)
138 var key = "_EFL_IO_WRITER_EVENT_CAN_WRITE_CHANGED";
139 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Efl, key);
140 if (desc == IntPtr.Zero)
142 Eina.Log.Error($"Failed to get native event {key}");
146 IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(e.arg ? (byte) 1 : (byte) 0);
149 Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, info);
153 Marshal.FreeHGlobal(info);
156 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
157 /// (Since EFL 1.22)</summary>
158 /// <returns><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</returns>
159 public bool GetCanWrite() {
160 var _ret_var = Efl.Io.IWriterConcrete.NativeMethods.efl_io_writer_can_write_get_ptr.Value.Delegate(this.NativeHandle);
161 Eina.Error.RaiseIfUnhandledException();
164 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
165 /// (Since EFL 1.22)</summary>
166 /// <param name="can_write"><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</param>
167 public void SetCanWrite(bool can_write) {
168 Efl.Io.IWriterConcrete.NativeMethods.efl_io_writer_can_write_set_ptr.Value.Delegate(this.NativeHandle,can_write);
169 Eina.Error.RaiseIfUnhandledException();
171 /// <summary>Writes data from a pre-populated buffer.
172 /// 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.
174 /// You can understand this method as write(2) libc function.
175 /// (Since EFL 1.22)</summary>
176 /// <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>
177 /// <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>
178 /// <returns>0 on succeed, a mapping of errno otherwise</returns>
179 public Eina.Error Write(ref Eina.Slice slice, ref Eina.Slice remaining) {
180 var _ret_var = Efl.Io.IWriterConcrete.NativeMethods.efl_io_writer_write_ptr.Value.Delegate(this.NativeHandle,ref slice, ref remaining);
181 Eina.Error.RaiseIfUnhandledException();
184 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IWriter.Write"/> can be called without blocking or failing.
185 /// (Since EFL 1.22)</summary>
186 /// <value><c>true</c> if it can be written without blocking or failure, <c>false</c> otherwise</value>
187 public bool CanWrite {
188 get { return GetCanWrite(); }
189 set { SetCanWrite(value); }
191 private static IntPtr GetEflClassStatic()
193 return Efl.Io.IWriterConcrete.efl_io_writer_interface_get();
195 /// <summary>Wrapper for native methods and virtual method delegates.
196 /// For internal use by generated code only.</summary>
197 public class NativeMethods : Efl.Eo.NativeClass
199 private static Efl.Eo.NativeModule Module = new Efl.Eo.NativeModule( efl.Libs.Efl);
200 /// <summary>Gets the list of Eo operations to override.</summary>
201 /// <returns>The list of Eo operations to be overload.</returns>
202 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
204 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
205 var methods = Efl.Eo.Globals.GetUserMethods(type);
207 if (efl_io_writer_can_write_get_static_delegate == null)
209 efl_io_writer_can_write_get_static_delegate = new efl_io_writer_can_write_get_delegate(can_write_get);
212 if (methods.FirstOrDefault(m => m.Name == "GetCanWrite") != null)
214 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) });
217 if (efl_io_writer_can_write_set_static_delegate == null)
219 efl_io_writer_can_write_set_static_delegate = new efl_io_writer_can_write_set_delegate(can_write_set);
222 if (methods.FirstOrDefault(m => m.Name == "SetCanWrite") != null)
224 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) });
227 if (efl_io_writer_write_static_delegate == null)
229 efl_io_writer_write_static_delegate = new efl_io_writer_write_delegate(write);
232 if (methods.FirstOrDefault(m => m.Name == "Write") != null)
234 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) });
239 /// <summary>Returns the Eo class for the native methods of this class.</summary>
240 /// <returns>The native class pointer.</returns>
241 public override IntPtr GetEflClass()
243 return Efl.Io.IWriterConcrete.efl_io_writer_interface_get();
246 #pragma warning disable CA1707, CS1591, SA1300, SA1600
248 [return: MarshalAs(UnmanagedType.U1)]
249 private delegate bool efl_io_writer_can_write_get_delegate(System.IntPtr obj, System.IntPtr pd);
251 [return: MarshalAs(UnmanagedType.U1)]
252 public delegate bool efl_io_writer_can_write_get_api_delegate(System.IntPtr obj);
254 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");
256 private static bool can_write_get(System.IntPtr obj, System.IntPtr pd)
258 Eina.Log.Debug("function efl_io_writer_can_write_get was called");
259 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
262 bool _ret_var = default(bool);
265 _ret_var = ((IWriter)ws.Target).GetCanWrite();
269 Eina.Log.Warning($"Callback error: {e.ToString()}");
270 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
278 return efl_io_writer_can_write_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
282 private static efl_io_writer_can_write_get_delegate efl_io_writer_can_write_get_static_delegate;
285 private delegate void efl_io_writer_can_write_set_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.U1)] bool can_write);
288 public delegate void efl_io_writer_can_write_set_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool can_write);
290 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");
292 private static void can_write_set(System.IntPtr obj, System.IntPtr pd, bool can_write)
294 Eina.Log.Debug("function efl_io_writer_can_write_set was called");
295 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
301 ((IWriter)ws.Target).SetCanWrite(can_write);
305 Eina.Log.Warning($"Callback error: {e.ToString()}");
306 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
313 efl_io_writer_can_write_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), can_write);
317 private static efl_io_writer_can_write_set_delegate efl_io_writer_can_write_set_static_delegate;
320 private delegate Eina.Error efl_io_writer_write_delegate(System.IntPtr obj, System.IntPtr pd, ref Eina.Slice slice, ref Eina.Slice remaining);
323 public delegate Eina.Error efl_io_writer_write_api_delegate(System.IntPtr obj, ref Eina.Slice slice, ref Eina.Slice remaining);
325 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");
327 private static Eina.Error write(System.IntPtr obj, System.IntPtr pd, ref Eina.Slice slice, ref Eina.Slice remaining)
329 Eina.Log.Debug("function efl_io_writer_write was called");
330 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
333 remaining = default(Eina.Slice); Eina.Error _ret_var = default(Eina.Error);
336 _ret_var = ((IWriter)ws.Target).Write(ref slice, ref remaining);
340 Eina.Log.Warning($"Callback error: {e.ToString()}");
341 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
349 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);
353 private static efl_io_writer_write_delegate efl_io_writer_write_static_delegate;
355 #pragma warning restore CA1707, CS1591, SA1300, SA1600