Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

linux

timer

glib

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?

like image 879
John Ledbetter Avatar asked Oct 27 '10 22:10

John Ledbetter


2 Answers

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.

like image 157
Havoc P Avatar answered Sep 22 '22 02:09

Havoc P


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

like image 26
rlt Avatar answered Sep 22 '22 02:09

rlt