gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/Wal...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog libbase/Makefile.am libbase/Wal...
Date: Sun, 06 Apr 2008 17:48:33 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/04/06 17:48:33

Modified files:
        .              : ChangeLog 
        libbase        : Makefile.am WallClockTimer.cpp 
        server         : SystemClock.cpp 
        server/asobj   : Date.cpp NetStreamFfmpeg.cpp 
        utilities      : processor.cpp 
        gui            : gui.cpp 
Added files:
        libbase        : Time.cpp Time.h 
Removed files:
        libbase        : tu_timer.cpp tu_timer.h 

Log message:
                * libbase/tu_timer.{cpp,h}: drop, functions moved to 
Time.{cpp,h}.
                * libbase/Time.{cpp,h}: new file to collect all platform- and
                  implementation-dependent clock time code in namespace 
clocktime.
                  Includes the used functions of tu_timer, timezone detection
                  from Date.cpp and a partial boost date-time implementation of 
a
                  timer (not enabled by default).
                * libbase/Makefile.am: add Time, remove tu_timer.
                * libbase/WallClockTimer.cpp: change from tu_timer to clocktime.
                * server/SystemClock.cpp: tu_timer -> clocktime.
                * utilities/processor.cpp: tu_timer -> clocktime.
                * gui/gui.cpp: tu_timer -> clocktime.
                * server/asobj/NetStreamFfmpeg.cpp: tu_timer -> clocktime.
                * server/asobj/Date.cpp: update methods to take account of local
                  timezone. The calculation of timezone, now in Time.cpp, is
                  a bit dubious, but the Date class methods *should* be
                  internally consistent - the timezone may be wrong in some
                  cases, but the relationship between UTC and local time methods
                  is always correctly described in Date.getTimezoneOffset().

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6189&r2=1.6190
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Makefile.am?cvsroot=gnash&r1=1.105&r2=1.106
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/WallClockTimer.cpp?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Time.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/Time.h?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_timer.cpp?cvsroot=gnash&r1=1.16&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/tu_timer.h?cvsroot=gnash&r1=1.11&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/server/SystemClock.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Date.cpp?cvsroot=gnash&r1=1.60&r2=1.61
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.109&r2=1.110
http://cvs.savannah.gnu.org/viewcvs/gnash/utilities/processor.cpp?cvsroot=gnash&r1=1.92&r2=1.93
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/gui.cpp?cvsroot=gnash&r1=1.144&r2=1.145

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6189
retrieving revision 1.6190
diff -u -b -r1.6189 -r1.6190
--- ChangeLog   5 Apr 2008 20:39:38 -0000       1.6189
+++ ChangeLog   6 Apr 2008 17:48:30 -0000       1.6190
@@ -1,3 +1,24 @@
+2008-04-06 Benjamin Wolsey <address@hidden>
+
+       * libbase/tu_timer.{cpp,h}: drop, functions moved to Time.{cpp,h}.
+       * libbase/Time.{cpp,h}: new file to collect all platform- and
+         implementation-dependent clock time code in namespace clocktime.
+         Includes the used functions of tu_timer, timezone detection
+         from Date.cpp and a partial boost date-time implementation of a
+         timer (not enabled by default).
+       * libbase/Makefile.am: add Time, remove tu_timer.
+       * libbase/WallClockTimer.cpp: change from tu_timer to clocktime.
+       * server/SystemClock.cpp: tu_timer -> clocktime.
+       * utilities/processor.cpp: tu_timer -> clocktime.
+       * gui/gui.cpp: tu_timer -> clocktime.
+       * server/asobj/NetStreamFfmpeg.cpp: tu_timer -> clocktime.
+       * server/asobj/Date.cpp: update methods to take account of local
+         timezone. The calculation of timezone, now in Time.cpp, is
+         a bit dubious, but the Date class methods *should* be
+         internally consistent - the timezone may be wrong in some
+         cases, but the relationship between UTC and local time methods
+         is always correctly described in Date.getTimezoneOffset().
+
 2008-04-05  Rob Savoye  <address@hidden>
 
        * libamf/amf.{h,cpp}: Keep track of the total size of data read

