PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1indexing
  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					
  9					This library is free software; you can redistribute it and/or
 10					modify it under the terms of the GNU Lesser General Public License
 11					as published by the Free Software Foundation; either version 2.1 of
 12					the License, or (at your option) any later version.
 13					
 14					This library is distributed in the hope that it will be useful, but
 15					WITHOUT ANY WARRANTY; without even the implied warranty of
 16					MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17					Lesser General Public License for more details.
 18
 19					You should have received a copy of the GNU Lesser General Public
 20					License along with this library; if not, write to the Free Software
 21					Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 22					02110-1301 USA
 23			]"
 24
 25deferred class GLIB_TIMEOUT
 26
 27inherit ANY undefine is_equal, copy end
 28
 29
 30
 31feature -- Access
 32
 33	enabled: BOOLEAN
 34			-- Periodical events are being called
 35
 36feature -- Operations
 37
 38	enable (interval: INTEGER_32) is
 39			-- Start periodic event call every `interval' ms
 40		require
 41			not enabled
 42		do
 43			event_id := g_timeout_add (interval, $callback, to_pointer)
 44			enabled := True
 45		ensure
 46			enabled
 47		end
 48
 49	disable is
 50			-- Stop periodic event call
 51		require
 52			enabled
 53		do
 54			enabled := False
 55		ensure
 56			not enabled
 57		end
 58
 59	tick is
 60			-- Called every interval. Call `disable' from here to be the last
 61			-- tick.
 62		deferred
 63		end
 64
 65feature {} -- Internal
 66
 67	event_id: INTEGER_32
 68
 69	callback: INTEGER_32 is
 70		do
 71			tick
 72			Result := enabled.to_integer
 73		end
 74
 75feature {} -- Externals
 76
 77	g_timeout_add (interval: INTEGER_32; function, data: POINTER): INTEGER_32 is
 78			-- Sets a `function' to be called at regular intervals, with the
 79			-- default priority, G_PRIORITY_DEFAULT. The function is called
 80			-- repeatedly until it returns FALSE, at which point the timeout
 81			-- is automatically destroyed and the function will not be
 82			-- called again. The first call to the function will be at the
 83			-- end of the first interval.
 84		require
 85			interval >= 0
 86			function.is_not_null
 87			data.is_not_null
 88		external "C use <gtk/gtk.h>"
 89		end
 90
 91-- GSource*    g_timeout_source_new            (guint interval);
 92-- guint       g_timeout_add_full              (gint priority,
 93--                                              guint interval,
 94--                                              GSourceFunc function,
 95--                                              gpointer data,
 96--                                              GDestroyNotify notify);
 97
 98-- g_timeout_source_new ()
 99
100-- GSource*    g_timeout_source_new            (guint interval);
101
102-- Creates a new timeout source.
103
104-- 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.
105
106-- interval : 	the timeout interval in milliseconds.
107-- Returns : 	the newly-created timeout source
108-- g_timeout_add_full ()
109
110-- guint       g_timeout_add_full              (gint priority,
111--                                              guint interval,
112--                                              GSourceFunc function,
113--                                              gpointer data,
114--                                              GDestroyNotify notify);
115
116-- 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.
117
118-- 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).
119
120-- priority : 	the priority of the idle source. Typically this will be in the range between G_PRIORITY_DEFAULT_IDLE and G_PRIORITY_HIGH_IDLE.
121-- interval : 	the time between calls to the function, in milliseconds (1/1000ths of a second)
122-- function : 	function to call
123-- data : 	data to pass to function
124-- notify : 	function to call when the idle is removed, or NULL
125-- Returns : 	the id of event source.
126end