John Ledbetter
John Ledbetter

Reputation: 14183

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

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?

Upvotes: 5

Views: 291

Answers (2)

rlt
rlt

Reputation: 21

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

Upvotes: 2

Havoc P
Havoc P

Reputation: 8467

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.

Upvotes: 3

Related Questions