Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Maemo: Developers

sensing change in System Clock using Qt

 

 

Maemo developers RSS feed   Index | Next | Previous | View Threaded


ibrahim.ali at asgatech

Jan 24, 2010, 1:55 AM

Post #1 of 8 (3126 views)
Permalink
sensing change in System Clock using Qt

Greetings;

I am creating a Qt application that depends on system clock (get the
current system time/date) to do time-dependent calculations. (calculate
duration from current time to a specifed/calculated duration in the
future, and set a QTimer's interval to that duration).

But the problem that can face me is the case when the user changes his
clock settings (i.e adjust phone's time to a different time). in this
case, the timer that has been set to some fixed duration can go wrong.

One solution i figured is to check for system time change every fixed
period (say a minute). But it seems a very ugly one since it is bad for
performance and not handy (wait for the next minute to come to check for
the clock and realize it was changed)

my question is: is there any way to get notified by the system clock of
any change/adjustments ? any signals sent by the system phone or
something like that ?

thanx in advance
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


Remi.Denis-Courmont at nokia

Jan 25, 2010, 11:20 PM

Post #2 of 8 (3024 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

Hello,

----- Message d'origine -----
> But the problem that can face me is the case when the user changes his
> clock settings (i.e adjust phone's time to a different time). in this
> case, the timer that has been set to some fixed duration can go wrong.

As a general rule, delay measurements should be done with the monotonic clock, not the wall clock (the real-time clock). As far as I know, Qt timers already do so internally. But of course, your own code should never request and use the wall clock for time measurements.

> One solution i figured is to check for system time change every fixed
> period (say a minute). But it seems a very ugly one since it is bad for
> performance and not handy (wait for the next minute to come to check
> for
> the clock and realize it was changed)

This is awful and pointless.

> my question is: is there any way to get notified by the system clock of
> any change/adjustments ? any signals sent by the system phone or
> something like that ?

That is not something you should be concerned with in the first place. If you do, it is a very strong hint that you are using the wrong clock.
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


ibrahim.ali at asgatech

Jan 30, 2010, 11:41 PM

Post #3 of 8 (2971 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

Remi.Denis-Courmont [at] nokia wrote:
> Hello,
>
> ----- Message d'origine -----
>
>> But the problem that can face me is the case when the user changes his
>> clock settings (i.e adjust phone's time to a different time). in this
>> case, the timer that has been set to some fixed duration can go wrong.
>>
>
> As a general rule, delay measurements should be done with the monotonic clock, not the wall clock (the real-time clock). As far as I know, Qt timers already do so internally. But of course, your own code should never request and use the wall clock for time measurements.
>
>
I don't think I follow you! What do you mean by monotonic clock ? If I
don't depend on the system's clock to get current time, where else can I
get it from ?
Let me explain my problem again briefly, I want to know the current
time, calculate some future durations depending on it. Then I figure
out the time left to the upcoming duration and set it as interval to a
QTimer Object. But I'm afraid that user may change the system clock
(adjust the clock) So that my preset time will be invalid.

_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


david at dgreaves

Jan 31, 2010, 12:36 AM

Post #4 of 8 (2967 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

ibrahim wrote:
> Remi.Denis-Courmont [at] nokia wrote:
>> Hello,
>>
>> ----- Message d'origine -----
>>
>>> But the problem that can face me is the case when the user changes his
>>> clock settings (i.e adjust phone's time to a different time). in this
>>> case, the timer that has been set to some fixed duration can go wrong.
>>>
>>
>> As a general rule, delay measurements should be done with the
>> monotonic clock, not the wall clock (the real-time clock). As far as I
>> know, Qt timers already do so internally. But of course, your own code
>> should never request and use the wall clock for time measurements.
>>
>>
> I don't think I follow you! What do you mean by monotonic clock ? If I
> don't depend on the system's clock to get current time, where else can I
> get it from ?
> Let me explain my problem again briefly, I want to know the current
> time, calculate some future durations depending on it. Then I figure
> out the time left to the upcoming duration and set it as interval to a
> QTimer Object. But I'm afraid that user may change the system clock
> (adjust the clock) So that my preset time will be invalid.

Just so you know... you're describing an implementation and asking if it does
what you want without describing what you want.

Example: "At 4am the user wants to play a sound at 8am (in 4hrs). At 6am the
user changes timezone and it becomes 7am. The alarm should sound at 8am in the
new timezone."

My guess is that you know about interval timers but you should be using a
wall-clock. Since you haven't specified what you want it's hard to know.

David

--
"Don't worry, you'll be fine; I saw it work in a cartoon once..."
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


ibrahim.ali at asgatech

Jan 31, 2010, 1:45 AM

Post #5 of 8 (2969 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

David Greaves wrote:
> ibrahim wrote:
>
>> Remi.Denis-Courmont [at] nokia wrote:
>>
>>> Hello,
>>>
>>> ----- Message d'origine -----
>>>
>>>
>>>> But the problem that can face me is the case when the user changes his
>>>> clock settings (i.e adjust phone's time to a different time). in this
>>>> case, the timer that has been set to some fixed duration can go wrong.
>>>>
>>>>
>>> As a general rule, delay measurements should be done with the
>>> monotonic clock, not the wall clock (the real-time clock). As far as I
>>> know, Qt timers already do so internally. But of course, your own code
>>> should never request and use the wall clock for time measurements.
>>>
>>>
>>>
>> I don't think I follow you! What do you mean by monotonic clock ? If I
>> don't depend on the system's clock to get current time, where else can I
>> get it from ?
>> Let me explain my problem again briefly, I want to know the current
>> time, calculate some future durations depending on it. Then I figure
>> out the time left to the upcoming duration and set it as interval to a
>> QTimer Object. But I'm afraid that user may change the system clock
>> (adjust the clock) So that my preset time will be invalid.
>>
>
> Just so you know... you're describing an implementation and asking if it does
> what you want without describing what you want.
>
> Example: "At 4am the user wants to play a sound at 8am (in 4hrs). At 6am the
> user changes timezone and it becomes 7am. The alarm should sound at 8am in the
> new timezone."
>
> My guess is that you know about interval timers but you should be using a
> wall-clock. Since you haven't specified what you want it's hard to know.
>
> David
>
>
I am very sorry for not making my question clear enough. But the
situation you just described is JUST what I want to do! Yes, I want to
do something exactly as you described; I am now at 4:00 am, I need to
make my app do something at - say - 8:00 am (the time of the alarm is
calculated and varies from time to time, so i can't just use cron jobs
to schedule the next alarm), So, I used a QTimer and set its interval to
the duration between now and the next alarm. BUT this solution won't
work if user decides to adjust the system clock/change timezone.
What I'm asking is there anyway to GET NOTIFIED by the system when its
clock/timezone changes (in order to recalculate the next alarm and set
my Qtimer object to a new duration)?? any signal emitted ? anything?

I hope i made my question clear and sorry for any inconvenience.
thanks again
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


trippin1 at gmail

Jan 31, 2010, 2:45 AM

Post #6 of 8 (2967 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

There are many D-Bus signals emitted when the time zone changes. Try
and make the effort to run dbus-monitor --system, please.

Failing that, the following pages exist:
http://maemo.org/api_refs/5.0/5.0-final/libosso/group__Time.html
http://maemo.org/api_refs/5.0/5.0-final/clockd/

Best Regards,
Faheem

On Sun, Jan 31, 2010 at 9:45 AM, ibrahim <ibrahim.ali [at] asgatech> wrote:
> David Greaves wrote:
>>
>> ibrahim wrote:
>>
>>>
>>> Remi.Denis-Courmont [at] nokia wrote:
>>>
>>>>
>>>>   Hello,
>>>>
>>>> ----- Message d'origine -----
>>>>
>>>>>
>>>>> But the problem that can face me is the case when the user changes his
>>>>> clock settings (i.e adjust phone's time to a different time). in this
>>>>> case, the timer that has been set to some fixed duration can go wrong.
>>>>>
>>>>
>>>> As a general rule, delay measurements should be done with the
>>>> monotonic clock, not the wall clock (the real-time clock). As far as I
>>>> know, Qt timers already do so internally. But of course, your own code
>>>> should never request and use the wall clock for time measurements.
>>>>
>>>>
>>>
>>> I don't think I follow you! What do you mean by monotonic clock ? If I
>>> don't depend on the system's clock to get current time, where else can I
>>> get it from ?
>>> Let me explain my problem again briefly, I want to know the current
>>> time, calculate some future durations  depending on it. Then I figure
>>> out the time left to the upcoming duration and set it as interval to a
>>> QTimer Object. But I'm afraid that user may change the system clock
>>> (adjust the clock) So that my preset time will be invalid.
>>>
>>
>> Just so you know... you're describing an implementation and asking if it
>> does
>> what you want without describing what you want.
>>
>> Example: "At 4am the user wants to play a sound at 8am (in 4hrs). At 6am
>> the
>> user changes timezone and it becomes 7am. The alarm should sound at 8am in
>> the
>> new timezone."
>>
>> My guess is that you know about interval timers but you should be using a
>> wall-clock. Since you haven't specified what you want it's hard to know.
>>
>> David
>>
>>
>
> I am very sorry for not making my question clear enough. But the situation
> you just described is JUST what I want to do! Yes, I want to do something
> exactly as you described; I am now at 4:00 am, I need to make my app do
> something at - say - 8:00 am (the time of the alarm is calculated and varies
> from time to time, so i can't just use cron jobs to schedule the next
> alarm), So, I used a QTimer and set its interval to the duration between now
> and the next alarm. BUT this solution won't work if user decides to adjust
> the system clock/change timezone.
> What I'm asking is there anyway to GET NOTIFIED by the system when its
> clock/timezone changes (in order to recalculate the next alarm and set my
> Qtimer object to a new duration)?? any signal emitted ? anything?
>
> I hope i made my question clear and sorry for any inconvenience.
> thanks again
> _______________________________________________
> maemo-developers mailing list
> maemo-developers [at] maemo
> https://lists.maemo.org/mailman/listinfo/maemo-developers
>
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers


nomrasco at gmail

Jan 31, 2010, 4:59 AM

Post #7 of 8 (2965 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

ibrahim wrote:
> I am very sorry for not making my question clear enough. But the
> situation you just described is JUST what I want to do! Yes, I want to
> do something exactly as you described; I am now at 4:00 am, I need to
> make my app do something at - say - 8:00 am (the time of the alarm is
> calculated and varies from time to time, so i can't just use cron jobs
> to schedule the next alarm), So, I used a QTimer and set its interval to
> the duration between now and the next alarm. BUT this solution won't
> work if user decides to adjust the system clock/change timezone.
> What I'm asking is there anyway to GET NOTIFIED by the system when > its
> clock/timezone changes (in order to recalculate the next alarm and set
> my Qtimer object to a new duration)?? any signal emitted ? anything?

> I hope i made my question clear and sorry for any inconvenience.
> thanks again

Hi,

You should check libalarm API and its feautures (
http://maemo.org/api_refs/5.0/5.0-final/libalarm/). It provides You exactly
what You want... the only problem is that it is in pure C. You can add alarm
and forget about QTimer etc. Device could be even boot up on You alarm if
that is a behaviour You would like to get (and device was switched off
before Your alarm;) ). It should not be to hard to use this library in Qt
code. Furthermore, You can check another library provided by Nokia - libtime
(http://maemo.org/api_refs/5.0/5.0-final/clockd/). It allows You to
communicate with clockd which is responsible for maintaining time on the
device. clockd daemon also sends D-Bus signal (
http://maemo.org/api_refs/5.0/5.0-final/clockd/libtime_8h.html just at the
top of the page :) ) after time was changed by the user or time was
synchronized and changed to different GMT offset (this is not working with
every GSM network though).

So.. fast reply for Your question is: signal send by clockd. Better
solution: use libalarm which will save You a lot of time :)

Best Regards
--
nomrasco
software development


ibrahim.ali at asgatech

Jan 31, 2010, 5:04 AM

Post #8 of 8 (2965 views)
Permalink
Re: sensing change in System Clock using Qt [In reply to]

nomrasco wrote:
> ibrahim wrote:
> > I am very sorry for not making my question clear enough. But the
> > situation you just described is JUST what I want to do! Yes, I want to
> > do something exactly as you described; I am now at 4:00 am, I need to
> > make my app do something at - say - 8:00 am (the time of the alarm is
> > calculated and varies from time to time, so i can't just use cron jobs
> > to schedule the next alarm), So, I used a QTimer and set its interval to
> > the duration between now and the next alarm. BUT this solution won't
> > work if user decides to adjust the system clock/change timezone.
> > What I'm asking is there anyway to GET NOTIFIED by the system when > its
> > clock/timezone changes (in order to recalculate the next alarm and set
> > my Qtimer object to a new duration)?? any signal emitted ? anything?
>
> > I hope i made my question clear and sorry for any inconvenience.
> > thanks again
>
> Hi,
>
> You should check libalarm API and its feautures
> (http://maemo.org/api_refs/5.0/5.0-final/libalarm/). It provides You
> exactly what You want... the only problem is that it is in pure C. You
> can add alarm and forget about QTimer etc. Device could be even boot
> up on You alarm if that is a behaviour You would like to get (and
> device was switched off before Your alarm;) ). It should not be to
> hard to use this library in Qt code. Furthermore, You can check
> another library provided by Nokia - libtime
> (http://maemo.org/api_refs/5.0/5.0-final/clockd/). It allows You to
> communicate with clockd which is responsible for maintaining time on
> the device. clockd daemon also sends D-Bus signal
> (http://maemo.org/api_refs/5.0/5.0-final/clockd/libtime_8h.html just
> at the top of the page :) ) after time was changed by the user or time
> was synchronized and changed to different GMT offset (this is not
> working with every GSM network though).
>
> So.. fast reply for Your question is: signal send by clockd. Better
> solution: use libalarm which will save You a lot of time :)
>
> Best Regards
> --
> nomrasco
> software development
thank you very much for your response. I will try both your and faheem's
answers. will get back to you soon if everything happens
thanks again
_______________________________________________
maemo-developers mailing list
maemo-developers [at] maemo
https://lists.maemo.org/mailman/listinfo/maemo-developers

Maemo developers RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.