Index: libbase/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libbase/Makefile.am,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -b -r1.105 -r1.106
--- libbase/Makefile.am 29 Mar 2008 13:09:47 -0000      1.105
+++ libbase/Makefile.am 6 Apr 2008 17:48:30 -0000       1.106
@@ -89,7 +89,7 @@
        string_table.cpp \
        tu_file.cpp \
        $(SDL_FILE) \
-       tu_timer.cpp \
+       Time.cpp \
        WallClockTimer.cpp \
        utf8.cpp \
        utility.cpp \
@@ -128,7 +128,7 @@
        tu_file.h \
        tu_math.h \
        tu_opengl_includes.h \
-       tu_timer.h \
+       Time.h \
        WallClockTimer.h \
        utf8.h \
        utility.h \

Index: libbase/WallClockTimer.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/WallClockTimer.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libbase/WallClockTimer.cpp  5 Mar 2008 03:55:52 -0000       1.4
+++ libbase/WallClockTimer.cpp  6 Apr 2008 17:48:31 -0000       1.5
@@ -23,32 +23,31 @@
 #endif
 
 #include "WallClockTimer.h"
-
-#include "tu_timer.h" // for "portable" get_ticks (contains implementation for 
win32)
+#include "Time.h" // for "portable" get_ticks (contains implementation for 
win32)
 
 namespace gnash {
 
 WallClockTimer::WallClockTimer()
        :
-       startTimer(tu_timer::get_ticks())
+       startTimer(clocktime::getTicks())
 {
 }
 
 void
 WallClockTimer::restart()
 {
-       startTimer = tu_timer::get_ticks();
+       startTimer = clocktime::getTicks();
 }
 
 boost::uint32_t
 WallClockTimer::elapsed() const
 {
-       boost::uint64_t currTime = tu_timer::get_ticks();
+       boost::uint64_t currTime = clocktime::getTicks();
        
        // be aware of time glitches
        if ( currTime <= startTimer ) return 0;
 
-       return currTime-startTimer;
+       return currTime - startTimer;
 
 }
 

Index: server/SystemClock.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/SystemClock.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- server/SystemClock.cpp      21 Jan 2008 20:55:48 -0000      1.3
+++ server/SystemClock.cpp      6 Apr 2008 17:48:31 -0000       1.4
@@ -23,7 +23,7 @@
 
 #include "SystemClock.h"
 
-#include "tu_timer.h" // for fetchSystemTime
+#include "Time.h" // for fetchSystemTime
 
 #include <boost/cstdint.hpp> // for boost::uint64_t typedef
 
@@ -34,9 +34,8 @@
 boost::uint64_t
 SystemClock::fetchSystemTime() 
 {
-    // TODO: review tu_timer implementation to make sure it
-    //       always return milliseconds
-    return tu_timer::get_ticks();
+    // Time::getTicks always returns milliseconds
+    return clocktime::getTicks();
 }
 
 /* public */

Index: server/asobj/Date.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Date.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -b -r1.60 -r1.61
--- server/asobj/Date.cpp       4 Apr 2008 13:27:27 -0000       1.60
+++ server/asobj/Date.cpp       6 Apr 2008 17:48:31 -0000       1.61
@@ -76,36 +76,15 @@
 #include "GnashException.h"
 #include "builtin_function.h"
 #include "Object.h" // for getObjectInterface
-#include "tu_timer.h"
+#include "Time.h"
 
 #include <ctime>
 #include <cmath>
 #include <boost/format.hpp>
 
-# include <sys/time.h>
-
-// Declaration for replacement timezone functions
-// In the absence of gettimeofday() we use ftime() to get milliseconds,
-// but not for timezone offset because ftime's TZ stuff is unreliable.
-// For that we use tzset()/timezone if it is available.
-
-// The structure of these ifdefs mimics the structure of the code below
-// where these things are used if available.
-
-#if !defined(HAVE_GETTIMEOFDAY) || (!defined(HAVE_TM_GMTOFF) && 
!defined(HAVE_TZSET))
-#ifdef HAVE_FTIME
-extern "C" {
-#  include <sys/types.h>    // for ftime()
-#  include <sys/timeb.h>    // for ftime()
-}
-#endif
-#endif
-
-#if !defined(HAVE_TM_GMTOFF)
-# ifdef HAVE_LONG_TIMEZONE
-extern long timezone;   // for tzset()/long timezone;
-# endif
-#endif
+// All clock time / localtime functions are in libbase/Time.cpp,
+// so that portability problems are all in one place. It saves
+// a lot of rebuilding too.
 
 namespace gnash {
 
@@ -133,9 +112,9 @@
 static double makeTimeValue(GnashTime& gt);
 static void getLocalTime(const double& time, GnashTime& gt);
 static void getUniversalTime(const double& time, GnashTime& gt);
+static int getLocalTimeZoneOffset(const double& time);
 
 static double rogue_date_args(const fn_call& fn, unsigned maxargs);
-static int getLocalTimeZoneOffset();
 
 // Helper macros for calendar algorithms
 #define IS_LEAP_YEAR(n) ( !((n + 1900) % 400) || ( !((n + 1900) % 4) && ((n + 
1900) % 100)) )
@@ -156,8 +135,8 @@
 static void
 getLocalTime(const double& time, GnashTime& gt)
 {
-    // Not yet correct - no time zone.
-    gt.timeZoneOffset = getLocalTimeZoneOffset();
+    // find local timezone offset for the desired time.
+    gt.timeZoneOffset = getLocalTimeZoneOffset(time);
     fillGnashTime(time, gt);
 }
 
