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 read data into a provided memory.
13 /// This interface allows external objects to transparently monitor for new data and as it to be read into a provided memory slice.
15 /// Calls to <see cref="Efl.Io.IReader.Read"/> may or may not block, that's not up to this interface to specify. The user can check based on <see cref="Efl.Io.IReader.Eos"/> property and signal if the stream reached an end, with event "can_read,changed" or property <see cref="Efl.Io.IReader.CanRead"/> to known whenever a read would have data to return.
16 /// (Since EFL 1.22)</summary>
17 [Efl.Io.IReaderConcrete.NativeMethods]
18 [Efl.Eo.BindingEntity]
19 public interface IReader :
20 Efl.Eo.IWrapper, IDisposable
22 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IReader.Read"/> can be called without blocking or failing.
23 /// (Since EFL 1.22)</summary>
24 /// <returns><c>true</c> if it can be read without blocking or failing, <c>false</c> otherwise</returns>
26 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IReader.Read"/> can be called without blocking or failing.
27 /// (Since EFL 1.22)</summary>
28 /// <param name="can_read"><c>true</c> if it can be read without blocking or failing, <c>false</c> otherwise</param>
29 void SetCanRead(bool can_read);
30 /// <summary>If <c>true</c> will notify end of stream.
31 /// (Since EFL 1.22)</summary>
32 /// <returns><c>true</c> if end of stream, <c>false</c> otherwise</returns>
34 /// <summary>If <c>true</c> will notify end of stream.
35 /// (Since EFL 1.22)</summary>
36 /// <param name="is_eos"><c>true</c> if end of stream, <c>false</c> otherwise</param>
37 void SetEos(bool is_eos);
38 /// <summary>Reads data into a pre-allocated buffer.
39 /// This operation will be executed immediately and may or may not block the caller thread for some time. The details of blocking behavior is to be defined by the implementation and may be subject to other parameters such as non-blocking flags, maximum timeout or even retry attempts.
41 /// You can understand this method as read(2) libc function.
42 /// (Since EFL 1.22)</summary>
43 /// <param name="rw_slice">Provides a pre-allocated memory to be filled up to rw_slice.len. It will be populated and the length will be set to the actually used amount of bytes, which can be smaller than the request.</param>
44 /// <returns>0 on succeed, a mapping of errno otherwise</returns>
45 Eina.Error Read(ref Eina.RwSlice rw_slice);
46 /// <summary>Notifies can_read property changed.
47 /// If <see cref="Efl.Io.IReader.CanRead"/> is <c>true</c> there is data to <see cref="Efl.Io.IReader.Read"/> without blocking/error. If <see cref="Efl.Io.IReader.CanRead"/> is <c>false</c>, <see cref="Efl.Io.IReader.Read"/> would either block or fail.
49 /// Note that usually this event is dispatched from inside <see cref="Efl.Io.IReader.Read"/>, thus before it returns.
50 /// (Since EFL 1.22)</summary>
51 event EventHandler<Efl.Io.IReaderCanReadChangedEvt_Args> CanReadChangedEvt;
52 /// <summary>Notifies end of stream, when property is marked as true.
53 /// If this is used alongside with an <see cref="Efl.Io.ICloser"/>, then it should be emitted before that call.
55 /// It should be emitted only once for an object unless it implements <see cref="Efl.Io.IPositioner.Seek"/>.
57 /// The property <see cref="Efl.Io.IReader.CanRead"/> should change to <c>false</c> before this event is dispatched.
58 /// (Since EFL 1.22)</summary>
59 event EventHandler EosEvt;
60 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IReader.Read"/> can be called without blocking or failing.
61 /// (Since EFL 1.22)</summary>
62 /// <value><c>true</c> if it can be read without blocking or failing, <c>false</c> otherwise</value>
67 /// <summary>If <c>true</c> will notify end of stream.
68 /// (Since EFL 1.22)</summary>
69 /// <value><c>true</c> if end of stream, <c>false</c> otherwise</value>
75 ///<summary>Event argument wrapper for event <see cref="Efl.Io.IReader.CanReadChangedEvt"/>.</summary>
76 [Efl.Eo.BindingEntity]
77 public class IReaderCanReadChangedEvt_Args : EventArgs {
78 ///<summary>Actual event payload.</summary>
79 public bool arg { get; set; }
81 /// <summary>Generic interface for objects that can read data into a provided memory.
82 /// This interface allows external objects to transparently monitor for new data and as it to be read into a provided memory slice.
84 /// Calls to <see cref="Efl.Io.IReader.Read"/> may or may not block, that's not up to this interface to specify. The user can check based on <see cref="Efl.Io.IReader.Eos"/> property and signal if the stream reached an end, with event "can_read,changed" or property <see cref="Efl.Io.IReader.CanRead"/> to known whenever a read would have data to return.
85 /// (Since EFL 1.22)</summary>
86 sealed public class IReaderConcrete :
91 ///<summary>Pointer to the native class description.</summary>
92 public override System.IntPtr NativeClass
96 if (((object)this).GetType() == typeof(IReaderConcrete))
98 return GetEflClassStatic();
102 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
107 /// <summary>Constructor to be used when objects are expected to be constructed from native code.</summary>
108 /// <param name="ch">Tag struct storing the native handle of the object being constructed.</param>
109 private IReaderConcrete(ConstructingHandle ch) : base(ch)
113 [System.Runtime.InteropServices.DllImport("libefl.so.1")] internal static extern System.IntPtr
114 efl_io_reader_interface_get();
115 /// <summary>Initializes a new instance of the <see cref="IReader"/> class.
116 /// Internal usage: This is used when interacting with C code and should not be used directly.</summary>
117 /// <param name="wh">The native pointer to be wrapped.</param>
118 private IReaderConcrete(Efl.Eo.Globals.WrappingHandle wh) : base(wh)
122 /// <summary>Notifies can_read property changed.
123 /// If <see cref="Efl.Io.IReader.CanRead"/> is <c>true</c> there is data to <see cref="Efl.Io.IReader.Read"/> without blocking/error. If <see cref="Efl.Io.IReader.CanRead"/> is <c>false</c>, <see cref="Efl.Io.IReader.Read"/> would either block or fail.
125 /// Note that usually this event is dispatched from inside <see cref="Efl.Io.IReader.Read"/>, thus before it returns.
126 /// (Since EFL 1.22)</summary>
127 public event EventHandler<Efl.Io.IReaderCanReadChangedEvt_Args> CanReadChangedEvt
131 lock (eflBindingEventLock)
133 Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>
135 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
138 Efl.Io.IReaderCanReadChangedEvt_Args args = new Efl.Io.IReaderCanReadChangedEvt_Args();
139 args.arg = Marshal.ReadByte(evt.Info) != 0;
142 value?.Invoke(obj, args);
146 Eina.Log.Error(e.ToString());
147 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
152 string key = "_EFL_IO_READER_EVENT_CAN_READ_CHANGED";
153 AddNativeEventHandler(efl.Libs.Efl, key, callerCb, value);
159 lock (eflBindingEventLock)
161 string key = "_EFL_IO_READER_EVENT_CAN_READ_CHANGED";
162 RemoveNativeEventHandler(efl.Libs.Efl, key, value);
166 ///<summary>Method to raise event CanReadChangedEvt.</summary>
167 public void OnCanReadChangedEvt(Efl.Io.IReaderCanReadChangedEvt_Args e)
169 var key = "_EFL_IO_READER_EVENT_CAN_READ_CHANGED";
170 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Efl, key);
171 if (desc == IntPtr.Zero)
173 Eina.Log.Error($"Failed to get native event {key}");
177 IntPtr info = Eina.PrimitiveConversion.ManagedToPointerAlloc(e.arg ? (byte) 1 : (byte) 0);
180 Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, info);
184 Marshal.FreeHGlobal(info);
187 /// <summary>Notifies end of stream, when property is marked as true.
188 /// If this is used alongside with an <see cref="Efl.Io.ICloser"/>, then it should be emitted before that call.
190 /// It should be emitted only once for an object unless it implements <see cref="Efl.Io.IPositioner.Seek"/>.
192 /// The property <see cref="Efl.Io.IReader.CanRead"/> should change to <c>false</c> before this event is dispatched.
193 /// (Since EFL 1.22)</summary>
194 public event EventHandler EosEvt
198 lock (eflBindingEventLock)
200 Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>
202 var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target;
205 EventArgs args = EventArgs.Empty;
208 value?.Invoke(obj, args);
212 Eina.Log.Error(e.ToString());
213 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
218 string key = "_EFL_IO_READER_EVENT_EOS";
219 AddNativeEventHandler(efl.Libs.Efl, key, callerCb, value);
225 lock (eflBindingEventLock)
227 string key = "_EFL_IO_READER_EVENT_EOS";
228 RemoveNativeEventHandler(efl.Libs.Efl, key, value);
232 ///<summary>Method to raise event EosEvt.</summary>
233 public void OnEosEvt(EventArgs e)
235 var key = "_EFL_IO_READER_EVENT_EOS";
236 IntPtr desc = Efl.EventDescription.GetNative(efl.Libs.Efl, key);
237 if (desc == IntPtr.Zero)
239 Eina.Log.Error($"Failed to get native event {key}");
243 Efl.Eo.Globals.efl_event_callback_call(this.NativeHandle, desc, IntPtr.Zero);
245 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IReader.Read"/> can be called without blocking or failing.
246 /// (Since EFL 1.22)</summary>
247 /// <returns><c>true</c> if it can be read without blocking or failing, <c>false</c> otherwise</returns>
248 public bool GetCanRead() {
249 var _ret_var = Efl.Io.IReaderConcrete.NativeMethods.efl_io_reader_can_read_get_ptr.Value.Delegate(this.NativeHandle);
250 Eina.Error.RaiseIfUnhandledException();
253 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IReader.Read"/> can be called without blocking or failing.
254 /// (Since EFL 1.22)</summary>
255 /// <param name="can_read"><c>true</c> if it can be read without blocking or failing, <c>false</c> otherwise</param>
256 public void SetCanRead(bool can_read) {
257 Efl.Io.IReaderConcrete.NativeMethods.efl_io_reader_can_read_set_ptr.Value.Delegate(this.NativeHandle,can_read);
258 Eina.Error.RaiseIfUnhandledException();
260 /// <summary>If <c>true</c> will notify end of stream.
261 /// (Since EFL 1.22)</summary>
262 /// <returns><c>true</c> if end of stream, <c>false</c> otherwise</returns>
263 public bool GetEos() {
264 var _ret_var = Efl.Io.IReaderConcrete.NativeMethods.efl_io_reader_eos_get_ptr.Value.Delegate(this.NativeHandle);
265 Eina.Error.RaiseIfUnhandledException();
268 /// <summary>If <c>true</c> will notify end of stream.
269 /// (Since EFL 1.22)</summary>
270 /// <param name="is_eos"><c>true</c> if end of stream, <c>false</c> otherwise</param>
271 public void SetEos(bool is_eos) {
272 Efl.Io.IReaderConcrete.NativeMethods.efl_io_reader_eos_set_ptr.Value.Delegate(this.NativeHandle,is_eos);
273 Eina.Error.RaiseIfUnhandledException();
275 /// <summary>Reads data into a pre-allocated buffer.
276 /// This operation will be executed immediately and may or may not block the caller thread for some time. The details of blocking behavior is to be defined by the implementation and may be subject to other parameters such as non-blocking flags, maximum timeout or even retry attempts.
278 /// You can understand this method as read(2) libc function.
279 /// (Since EFL 1.22)</summary>
280 /// <param name="rw_slice">Provides a pre-allocated memory to be filled up to rw_slice.len. It will be populated and the length will be set to the actually used amount of bytes, which can be smaller than the request.</param>
281 /// <returns>0 on succeed, a mapping of errno otherwise</returns>
282 public Eina.Error Read(ref Eina.RwSlice rw_slice) {
283 var _ret_var = Efl.Io.IReaderConcrete.NativeMethods.efl_io_reader_read_ptr.Value.Delegate(this.NativeHandle,ref rw_slice);
284 Eina.Error.RaiseIfUnhandledException();
287 /// <summary>If <c>true</c> will notify <see cref="Efl.Io.IReader.Read"/> can be called without blocking or failing.
288 /// (Since EFL 1.22)</summary>
289 /// <value><c>true</c> if it can be read without blocking or failing, <c>false</c> otherwise</value>
290 public bool CanRead {
291 get { return GetCanRead(); }
292 set { SetCanRead(value); }
294 /// <summary>If <c>true</c> will notify end of stream.
295 /// (Since EFL 1.22)</summary>
296 /// <value><c>true</c> if end of stream, <c>false</c> otherwise</value>
298 get { return GetEos(); }
299 set { SetEos(value); }
301 private static IntPtr GetEflClassStatic()
303 return Efl.Io.IReaderConcrete.efl_io_reader_interface_get();
305 /// <summary>Wrapper for native methods and virtual method delegates.
306 /// For internal use by generated code only.</summary>
307 public new class NativeMethods : Efl.Eo.EoWrapper.NativeMethods
309 private static Efl.Eo.NativeModule Module = new Efl.Eo.NativeModule( efl.Libs.Efl);
310 /// <summary>Gets the list of Eo operations to override.</summary>
311 /// <returns>The list of Eo operations to be overload.</returns>
312 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
314 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
315 var methods = Efl.Eo.Globals.GetUserMethods(type);
317 if (efl_io_reader_can_read_get_static_delegate == null)
319 efl_io_reader_can_read_get_static_delegate = new efl_io_reader_can_read_get_delegate(can_read_get);
322 if (methods.FirstOrDefault(m => m.Name == "GetCanRead") != null)
324 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_can_read_get"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_can_read_get_static_delegate) });
327 if (efl_io_reader_can_read_set_static_delegate == null)
329 efl_io_reader_can_read_set_static_delegate = new efl_io_reader_can_read_set_delegate(can_read_set);
332 if (methods.FirstOrDefault(m => m.Name == "SetCanRead") != null)
334 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_can_read_set"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_can_read_set_static_delegate) });
337 if (efl_io_reader_eos_get_static_delegate == null)
339 efl_io_reader_eos_get_static_delegate = new efl_io_reader_eos_get_delegate(eos_get);
342 if (methods.FirstOrDefault(m => m.Name == "GetEos") != null)
344 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_eos_get"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_eos_get_static_delegate) });
347 if (efl_io_reader_eos_set_static_delegate == null)
349 efl_io_reader_eos_set_static_delegate = new efl_io_reader_eos_set_delegate(eos_set);
352 if (methods.FirstOrDefault(m => m.Name == "SetEos") != null)
354 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_eos_set"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_eos_set_static_delegate) });
357 if (efl_io_reader_read_static_delegate == null)
359 efl_io_reader_read_static_delegate = new efl_io_reader_read_delegate(read);
362 if (methods.FirstOrDefault(m => m.Name == "Read") != null)
364 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_read"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_read_static_delegate) });
369 /// <summary>Returns the Eo class for the native methods of this class.</summary>
370 /// <returns>The native class pointer.</returns>
371 public override IntPtr GetEflClass()
373 return Efl.Io.IReaderConcrete.efl_io_reader_interface_get();
376 #pragma warning disable CA1707, CS1591, SA1300, SA1600
378 [return: MarshalAs(UnmanagedType.U1)]
379 private delegate bool efl_io_reader_can_read_get_delegate(System.IntPtr obj, System.IntPtr pd);
381 [return: MarshalAs(UnmanagedType.U1)]
382 public delegate bool efl_io_reader_can_read_get_api_delegate(System.IntPtr obj);
384 public static Efl.Eo.FunctionWrapper<efl_io_reader_can_read_get_api_delegate> efl_io_reader_can_read_get_ptr = new Efl.Eo.FunctionWrapper<efl_io_reader_can_read_get_api_delegate>(Module, "efl_io_reader_can_read_get");
386 private static bool can_read_get(System.IntPtr obj, System.IntPtr pd)
388 Eina.Log.Debug("function efl_io_reader_can_read_get was called");
389 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
392 bool _ret_var = default(bool);
395 _ret_var = ((IReader)ws.Target).GetCanRead();
399 Eina.Log.Warning($"Callback error: {e.ToString()}");
400 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
408 return efl_io_reader_can_read_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
412 private static efl_io_reader_can_read_get_delegate efl_io_reader_can_read_get_static_delegate;
415 private delegate void efl_io_reader_can_read_set_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.U1)] bool can_read);
418 public delegate void efl_io_reader_can_read_set_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool can_read);
420 public static Efl.Eo.FunctionWrapper<efl_io_reader_can_read_set_api_delegate> efl_io_reader_can_read_set_ptr = new Efl.Eo.FunctionWrapper<efl_io_reader_can_read_set_api_delegate>(Module, "efl_io_reader_can_read_set");
422 private static void can_read_set(System.IntPtr obj, System.IntPtr pd, bool can_read)
424 Eina.Log.Debug("function efl_io_reader_can_read_set was called");
425 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
431 ((IReader)ws.Target).SetCanRead(can_read);
435 Eina.Log.Warning($"Callback error: {e.ToString()}");
436 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
443 efl_io_reader_can_read_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), can_read);
447 private static efl_io_reader_can_read_set_delegate efl_io_reader_can_read_set_static_delegate;
449 [return: MarshalAs(UnmanagedType.U1)]
450 private delegate bool efl_io_reader_eos_get_delegate(System.IntPtr obj, System.IntPtr pd);
452 [return: MarshalAs(UnmanagedType.U1)]
453 public delegate bool efl_io_reader_eos_get_api_delegate(System.IntPtr obj);
455 public static Efl.Eo.FunctionWrapper<efl_io_reader_eos_get_api_delegate> efl_io_reader_eos_get_ptr = new Efl.Eo.FunctionWrapper<efl_io_reader_eos_get_api_delegate>(Module, "efl_io_reader_eos_get");
457 private static bool eos_get(System.IntPtr obj, System.IntPtr pd)
459 Eina.Log.Debug("function efl_io_reader_eos_get was called");
460 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
463 bool _ret_var = default(bool);
466 _ret_var = ((IReader)ws.Target).GetEos();
470 Eina.Log.Warning($"Callback error: {e.ToString()}");
471 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
479 return efl_io_reader_eos_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
483 private static efl_io_reader_eos_get_delegate efl_io_reader_eos_get_static_delegate;
486 private delegate void efl_io_reader_eos_set_delegate(System.IntPtr obj, System.IntPtr pd, [MarshalAs(UnmanagedType.U1)] bool is_eos);
489 public delegate void efl_io_reader_eos_set_api_delegate(System.IntPtr obj, [MarshalAs(UnmanagedType.U1)] bool is_eos);
491 public static Efl.Eo.FunctionWrapper<efl_io_reader_eos_set_api_delegate> efl_io_reader_eos_set_ptr = new Efl.Eo.FunctionWrapper<efl_io_reader_eos_set_api_delegate>(Module, "efl_io_reader_eos_set");
493 private static void eos_set(System.IntPtr obj, System.IntPtr pd, bool is_eos)
495 Eina.Log.Debug("function efl_io_reader_eos_set was called");
496 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
502 ((IReader)ws.Target).SetEos(is_eos);
506 Eina.Log.Warning($"Callback error: {e.ToString()}");
507 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
514 efl_io_reader_eos_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), is_eos);
518 private static efl_io_reader_eos_set_delegate efl_io_reader_eos_set_static_delegate;
521 private delegate Eina.Error efl_io_reader_read_delegate(System.IntPtr obj, System.IntPtr pd, ref Eina.RwSlice rw_slice);
524 public delegate Eina.Error efl_io_reader_read_api_delegate(System.IntPtr obj, ref Eina.RwSlice rw_slice);
526 public static Efl.Eo.FunctionWrapper<efl_io_reader_read_api_delegate> efl_io_reader_read_ptr = new Efl.Eo.FunctionWrapper<efl_io_reader_read_api_delegate>(Module, "efl_io_reader_read");
528 private static Eina.Error read(System.IntPtr obj, System.IntPtr pd, ref Eina.RwSlice rw_slice)
530 Eina.Log.Debug("function efl_io_reader_read was called");
531 var ws = Efl.Eo.Globals.GetWrapperSupervisor(obj);
534 Eina.Error _ret_var = default(Eina.Error);
537 _ret_var = ((IReader)ws.Target).Read(ref rw_slice);
541 Eina.Log.Warning($"Callback error: {e.ToString()}");
542 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
550 return efl_io_reader_read_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), ref rw_slice);
554 private static efl_io_reader_read_delegate efl_io_reader_read_static_delegate;
556 #pragma warning restore CA1707, CS1591, SA1300, SA1600