/src/wrappers/glib/library/core/glib_timeout.e

http://github.com/tybor/Liberty · Specman e · 126 lines · 61 code · 28 blank · 37 comment · 3 complexity · 6cd9bb7f7a3688ffa6f6f01cb9fc5d1e MD5 · raw file

  1. indexing
  2. description: "[
  3. Base class for having timed periodical events called from
  4. the main loop
  5. "]
  6. copyright: "[
  7. Copyright (C) 2006 Paolo Redaelli, eiffel-gtk team
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public License
  10. as published by the Free Software Foundation; either version 2.1 of
  11. the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. 02110-1301 USA
  20. ]"
  21. deferred class GLIB_TIMEOUT
  22. inherit ANY undefine is_equal, copy end
  23. feature -- Access
  24. enabled: BOOLEAN
  25. -- Periodical events are being called
  26. feature -- Operations
  27. enable (interval: INTEGER_32) is
  28. -- Start periodic event call every `interval' ms
  29. require
  30. not enabled
  31. do
  32. event_id := g_timeout_add (interval, $callback, to_pointer)
  33. enabled := True
  34. ensure
  35. enabled
  36. end
  37. disable is
  38. -- Stop periodic event call
  39. require
  40. enabled
  41. do
  42. enabled := False
  43. ensure
  44. not enabled
  45. end
  46. tick is
  47. -- Called every interval. Call `disable' from here to be the last
  48. -- tick.
  49. deferred
  50. end
  51. feature {} -- Internal
  52. event_id: INTEGER_32
  53. callback: INTEGER_32 is
  54. do
  55. tick
  56. Result := enabled.to_integer
  57. end
  58. feature {} -- Externals
  59. g_timeout_add (interval: INTEGER_32; function, data: POINTER): INTEGER_32 is
  60. -- Sets a `function' to be called at regular intervals, with the
  61. -- default priority, G_PRIORITY_DEFAULT. The function is called
  62. -- repeatedly until it returns FALSE, at which point the timeout
  63. -- is automatically destroyed and the function will not be
  64. -- called again. The first call to the function will be at the
  65. -- end of the first interval.
  66. require
  67. interval >= 0
  68. function.is_not_null
  69. data.is_not_null
  70. external "C use <gtk/gtk.h>"
  71. end
  72. -- GSource* g_timeout_source_new (guint interval);
  73. -- guint g_timeout_add_full (gint priority,
  74. -- guint interval,
  75. -- GSourceFunc function,
  76. -- gpointer data,
  77. -- GDestroyNotify notify);
  78. -- g_timeout_source_new ()
  79. -- GSource* g_timeout_source_new (guint interval);
  80. -- Creates a new timeout source.
  81. -- The source will not initially be associated with any GMainContext and must be added to one with g_source_attach() before it will be executed.
  82. -- interval : the timeout interval in milliseconds.
  83. -- Returns : the newly-created timeout source
  84. -- g_timeout_add_full ()
  85. -- guint g_timeout_add_full (gint priority,
  86. -- guint interval,
  87. -- GSourceFunc function,
  88. -- gpointer data,
  89. -- GDestroyNotify notify);
  90. -- Sets a function to be called at regular intervals, with the given priority. The function is called repeatedly until it returns FALSE, at which point the timeout is automatically destroyed and the function will not be called again. The notify function is called when the timeout is destroyed. The first call to the function will be at the end of the first interval.
  91. -- Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval (it does not try to 'catch up' time lost in delays).
  92. -- priority : the priority of the idle source. Typically this will be in the range between G_PRIORITY_DEFAULT_IDLE and G_PRIORITY_HIGH_IDLE.
  93. -- interval : the time between calls to the function, in milliseconds (1/1000ths of a second)
  94. -- function : function to call
  95. -- data : data to pass to function
  96. -- notify : function to call when the idle is removed, or NULL
  97. -- Returns : the id of event source.
  98. end