@@ -269,7 +248,7 @@
 getDateInterface()
 {
   static boost::intrusive_ptr<as_object> o;
-  if ( o == NULL )
+    if ( !o )
   {
     o = new as_object(getObjectInterface());
     attachDateInterface(*o);
@@ -322,8 +301,8 @@
 
     getLocalTime(value, gt);
 
-    int offsetMinutes = gt.timeZoneOffset / 60;
-    int offsetHours = gt.timeZoneOffset % 60;    
+    int offsetHours = gt.timeZoneOffset / 60;
+    int offsetMinutes = gt.timeZoneOffset % 60;    
   
     // If timezone is negative, both hours and minutes will be negative
     // but for the purpose of printing a string, only the hour needs to
@@ -376,7 +355,7 @@
     // TODO: move this to date_as_object constructor
     if (fn.nargs < 1 || fn.arg(0).is_undefined()) {
         // Set from system clock
-        date->value = tu_timer::get_ticks();
+        date->value = clocktime::getTicks();
     }
     else if (fn.nargs == 1) {
         // Set the value in milliseconds since 1970 UTC
@@ -424,14 +403,12 @@
                 // Done already
             }
 
-            double val = makeTimeValue(gt); // convert from local time
-            if (val == -1) {
-                // mktime could not represent the time
-                log_error(_("Date() failed to initialise from arguments"));
-                date->value = 0;  // or undefined?
-            } else {
-                date->value = val;
-            }
+        // The arguments are in local time: subtract the local time offset
+        // at the desired time to get UTC. This may not be completely correct
+        // due to shortcomings in the timezoneoffset calculation, but should
+        // be internally consistent.
+        double localTime = makeTimeValue(gt);
+        date->value = localTime - clocktime::getTimeZoneOffset(localTime) * 
60000;
     }
     
     return as_value(date);
@@ -523,83 +500,13 @@
 
 
 // Return the difference between UTC and localtime in minutes.
-static int getLocalTimeZoneOffset()
+static int getLocalTimeZoneOffset(const double& time)
 {
     // This simply has to return the difference in minutes
     // between UTC (Greenwich Mean Time, GMT) and the localtime.
     // Obviously, this includes Daylight Saving Time if it applies.
     
-    // Should we get this from tu_timer too.
-
-    return 0;
-#ifdef HAVE_TM_GMTOFF
-  // tm_gmtoff is in seconds east of GMT; convert to minutes.
-//  return((int) (tm.tm_gmtoff / 60));
-    return 0;
-#else
-  // Find the geographical system timezone offset and add an hour if
-  // DST applies to the date.
-  // To get it really right I guess we should call both gmtime()
-  // and localtime() and look at the difference.
-  //
-  // The range of standard time is GMT-11 to GMT+14.
-  // The most extreme with DST is Chatham Island GMT+12:45 +1DST
-
-  int minutes_east;
-
-  // Find out system timezone offset...
-
-#if 0
-
-# if defined(HAVE_TZSET) && defined(HAVE_LONG_TIMEZONE)
-  tzset();
-  minutes_east = -timezone/60; // timezone is seconds west of GMT
-# elif defined(HAVE_GETTIMEOFDAY)
-  // gettimeofday(3):
-  // "The use of the timezone structure is obsolete; the tz argument
-  // should normally be specified as NULL. The tz_dsttime field has
-  // never been used under Linux; it has not been and will not be
-  // supported by libc or glibc."
-  // Still, mancansa d'asu, t'acuma i buoi.
-  struct timeval tv;
-  struct timezone tz;
-  gettimeofday(&tv,&tz);
-  minutes_east = -tz.tz_minuteswest;
-
-# elif defined(HAVE_FTIME)
-  // ftime(3): "These days the contents of the timezone and dstflag
-  // fields are undefined."
-  // In practice, timezone is -120 in Italy when it should be -60.
-  struct timeb tb;
-    
-  ftime (&tb);
-  // tb.timezone is number of minutes west of GMT
-  minutes_east = -tb.timezone;
-
-# else
-  minutes_east = 0; // No idea.
-# endif
-
-  // ...and adjust by one hour if DST was in force at that time.
-  //
-  // According to http://www.timeanddate.com/time/, the only place that
-  // uses DST != +1 hour is Lord Howe Island with half an hour. Tough.
-
-  if (tm.tm_isdst == 0) {
-    // DST exists and is not in effect
-  } else if (tm.tm_isdst > 0) {
-    // DST exists and was in effect
-    minutes_east += 60;
-  } else {
-    // tm_isdst is negative: cannot get TZ info.
-    // Convert and print in UTC instead.
-    log_error("Cannot get timezone information");
-    minutes_east = 0;
-  }
-#endif
-
-  return minutes_east;
-#endif // HAVE_TM_OFFSET
+    return clocktime::getTimeZoneOffset(time);
 }
 
 
@@ -611,7 +518,7 @@
 date_gettimezoneoffset(const fn_call& fn)
 {
     boost::intrusive_ptr<date_as_object> date = 
ensureType<date_as_object>(fn.this_ptr);
-    return as_value( -getLocalTimeZoneOffset() );
+    return as_value( -getLocalTimeZoneOffset(date->value) );
 }
 
 
@@ -668,7 +575,11 @@
 {
     // Needs timezone.
     if (utc) date.value = makeTimeValue(gt);
-    else date.value = makeTimeValue(gt);
+
+    else {
+        double localTime = makeTimeValue(gt);
+        date.value = localTime - clocktime::getTimeZoneOffset(localTime) * 
60000;
+    }
 }
 
 static void

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -b -r1.109 -r1.110
--- server/asobj/NetStreamFfmpeg.cpp    23 Mar 2008 01:20:03 -0000      1.109
+++ server/asobj/NetStreamFfmpeg.cpp    6 Apr 2008 17:48:32 -0000       1.110
@@ -32,7 +32,7 @@
 #include "movie_root.h"
 #include "sound_handler.h"
 #include "VideoDecoderFfmpeg.h"
-#include "tu_timer.h" // TODO: use the VirtualClock instead ?
+#include "Time.h" // TODO: use the VirtualClock instead ?
 
 #include <boost/scoped_array.hpp>
 
@@ -669,7 +669,7 @@
        ns->m_last_audio_timestamp = 0;
        ns->m_current_timestamp = 0;
 
-       ns->m_start_clock = tu_timer::get_ticks();
+       ns->m_start_clock = clocktime::getTicks();
 
        ns->m_unqueued_data = NULL;
 
@@ -1133,7 +1133,7 @@
                m_last_audio_timestamp = 0;
                m_current_timestamp = 0;
 
-               m_start_clock = tu_timer::get_ticks();
+               m_start_clock = clocktime::getTicks();
 
        }
        else if (m_isFLV)
