Browse Source

extensions to notify

David Rose 23 years ago
parent
commit
f5e5fcf8e2

+ 0 - 1
dtool/src/dconfig/notify.cxx

@@ -23,7 +23,6 @@
 #include <filename.h>
 #include <filename.h>
 
 
 #include <ctype.h>
 #include <ctype.h>
-#include <time.h>  // for strftime().
 
 
 #ifdef WIN32
 #ifdef WIN32
 #include <windows.h>   //for DebugBreak()
 #include <windows.h>   //for DebugBreak()

+ 21 - 5
dtool/src/dconfig/notifyCategory.cxx

@@ -20,11 +20,14 @@
 #include "notify.h"
 #include "notify.h"
 #include "config_notify.h"
 #include "config_notify.h"
 
 
+#include <time.h>  // for strftime().
 #include <assert.h>
 #include <assert.h>
 
 
+time_t NotifyCategory::_server_delta = 0;
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NotifyCategory::Constructor
 //     Function: NotifyCategory::Constructor
-//       Access: Public
+//       Access: Private
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 NotifyCategory::
 NotifyCategory::
@@ -86,7 +89,7 @@ NotifyCategory(const string &fullname, const string &basename,
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NotifyCategory::out
 //     Function: NotifyCategory::out
-//       Access: Public
+//       Access: Published
 //  Description: Begins a new message to this Category at the
 //  Description: Begins a new message to this Category at the
 //               indicated severity level.  If the indicated severity
 //               indicated severity level.  If the indicated severity
 //               level is enabled, this writes a prefixing string to
 //               level is enabled, this writes a prefixing string to
@@ -100,7 +103,7 @@ out(NotifySeverity severity, bool prefix) const {
     if (prefix) {
     if (prefix) {
       if (get_notify_timestamp()) {
       if (get_notify_timestamp()) {
         // Format a timestamp to include as a prefix as well.
         // Format a timestamp to include as a prefix as well.
-        time_t now = time(NULL);
+        time_t now = time(NULL) + _server_delta;
         struct tm *ptm = localtime(&now);
         struct tm *ptm = localtime(&now);
 
 
         char buffer[128];
         char buffer[128];
@@ -123,7 +126,7 @@ out(NotifySeverity severity, bool prefix) const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NotifyCategory::get_num_children
 //     Function: NotifyCategory::get_num_children
-//       Access: Public
+//       Access: Published
 //  Description: Returns the number of child Categories of this
 //  Description: Returns the number of child Categories of this
 //               particular Category.
 //               particular Category.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -134,7 +137,7 @@ get_num_children() const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: NotifyCategory::get_child
 //     Function: NotifyCategory::get_child
-//       Access: Public
+//       Access: Published
 //  Description: Returns the nth child Category of this particular
 //  Description: Returns the nth child Category of this particular
 //               Category.
 //               Category.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -143,3 +146,16 @@ get_child(int i) const {
   assert(i >= 0 && i < (int)_children.size());
   assert(i >= 0 && i < (int)_children.size());
   return _children[i];
   return _children[i];
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: NotifyCategory::set_server_delta
+//       Access: Published, Static
+//  Description: Sets a global delta (in seconds) between the local
+//               time and the server's time, for the purpose of
+//               synchronizing the time stamps in the log messages of
+//               the client with that of a known server.
+////////////////////////////////////////////////////////////////////
+void NotifyCategory::
+set_server_delta(time_t delta) {
+  _server_delta = delta;
+}

+ 4 - 0
dtool/src/dconfig/notifyCategory.h

@@ -76,6 +76,8 @@ PUBLISHED:
   int get_num_children() const;
   int get_num_children() const;
   NotifyCategory *get_child(int i) const;
   NotifyCategory *get_child(int i) const;
 
 
+  static void set_server_delta(time_t delta);
+
 private:
 private:
   string _fullname;
   string _fullname;
   string _basename;
   string _basename;
@@ -84,6 +86,8 @@ private:
   typedef vector<NotifyCategory *> Children;
   typedef vector<NotifyCategory *> Children;
   Children _children;
   Children _children;
 
 
+  static time_t _server_delta;
+
   friend class Notify;
   friend class Notify;
 };
 };