/src/wrappers/gobject/library/g_signals.e

http://github.com/tybor/Liberty · Specman e · 102 lines · 53 code · 14 blank · 35 comment · 2 complexity · d52464f8dc569a9a60a068e2ee0f6094 MD5 · raw file

  1. indexing
  2. description: "Utility functions dealing with Gobject signals"
  3. deferred class G_SIGNALS
  4. inherit
  5. WRAPPER_HANDLER
  6. undefine null_or end
  7. insert G_SIGNAL_EXTERNALS
  8. feature
  9. query (an_id: INTEGER): G_SIGNAL_QUERY is
  10. -- Queries the signal system for in-depth information about a
  11. -- specific signal. This function will fill in a
  12. -- user-provided structure to hold signal-specific
  13. -- information. If an invalid signal id is passed in, the
  14. -- signal_id member of the GSignalQuery is 0.
  15. -- `an_id': The signal id of the signal to query information
  16. -- for.
  17. do
  18. create Result.allocate
  19. -- Note: TODO: signal_id is guint therefore an_id shall be NATURAL
  20. g_signal_query (an_id, Result.handle)
  21. end
  22. lookup (a_name: STRING; a_type: INTEGER): INTEGER is
  23. -- identifying integer of signal `a_name' emitted by objects
  24. -- with type number `a_type`. Emitting the signal by number
  25. -- is somewhat faster than using the name each time.
  26. -- Also tries the ancestors of the given type.
  27. -- It is 0 if no signal was found.
  28. do
  29. Result:=g_signal_lookup (a_name.to_external,a_type)
  30. ensure positive: Result>=0
  31. end
  32. get_signal_name (an_id: INTEGER): STRING is
  33. -- Name of the signal with identifier equals to `an_id'. Two
  34. -- different signals may have the same name, if they have
  35. -- differing types.
  36. require valid_id: an_id>0
  37. local ptr: POINTER
  38. do
  39. ptr:=g_signal_name (an_id)
  40. if ptr.is_not_null
  41. then create Result.from_external_copy (ptr)
  42. else Result:=Void -- Note: Redundant, but more clear
  43. end
  44. end
  45. connect (an_object: G_OBJECT;
  46. a_signal_name: STRING;
  47. a_function_pointer: POINTER) is
  48. -- Directly connect `a_function' to the signal named
  49. -- `a_signal_name' for `an_object' (i.e. when `an_object'
  50. -- emits `a_signal_name' `a_function_pointer' will be called)
  51. -- Note: this function must be always called in this way:
  52. -- connect(Current,"my-signal",$a_feature_of_current). If you
  53. -- need a more flexible approach you can use CALLBACKs.
  54. require
  55. valid_object: an_object /= Void
  56. valid_signal_name: a_signal_name /= Void
  57. valid_function: a_function_pointer.is_not_null
  58. local an_id: INTEGER
  59. do
  60. -- The handler will be called before the default handler of the signal.
  61. -- instance : the instance to connect to.
  62. -- detailed_signal : a string of the form "signal-name::detail".
  63. -- c_handler : the GCallback to connect.
  64. -- data : data to pass to c_handler calls.
  65. -- Returns : the handler id
  66. an_id := g_signal_connect_swapped (an_object.handle,a_signal_name.to_external,
  67. a_function_pointer, an_object.to_pointer)
  68. -- g_signal_connect_swapped is necessary because SmartEiffel
  69. -- expect a pointer to an Eiffel object as first parameter of
  70. -- each function.
  71. debug
  72. print ("connect("+an_object.to_pointer.to_string+
  73. ", `"+a_signal_name+"', "+
  74. a_function_pointer.to_string+")%N")
  75. end
  76. end
  77. stop_by_name (instance: G_OBJECT; name: STRING) is
  78. -- Stops a signal's current emission.
  79. -- like `stop' except it will look up the signal id for you.
  80. -- `instance': the object whose signal handlers you wish to stop.
  81. -- `name': a string of the form "signal-name::detail".
  82. require
  83. instance /= Void
  84. name /= Void
  85. do
  86. g_signal_stop_emission_by_name (instance.handle, name.to_external)
  87. end
  88. end