@@ -1215,7 +1215,7 @@
                }
                else
                {
-                       current_clock = tu_timer::get_ticks() - m_start_clock;
+                       current_clock = clocktime::getTicks() - m_start_clock;
                        m_current_timestamp = current_clock;
                }
 
@@ -1318,7 +1318,7 @@
        m_pause = true;
 
        // Save the current time so we later can tell how long the pause lasted
-       m_time_of_pause = tu_timer::get_ticks();
+       m_time_of_pause = clocktime::getTicks();
 }
 
 void NetStreamFfmpeg::unpausePlayback()
@@ -1332,13 +1332,13 @@
 
        if (m_current_timestamp == 0)
        {
-               m_start_clock = tu_timer::get_ticks();
+               m_start_clock = clocktime::getTicks();
        }
        else
        {
                // Add the paused time to the start time so that the playhead 
doesn't
                // noticed that we have been paused
-               m_start_clock += tu_timer::get_ticks() - m_time_of_pause;
+               m_start_clock += clocktime::getTicks() - m_time_of_pause;
        }
 
        // Re-connect to the soundhandler.

Index: utilities/processor.cpp
===================================================================
RCS file: /sources/gnash/gnash/utilities/processor.cpp,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -b -r1.92 -r1.93
--- utilities/processor.cpp     22 Mar 2008 02:36:20 -0000      1.92
+++ utilities/processor.cpp     6 Apr 2008 17:48:32 -0000       1.93
@@ -31,7 +31,7 @@
 #endif
 
 #include "gettext.h"
