tags:

views:

19

answers:

1

I am creating an event with g_timeout_add or g_timeout_add_seconds which 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?

+2  A: 

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.

Havoc P
Thanks; I'd rather not depend on any private functionality that may or may not change, so I guess I'll have to keep track of the time myself.
John Ledbetter