开发者

possible to retrieve time left on a glib 'event?'

开发者 https://www.devze.com 2023-01-22 12:13 出处:网络
I am creating an event with g_timeout_add or g_timeout_add_seconds w开发者_C百科hich returns an event id; I can cancel the event by calling g_source_remove.

I am creating an event with g_timeout_add or g_timeout_add_seconds w开发者_C百科hich returns an event id; I can cancel the event by calling g_source_remove.

However, at some point what I would like to do is see how much time is remaining until the event is fired. Is there a simple way to do this with the glib api, or do I need to manually store and compare timestamps with g_source_get_current_time?


There is no reasonable way to do this in GLib.

The unreasonable way would be to get the GSource (g_main_context_find_source_by_id) and then invoke the source->source_funcs->prepare() operation on the GSource, which would return the time until the source should be dispatched. This is kind of sketchy: source_funcs is private, and prepare() isn't really intended to be used except internally by the main loop.

Best I can tell it would work though. I haven't tried it.


save the start time + timeout interval, subract from current time when you want to know the time left.

0

精彩评论

暂无评论...
验证码 换一张
取 消