-#include "tu_file.h"
+#include "Time.h"
 #include "gnash.h"
 #include "movie_definition.h"
 #include "sprite_instance.h"
@@ -44,7 +44,6 @@
 #include "VM.h"
 #include "noseek_fd_adapter.h"
 #include "ManualClock.h"
-#include "tu_timer.h"
 #include "StringPredicates.h"
 
 extern "C"{
@@ -115,15 +114,15 @@
 void
 resetLastAdvanceTimer()
 {
-       using namespace tu_timer;
-       lastAdvanceTimer = ticks_to_seconds(get_ticks());
+    // clocktime::getTicks() returns milliseconds
+       lastAdvanceTimer = static_cast<double>(clocktime::getTicks()) / 1000.0;
 }
 
 double
 secondsSinceLastAdvance()
 {
-       using namespace tu_timer;
-       double now = ticks_to_seconds(get_ticks());
+    // clocktime::getTicks() returns milliseconds
+       double now = static_cast<double>(clocktime::getTicks()) / 1000.0;
        return ( now - lastAdvanceTimer);
 }
 

Index: gui/gui.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/gui.cpp,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -b -r1.144 -r1.145
--- gui/gui.cpp 3 Apr 2008 14:24:02 -0000       1.144
+++ gui/gui.cpp 6 Apr 2008 17:48:32 -0000       1.145
@@ -31,7 +31,7 @@
 #include "VM.h"
 
 #ifdef GNASH_FPS_DEBUG
-#include "tu_timer.h"
+#include "Time.h"
 #endif
 
 #include <cstdio>
@@ -1002,7 +1002,7 @@
          return;
   }
 
-  boost::uint64_t current_timer = tu_timer::get_ticks();
+  boost::uint64_t current_timer = clocktime::get_ticks();
 
   // TODO: keep fps_timer_interval in milliseconds to avoid the multiplication
   //       at each fpsCounterTick call...

