1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * Moonlight List (moonlight-list@lists.ximian.com)
6 * Copyright 2007 Novell, Inc. (http://www.novell.com)
8 * See the LICENSE file included with the distribution for details.
18 #ifdef HAVE_SYS_TIME_H
23 #include "timesource.h"
29 gettimeofday (struct timeval
*tv
, void *tz
)
31 long int l
= GetTickCount ();
33 tv
->tv_sec
= l
/ 1000;
34 tv
->tv_usec
= (l
% 1000) * 1000;
45 #ifdef CLOCK_MONOTONIC
46 struct timespec tspec
;
47 if (clock_gettime (CLOCK_MONOTONIC
, &tspec
) == 0) {
48 res
= (TimeSpan
)((gint64
)tspec
.tv_sec
* 10000000 + tspec
.tv_nsec
/ 100);
53 if (gettimeofday (&tv
, NULL
) == 0) {
54 res
= (TimeSpan
)(tv
.tv_sec
* 1000000 + tv
.tv_usec
) * 10;
63 TimeSource::TimeSource (Deployment
*deployment
) : EventObject (deployment
)
65 SetObjectType (Type::TIMESOURCE
);
68 TimeSource::TimeSource ()
70 SetObjectType (Type::TIMESOURCE
);
73 TimeSource::~TimeSource ()
88 TimeSource::SetTimerFrequency (int frequency
)
98 SystemTimeSource::SystemTimeSource (Deployment
*deployment
) : TimeSource (deployment
)
100 SetObjectType (Type::SYSTEMTIMESOURCE
);
105 SystemTimeSource::SystemTimeSource ()
107 SetObjectType (Type::SYSTEMTIMESOURCE
);
112 SystemTimeSource::~SystemTimeSource ()
118 SystemTimeSource::SetTimerFrequency (int timeout
)
120 bool running
= timeout_id
!= 0;
132 SystemTimeSource::Start ()
138 g_warning ("SystemTimeSource::frequency uninitialized in ::Start()");
140 timeout_id
= g_timeout_add_full (MOON_PRIORITY_DEFAULT
, frequency
, SystemTimeSource::tick_timeout
, this, NULL
);
144 SystemTimeSource::Stop ()
146 if (timeout_id
!= 0) {
147 g_source_remove (timeout_id
);
153 SystemTimeSource::GetNow ()
159 SystemTimeSource::tick_timeout (gpointer data
)
161 SystemTimeSource
*source
= (SystemTimeSource
*)data
;
163 source
->SetCurrentDeployment ();
164 source
->Emit (TimeSource::TickEvent
);
168 ManualTimeSource::ManualTimeSource ()
170 SetObjectType (Type::MANUALTIMESOURCE
);
174 ManualTimeSource::~ManualTimeSource ()
179 ManualTimeSource::SetCurrentTime (TimeSpan current_time
)
181 this->current_time
= current_time
;
182 g_main_context_iteration (g_main_context_default (), false);
183 Emit (TimeSource::TickEvent
);
184 Emit (TimeSource::TickEvent
);
185 Emit (TimeSource::TickEvent
);
189 ManualTimeSource::GetNow ()