1 #pragma warning disable CS1591
3 using System.Runtime.InteropServices;
4 using System.Collections.Generic;
6 using System.ComponentModel;
8 /// <summary>Fds are objects that watch the activity on a given file descriptor. This file descriptor can be a network, a file, provided by a library.
9 /// The object will trigger relevant events depending on what's happening.</summary>
11 public class LoopFd : Efl.LoopConsumer, Efl.Eo.IWrapper
13 ///<summary>Pointer to the native class description.</summary>
14 public override System.IntPtr NativeClass {
16 if (((object)this).GetType() == typeof (LoopFd))
17 return Efl.LoopFdNativeInherit.GetEflClassStatic();
19 return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];
22 [System.Runtime.InteropServices.DllImport(efl.Libs.Ecore)] internal static extern System.IntPtr
23 efl_loop_fd_class_get();
24 ///<summary>Creates a new instance.</summary>
25 ///<param name="parent">Parent instance.</param>
26 public LoopFd(Efl.Object parent= null
28 base(efl_loop_fd_class_get(), typeof(LoopFd), parent)
30 FinishInstantiation();
32 ///<summary>Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>
33 protected LoopFd(System.IntPtr raw) : base(raw)
35 RegisterEventProxies();
37 ///<summary>Internal usage: Constructor to forward the wrapper initialization to the root class that interfaces with native code. Should not be used directly.</summary>
38 protected LoopFd(IntPtr base_klass, System.Type managed_type, Efl.Object parent) : base(base_klass, managed_type, parent) {}
39 ///<summary>Verifies if the given object is equal to this one.</summary>
40 public override bool Equals(object obj)
42 var other = obj as Efl.Object;
45 return this.NativeHandle == other.NativeHandle;
47 ///<summary>Gets the hash code for this object based on the native pointer it points to.</summary>
48 public override int GetHashCode()
50 return this.NativeHandle.ToInt32();
52 ///<summary>Turns the native pointer into a string representation.</summary>
53 public override String ToString()
55 return $"{this.GetType().Name}@[{this.NativeHandle.ToInt32():x}]";
57 private static object ReadEvtKey = new object();
58 /// <summary>Called when a read happened on the file descriptor</summary>
59 public event EventHandler ReadEvt
63 string key = "_EFL_LOOP_FD_EVENT_READ";
64 if (AddNativeEventHandler(efl.Libs.Ecore, key, this.evt_ReadEvt_delegate)) {
65 eventHandlers.AddHandler(ReadEvtKey , value);
67 Eina.Log.Error($"Error adding proxy for event {key}");
72 string key = "_EFL_LOOP_FD_EVENT_READ";
73 if (RemoveNativeEventHandler(key, this.evt_ReadEvt_delegate)) {
74 eventHandlers.RemoveHandler(ReadEvtKey , value);
76 Eina.Log.Error($"Error removing proxy for event {key}");
80 ///<summary>Method to raise event ReadEvt.</summary>
81 public void On_ReadEvt(EventArgs e)
85 evt = (EventHandler)eventHandlers[ReadEvtKey];
89 Efl.EventCb evt_ReadEvt_delegate;
90 private void on_ReadEvt_NativeCallback(System.IntPtr data, ref Efl.Event.NativeStruct evt)
92 EventArgs args = EventArgs.Empty;
95 } catch (Exception e) {
96 Eina.Log.Error(e.ToString());
97 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
101 private static object WriteEvtKey = new object();
102 /// <summary>Called when a write happened on the file descriptor</summary>
103 public event EventHandler WriteEvt
107 string key = "_EFL_LOOP_FD_EVENT_WRITE";
108 if (AddNativeEventHandler(efl.Libs.Ecore, key, this.evt_WriteEvt_delegate)) {
109 eventHandlers.AddHandler(WriteEvtKey , value);
111 Eina.Log.Error($"Error adding proxy for event {key}");
116 string key = "_EFL_LOOP_FD_EVENT_WRITE";
117 if (RemoveNativeEventHandler(key, this.evt_WriteEvt_delegate)) {
118 eventHandlers.RemoveHandler(WriteEvtKey , value);
120 Eina.Log.Error($"Error removing proxy for event {key}");
124 ///<summary>Method to raise event WriteEvt.</summary>
125 public void On_WriteEvt(EventArgs e)
129 evt = (EventHandler)eventHandlers[WriteEvtKey];
131 evt?.Invoke(this, e);
133 Efl.EventCb evt_WriteEvt_delegate;
134 private void on_WriteEvt_NativeCallback(System.IntPtr data, ref Efl.Event.NativeStruct evt)
136 EventArgs args = EventArgs.Empty;
139 } catch (Exception e) {
140 Eina.Log.Error(e.ToString());
141 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
145 private static object ErrorEvtKey = new object();
146 /// <summary>Called when a error occurred on the file descriptor</summary>
147 public event EventHandler ErrorEvt
151 string key = "_EFL_LOOP_FD_EVENT_ERROR";
152 if (AddNativeEventHandler(efl.Libs.Ecore, key, this.evt_ErrorEvt_delegate)) {
153 eventHandlers.AddHandler(ErrorEvtKey , value);
155 Eina.Log.Error($"Error adding proxy for event {key}");
160 string key = "_EFL_LOOP_FD_EVENT_ERROR";
161 if (RemoveNativeEventHandler(key, this.evt_ErrorEvt_delegate)) {
162 eventHandlers.RemoveHandler(ErrorEvtKey , value);
164 Eina.Log.Error($"Error removing proxy for event {key}");
168 ///<summary>Method to raise event ErrorEvt.</summary>
169 public void On_ErrorEvt(EventArgs e)
173 evt = (EventHandler)eventHandlers[ErrorEvtKey];
175 evt?.Invoke(this, e);
177 Efl.EventCb evt_ErrorEvt_delegate;
178 private void on_ErrorEvt_NativeCallback(System.IntPtr data, ref Efl.Event.NativeStruct evt)
180 EventArgs args = EventArgs.Empty;
183 } catch (Exception e) {
184 Eina.Log.Error(e.ToString());
185 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
189 ///<summary>Register the Eo event wrappers making the bridge to C# events. Internal usage only.</summary>
190 protected override void RegisterEventProxies()
192 base.RegisterEventProxies();
193 evt_ReadEvt_delegate = new Efl.EventCb(on_ReadEvt_NativeCallback);
194 evt_WriteEvt_delegate = new Efl.EventCb(on_WriteEvt_NativeCallback);
195 evt_ErrorEvt_delegate = new Efl.EventCb(on_ErrorEvt_NativeCallback);
197 /// <summary>Defines which file descriptor to watch. If it is a file, use file_fd variant.</summary>
198 /// <returns>The file descriptor.</returns>
199 virtual public int GetFd() {
200 var _ret_var = Efl.LoopFdNativeInherit.efl_loop_fd_get_ptr.Value.Delegate((inherited ? Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass) : this.NativeHandle));
201 Eina.Error.RaiseIfUnhandledException();
204 /// <summary>Defines the fd to watch.</summary>
205 /// <param name="fd">The file descriptor.</param>
206 /// <returns></returns>
207 virtual public void SetFd( int fd) {
208 Efl.LoopFdNativeInherit.efl_loop_fd_set_ptr.Value.Delegate((inherited ? Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass) : this.NativeHandle), fd);
209 Eina.Error.RaiseIfUnhandledException();
211 /// <summary>Defines which file descriptor to watch when watching a file.</summary>
212 /// <returns>The file descriptor.</returns>
213 virtual public int GetFdFile() {
214 var _ret_var = Efl.LoopFdNativeInherit.efl_loop_fd_file_get_ptr.Value.Delegate((inherited ? Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass) : this.NativeHandle));
215 Eina.Error.RaiseIfUnhandledException();
218 /// <summary>Defines the fd to watch on.</summary>
219 /// <param name="fd">The file descriptor.</param>
220 /// <returns></returns>
221 virtual public void SetFdFile( int fd) {
222 Efl.LoopFdNativeInherit.efl_loop_fd_file_set_ptr.Value.Delegate((inherited ? Efl.Eo.Globals.efl_super(this.NativeHandle, this.NativeClass) : this.NativeHandle), fd);
223 Eina.Error.RaiseIfUnhandledException();
225 /// <summary>Defines which file descriptor to watch. If it is a file, use file_fd variant.</summary>
226 /// <value>The file descriptor.</value>
228 get { return GetFd(); }
229 set { SetFd( value); }
231 /// <summary>Defines which file descriptor to watch when watching a file.</summary>
232 /// <value>The file descriptor.</value>
234 get { return GetFdFile(); }
235 set { SetFdFile( value); }
237 private static IntPtr GetEflClassStatic()
239 return Efl.LoopFd.efl_loop_fd_class_get();
242 public class LoopFdNativeInherit : Efl.LoopConsumerNativeInherit{
243 public new static Efl.Eo.NativeModule _Module = new Efl.Eo.NativeModule(efl.Libs.Ecore);
244 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
246 var descs = new System.Collections.Generic.List<Efl_Op_Description>();
247 var methods = Efl.Eo.Globals.GetUserMethods(type);
248 if (efl_loop_fd_get_static_delegate == null)
249 efl_loop_fd_get_static_delegate = new efl_loop_fd_get_delegate(fd_get);
250 if (methods.FirstOrDefault(m => m.Name == "GetFd") != null)
251 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_loop_fd_get"), func = Marshal.GetFunctionPointerForDelegate(efl_loop_fd_get_static_delegate)});
252 if (efl_loop_fd_set_static_delegate == null)
253 efl_loop_fd_set_static_delegate = new efl_loop_fd_set_delegate(fd_set);
254 if (methods.FirstOrDefault(m => m.Name == "SetFd") != null)
255 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_loop_fd_set"), func = Marshal.GetFunctionPointerForDelegate(efl_loop_fd_set_static_delegate)});
256 if (efl_loop_fd_file_get_static_delegate == null)
257 efl_loop_fd_file_get_static_delegate = new efl_loop_fd_file_get_delegate(fd_file_get);
258 if (methods.FirstOrDefault(m => m.Name == "GetFdFile") != null)
259 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_loop_fd_file_get"), func = Marshal.GetFunctionPointerForDelegate(efl_loop_fd_file_get_static_delegate)});
260 if (efl_loop_fd_file_set_static_delegate == null)
261 efl_loop_fd_file_set_static_delegate = new efl_loop_fd_file_set_delegate(fd_file_set);
262 if (methods.FirstOrDefault(m => m.Name == "SetFdFile") != null)
263 descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_loop_fd_file_set"), func = Marshal.GetFunctionPointerForDelegate(efl_loop_fd_file_set_static_delegate)});
264 descs.AddRange(base.GetEoOps(type));
267 public override IntPtr GetEflClass()
269 return Efl.LoopFd.efl_loop_fd_class_get();
271 public static new IntPtr GetEflClassStatic()
273 return Efl.LoopFd.efl_loop_fd_class_get();
277 private delegate int efl_loop_fd_get_delegate(System.IntPtr obj, System.IntPtr pd);
280 public delegate int efl_loop_fd_get_api_delegate(System.IntPtr obj);
281 public static Efl.Eo.FunctionWrapper<efl_loop_fd_get_api_delegate> efl_loop_fd_get_ptr = new Efl.Eo.FunctionWrapper<efl_loop_fd_get_api_delegate>(_Module, "efl_loop_fd_get");
282 private static int fd_get(System.IntPtr obj, System.IntPtr pd)
284 Eina.Log.Debug("function efl_loop_fd_get was called");
285 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
286 if(wrapper != null) {
287 int _ret_var = default(int);
289 _ret_var = ((LoopFd)wrapper).GetFd();
290 } catch (Exception e) {
291 Eina.Log.Warning($"Callback error: {e.ToString()}");
292 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
296 return efl_loop_fd_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
299 private static efl_loop_fd_get_delegate efl_loop_fd_get_static_delegate;
302 private delegate void efl_loop_fd_set_delegate(System.IntPtr obj, System.IntPtr pd, int fd);
305 public delegate void efl_loop_fd_set_api_delegate(System.IntPtr obj, int fd);
306 public static Efl.Eo.FunctionWrapper<efl_loop_fd_set_api_delegate> efl_loop_fd_set_ptr = new Efl.Eo.FunctionWrapper<efl_loop_fd_set_api_delegate>(_Module, "efl_loop_fd_set");
307 private static void fd_set(System.IntPtr obj, System.IntPtr pd, int fd)
309 Eina.Log.Debug("function efl_loop_fd_set was called");
310 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
311 if(wrapper != null) {
314 ((LoopFd)wrapper).SetFd( fd);
315 } catch (Exception e) {
316 Eina.Log.Warning($"Callback error: {e.ToString()}");
317 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
320 efl_loop_fd_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), fd);
323 private static efl_loop_fd_set_delegate efl_loop_fd_set_static_delegate;
326 private delegate int efl_loop_fd_file_get_delegate(System.IntPtr obj, System.IntPtr pd);
329 public delegate int efl_loop_fd_file_get_api_delegate(System.IntPtr obj);
330 public static Efl.Eo.FunctionWrapper<efl_loop_fd_file_get_api_delegate> efl_loop_fd_file_get_ptr = new Efl.Eo.FunctionWrapper<efl_loop_fd_file_get_api_delegate>(_Module, "efl_loop_fd_file_get");
331 private static int fd_file_get(System.IntPtr obj, System.IntPtr pd)
333 Eina.Log.Debug("function efl_loop_fd_file_get was called");
334 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
335 if(wrapper != null) {
336 int _ret_var = default(int);
338 _ret_var = ((LoopFd)wrapper).GetFdFile();
339 } catch (Exception e) {
340 Eina.Log.Warning($"Callback error: {e.ToString()}");
341 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
345 return efl_loop_fd_file_get_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)));
348 private static efl_loop_fd_file_get_delegate efl_loop_fd_file_get_static_delegate;
351 private delegate void efl_loop_fd_file_set_delegate(System.IntPtr obj, System.IntPtr pd, int fd);
354 public delegate void efl_loop_fd_file_set_api_delegate(System.IntPtr obj, int fd);
355 public static Efl.Eo.FunctionWrapper<efl_loop_fd_file_set_api_delegate> efl_loop_fd_file_set_ptr = new Efl.Eo.FunctionWrapper<efl_loop_fd_file_set_api_delegate>(_Module, "efl_loop_fd_file_set");
356 private static void fd_file_set(System.IntPtr obj, System.IntPtr pd, int fd)
358 Eina.Log.Debug("function efl_loop_fd_file_set was called");
359 Efl.Eo.IWrapper wrapper = Efl.Eo.Globals.PrivateDataGet(pd);
360 if(wrapper != null) {
363 ((LoopFd)wrapper).SetFdFile( fd);
364 } catch (Exception e) {
365 Eina.Log.Warning($"Callback error: {e.ToString()}");
366 Eina.Error.Set(Eina.Error.UNHANDLED_EXCEPTION);
369 efl_loop_fd_file_set_ptr.Value.Delegate(Efl.Eo.Globals.efl_super(obj, Efl.Eo.Globals.efl_class_get(obj)), fd);
372 private static efl_loop_fd_file_set_delegate efl_loop_fd_file_set_static_delegate;