Index: libbase/Time.cpp
===================================================================
RCS file: libbase/Time.cpp
diff -N libbase/Time.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libbase/Time.cpp    6 Apr 2008 17:48:30 -0000       1.1
@@ -0,0 +1,292 @@
+// Time.cpp: clock and local time functions for Gnash
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+/// \page
+/// Gnash has three time implementations: one using boost::date_time,
+/// which handles portability itself, one for POSIX systems and one for 
+/// Win32.
+///
+/// Namespace clocktime contains a unified source for wall clock time: this
+/// is used mainly for the timing of movie advances and in the ActionScript
+/// Date class. FPS profiling also uses clocktime:: for a relatively high 
resolution,
+/// robust timer.
+///
+/// The boost::date_time has the great advantage of handling portability 
itself,
+/// as well as being able to handle a much larger range of true dates. Its
+/// disadvantage is that date_time requires not only header files, but also
+/// a run-time library, and thus increases the requirements.
+
+#include "Time.h"
+#include "log.h"
+
+// Define USE_BOOST_DATE_TIME to use boost as the basis for all
+// clock time functions. The function getTimeZoneOffset() is not
+// yet implemented for boost, but will only affect the Date class.
+#undef USE_BOOST_DATE_TIME
+
+#ifdef USE_BOOST_DATE_TIME
+
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/microsec_time_clock.hpp>
+
+using namespace boost::posix_time;
+
+boost::uint64_t
+clocktime::getTicks()
+{
+
+    // Midnight, 1st January 1970: the Epoch.
+    static const posix_time::ptime epoch (from_time_t(0));
+    
+    // Time between now and the Epoch.
+    posix_time::time_duration elapsed = (microsec_clock::local_time() - epoch);
+    
+    // Divisor to convert ticks to milliseconds
+    const int denominator = time_duration::ticks_per_second() / 1000.0;
+    
+       return elapsed.ticks() / denominator;
+}
+
+double
+clocktime::ticksToSeconds(boost::uint64_t ticks)
+{
+       return ticks / 1000.0;
+}
+
+boost::int32_t
+clocktime::getTimeZoneOffset()
+{
+    // Obviously this doesn't work yet. Using this method
+    // may come up against the problem that boost won't handle
+    // dates outside its limits. However, ActionScript seems
+    // not to regard dates later than 2037 as having dst (this
+    // may depend on a machine-specific tz database) and there
+    // could also be a lower limit.
+
+    return 0;
+}
+
+#else // not using boost::date_time
+
+#include <ctime> // for time_t, localtime
+
+#if !defined(HAVE_GETTIMEOFDAY) || (!defined(HAVE_TM_GMTOFF) && 
!defined(HAVE_TZSET))
+#ifdef HAVE_FTIME
+extern "C" {
+#  include <sys/types.h>    // for ftime()
+#  include <sys/timeb.h>    // for ftime()
+}
+#endif
+#endif
+
+#if !defined(HAVE_TM_GMTOFF)
+# ifdef HAVE_LONG_TIMEZONE
+extern long timezone;   // for tzset()/long timezone;
+# endif
+#endif
+
+/// Win32 implementation for getTicks
+# if defined(_WIN32) || defined(WIN32)
+#  include <windows.h>
+#  include <mmsystem.h>
+
+
+boost::uint64_t
+clocktime::getTicks()
+{
+       return timeGetTime();
+}
+
+boost::int32_t
+clocktime::getTimeZoneOffset()
+{
+    return 0;
+}
+
+
+# else // not _WIN32
+#  include <sys/time.h>
+
+boost::uint64_t
+clocktime::getTicks()
+{
+
+       struct timeval tv;
+       
+       gettimeofday(&tv, 0);
+
+       boost::uint64_t result = static_cast<boost::uint64_t>(tv.tv_sec) * 
1000000L;
+
+       // Time Unit: microsecond
+       result += tv.tv_usec;
+
+       return static_cast<boost::uint64_t>(result / 1000.0);
+}
+
+# endif // not WIN32
+
+// Common non-boost conversion of ticks to seconds
+double
+clocktime::ticksToSeconds(boost::uint64_t ticks)
+{
+       return ticks * (1.0f / 1000.f);
+}
+
+/// Common non-boost function to return the present time offset.
+/// This all seems like a terrible hack. It was moved from Date.cpp,
+/// whence the following explanation also comes.
+///
+/// If the real mktime() sees isdst == 0 with a DST date, it sets
+/// t_isdst and modifies the hour fields, but we need to set the
+/// specified hour in the localtime in force at that time.
+///
+/// To do this we set tm_isdst to the correct value for that moment in time
+/// by doing an initial conversion of the time to find out is_dst for that
+/// moment without DST, then do the real conversion.
+/// This may still get things wrong around the hour when the clocks go back
+///
+/// It also gets things wrong for very high or low time values, when the
+/// localtime implementation fills the gmtoff element with 53 minutes (on
+/// at least one machine, anyway).
+boost::int32_t
+clocktime::getTimeZoneOffset(double time)
+{
+    
+    time_t tt = static_cast<time_t>(time / 1000.0);
+
+    struct tm tm;
+
+#ifdef HAVE_LOCALTIME_R
+    localtime_r(&tt, &tm);
+#else
+    struct tm *tmp;
+    tmp = localtime(t);
+    memcpy(tm, tmp, sizeof(struct tm));
+#endif
+
+    struct tm tm2 = tm;
+    tm2.tm_isdst = 0;
+
+    time_t ttmp = 0;
+    
+    ttmp = mktime(&tm2);
+
+    localtime_r(&ttmp, &tm2);  // find out whether DST is in force
+
+    // If mktime or localtime fail, tm2.tm_isdst should be unchanged,
+    // so 0. That's why we don't make any checks on their success.
+
+    tm.tm_isdst = tm2.tm_isdst;
+
+#ifdef HAVE_TM_GMTOFF
+
+    int offset;
+
+    // tm_gmtoff is in seconds east of GMT; convert to minutes.
+    offset = tm.tm_gmtoff / 60;
+    //gnash::log_debug("Using tm.tm_gmtoff. Offset is %d", offset);
+    return offset;
+
+#else
+
+  // Find the geographical system timezone offset and add an hour if
+  // DST applies to the date.
+  // To get it really right I guess we should call both gmtime()
+  // and localtime() and look at the difference.
+  //
+  // The range of standard time is GMT-11 to GMT+14.
+  // The most extreme with DST is Chatham Island GMT+12:45 +1DST
+
+  int offset;
+
+# if defined(HAVE_TZSET) && defined(HAVE_LONG_TIMEZONE)
+
+    tzset();
+    // timezone is seconds west of GMT
+    offset = -timezone / 60;
+    //gnash::log_debug("Using tzset. Offset is %d", offset);
+
+# elif defined(HAVE_GETTIMEOFDAY)
+
+    // gettimeofday(3):
+    // "The use of the timezone structure is obsolete; the tz argument
+    // should normally be specified as NULL. The tz_dsttime field has
+    // never been used under Linux; it has not been and will not be
+    // supported by libc or glibc."
+    // Still, mancansa d'asu, t'acuma i buoi (Mangels Esel, Ochsen 
einspannen...)
+    //
+    // In practice this appears to return the present time offset including 
dst,
+    // so adding the dst of the time specified (we do this a couple of lines 
down)
+    // gives the correct result when it's not presently dst, the wrong one when
+    // it is.
+    struct timeval tv;
+    struct timezone tz;
+    gettimeofday(&tv, &tz);
+    offset = -tz.tz_minuteswest;
+    //gnash::log_debug("Using gettimeofday. Offset is %d", offset);
+
+# elif defined(HAVE_FTIME)
+    // ftime(3): "These days the contents of the timezone and dstflag
+    // fields are undefined."
+    // In practice, timezone is -120 in Italy when it should be -60.
+    // The problem here as for gettimeofday: the offset also includes dst.
+    struct timeb tb;
+    
+    ftime (&tb);
+    // tb.timezone is number of minutes west of GMT
+    offset = -tb.timezone;
+    //gnash::log_debug("Using ftime. Offset is %d", offset);
+
+# else
+
+    offset = 0; // No idea.
+    //gnash::log_debug("Cannot find offset. Offset is %d", offset);
+
+# endif
+
+  // Adjust by one hour if DST was in force at that time.
+  //
+  // According to http://www.timeanddate.com/time/, the only place that
+  // uses DST != +1 hour is Lord Howe Island with half an hour. Tough.
+
+    if (tm.tm_isdst == 0) {
+        // DST exists and is not in effect
+    }
+    else if (tm.tm_isdst > 0) {
+        // DST exists and was in effect
+        offset += 60;
+    }
+    else {
+        // tm_isdst is negative: cannot get TZ info.
+        // Convert and print in UTC instead.
+        static bool warned = false;
+        if (!warned) {
+            gnash::log_error(_("Cannot get requested timezone information"));
+            warned = true;
+        }
+        offset = 0;
+    }
+
+    return offset;
+
+#endif // No gmoff
+}
+
+
+
+#endif // Not using boost::date_time

Index: libbase/Time.h
===================================================================
RCS file: libbase/Time.h
diff -N libbase/Time.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ libbase/Time.h      6 Apr 2008 17:48:31 -0000       1.1
@@ -0,0 +1,44 @@
+// Time.h: clock and local time functions for Gnash
+// 
+//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+// 
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef GNASH_TIME_H
+#define GNASH_TIME_H
+
+#include <boost/cstdint.hpp>
+#include "dsodefs.h"
+
+namespace clocktime
+{
+    /// Wall clock timer, uses highest available resolution.
+    /// Generally microseconds on Linux / Unix, microseconds with
+    /// millisecond resolution on Windows. Nanosecond resolution is
+    /// theoretically available.
+       DSOEXPORT boost::uint64_t getTicks();
+
+       /// Converts ticks to seconds.
+       DSOEXPORT double ticksToSeconds(boost::uint64_t ticks);
+
+       /// Returns the offset between actual clock time and UTC.
+       /// It relies on the system's time zone settings, so
+       /// cannot be regarded as reliable.
+       DSOEXPORT boost::int32_t getTimeZoneOffset(double time);
+
+}
+
+#endif

Index: libbase/tu_timer.cpp
===================================================================
RCS file: libbase/tu_timer.cpp
diff -N libbase/tu_timer.cpp
--- libbase/tu_timer.cpp        4 Apr 2008 11:43:13 -0000       1.16
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,67 +0,0 @@
-// tu_timer.cpp        -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain.  Do
-// whatever you want with it.
-
-// Utility/profiling timer.
-
-
-#include "tu_timer.h"
-
-
-#if defined(_WIN32) || defined(WIN32)
-
-#include <windows.h>
-#include <mmsystem.h>
-
-
-boost::uint64_t tu_timer::get_ticks()
-{
-       return timeGetTime();
-}
-
-
-double tu_timer::ticks_to_seconds(boost::uint64_t ticks)
-{
-       return ticks * (1.0f / 1000.f);
-}
-
-#else  // not _WIN32
-
-
-#include <sys/time.h>
-
-
-// The profile ticks implementation is just fine for a normal timer.
-
-
-boost::uint64_t tu_timer::get_ticks()
-{
-
-       struct timeval tv;
-       
-       gettimeofday(&tv, 0);
-
-       boost::uint64_t result = static_cast<boost::uint64_t>(tv.tv_sec) * 
1000000L;
-
-       result += tv.tv_usec;
-       // Time Unit: microsecond
-
-       return static_cast<boost::uint64_t>(result / 1000.0);
-}
-
-
-double tu_timer::ticks_to_seconds(boost::uint64_t ticks)
-{
-       return ticks / 1000000.0;
-}
-
-#endif // not _WIN32
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8 
-// tab-width: 8
-// indent-tabs-mode: t
-// End:

Index: libbase/tu_timer.h
===================================================================
RCS file: libbase/tu_timer.h
diff -N libbase/tu_timer.h
--- libbase/tu_timer.h  4 Apr 2008 11:43:13 -0000       1.11
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,36 +0,0 @@
-// tu_timer.h  -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain.  Do
-// whatever you want with it.
-
-// Utility/profiling timer.
-
-
-#ifndef TU_TIMER_H
-
-#include "dsodefs.h" // DSOEXPORT
-
-#include <boost/cstdint.hpp> // for C99 int types 
-
-
-namespace tu_timer
-{
-       // General-purpose wall-clock timer.  May not be hi-res enough
-       // for profiling. Time Unit: millisecond
-       DSOEXPORT boost::uint64_t get_ticks();
-
-       // Time Unit: second
-       DSOEXPORT double ticks_to_seconds(boost::uint64_t ticks);
-       
-}
-
-
-#endif // TU_TIMER_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8 
-// tab-width: 8
-// indent-tabs-mode: t
-// End:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]