Author: cazfi
Date: Sun Feb 28 13:12:57 2016
New Revision: 32112

URL: http://svn.gna.org/viewcvs/freeciv?rev=32112&view=rev
Log:
Server sends deprecation warning events to client

See patch #7013

Modified:
    trunk/client/client_main.c
    trunk/server/console.c
    trunk/server/ruleset.c
    trunk/utility/deprecations.c
    trunk/utility/deprecations.h
    trunk/utility/log.c
    trunk/utility/log.h

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Sun Feb 28 13:12:57 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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

Modified: trunk/server/console.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/console.c?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/server/console.c      (original)
+++ trunk/server/console.c      Sun Feb 28 13:12:57 2016
@@ -24,6 +24,7 @@
 #endif
 
 /* utility */
+#include "deprecations.h"
 #include "fcbacktrace.h"
 #include "fciconv.h"
 #include "fcintl.h"
@@ -133,6 +134,14 @@
 #endif /* DEBUG */
 
 /************************************************************************
+  Deprecation warning callback to send event to clients.
+************************************************************************/
+static void depr_warn_callback(const char *msg)
+{
+  notify_conn(NULL, NULL, E_DEPRECATION_WARNING, ftc_warning, "%s", msg);
+}
+
+/************************************************************************
   Initialize logging via console.
 ************************************************************************/
 void con_log_init(const char *log_filename, enum log_level level,
@@ -146,6 +155,7 @@
            fatal_assertions);
 #endif /* DEBUG */
   backtrace_init();
+  deprecation_warn_cb_set(depr_warn_callback);
 }
 
 /************************************************************************

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Sun Feb 28 13:12:57 2016
@@ -201,9 +201,10 @@
                         const char *format, ...)
 {
   va_list args;
+  char buf[1024];
 
   va_start(args, format);
-  vdo_log(file, function, line, FALSE, level, format, args);
+  vdo_log(file, function, line, FALSE, level, buf, sizeof(buf), format, args);
   va_end(args);
 
   if (LOG_FATAL >= level) {

Modified: trunk/utility/deprecations.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/deprecations.c?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/utility/deprecations.c        (original)
+++ trunk/utility/deprecations.c        Sun Feb 28 13:12:57 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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
@@ -23,6 +23,8 @@
 
 #include "deprecations.h"
 
+static deprecation_warn_callback depr_cb = NULL;
+
 static bool depr_warns_enabled = FALSE;
 
 /************************************************************************
@@ -40,3 +42,28 @@
 {
   return depr_warns_enabled;
 }
+
+/************************************************************************
+  Set callback to call when deprecation warnings are issued
+************************************************************************/
+void deprecation_warn_cb_set(deprecation_warn_callback new_cb)
+{
+  depr_cb = new_cb;
+}
+
+/************************************************************************
+  Log the deprecation warning
+************************************************************************/
+void do_log_deprecation(const char *format, ...)
+{
+  va_list args;
+  char buf[1024];
+
+  va_start(args, format);
+  vdo_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, LOG_DEPRECATION,
+          buf, sizeof(buf), format, args);
+  if (depr_cb != NULL) {
+    depr_cb(buf);
+  }
+  va_end(args);
+}

Modified: trunk/utility/deprecations.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/deprecations.h?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/utility/deprecations.h        (original)
+++ trunk/utility/deprecations.h        Sun Feb 28 13:12:57 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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
@@ -21,29 +21,34 @@
 /* utility */
 #include "log.h"
 
+typedef void (*deprecation_warn_callback)(const char *msg);
+
 #define LOG_DEPRECATION LOG_NORMAL
 
+void deprecation_warn_cb_set(deprecation_warn_callback new_cb);
 void deprecation_warnings_enable(void);
 bool are_deprecation_warnings_enabled(void);
+
+void do_log_deprecation(const char *format, ...);
 
 #define log_deprecation(message, ...) \
   do { \
     if (are_deprecation_warnings_enabled()) { \
-      log_base(LOG_DEPRECATION, message, ## __VA_ARGS__); \
+      do_log_deprecation(message, ## __VA_ARGS__); \
     } \
   } while (FALSE);
 
 #define log_deprecation_alt(altlvl, message, ...) \
   do { \
     if (are_deprecation_warnings_enabled()) { \
-      log_base(LOG_DEPRECATION, message, ## __VA_ARGS__); \
+      do_log_deprecation(message, ## __VA_ARGS__); \
     } else { \
       log_base(altlvl, message, ## __VA_ARGS__); \
     } \
   } while (FALSE);
 
 #define log_deprecation_always(message, ...) \
-  log_base(LOG_DEPRECATION, message, ## __VA_ARGS__);
+  do_log_deprecation(message, ## __VA_ARGS__);
 
 #ifdef __cplusplus
 }

Modified: trunk/utility/log.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/log.c?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/utility/log.c (original)
+++ trunk/utility/log.c Sun Feb 28 13:12:57 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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
@@ -385,23 +385,22 @@
 *****************************************************************************/
 void vdo_log(const char *file, const char *function, int line,
              bool print_from_where, enum log_level level,
-             const char *message, va_list args)
+             char *buf, int buflen, const char *message, va_list args)
 {
   char buf_where[MAX_LEN_LOG_LINE];
-  char buf_msg[MAX_LEN_LOG_LINE];
 
   /* There used to be check against recursive logging here, but
    * the way it worked prevented any kind of simultaneous logging,
    * not just recursive. Multiple threads should be able to log
    * simultaneously. */
 
-  fc_vsnprintf(buf_msg, sizeof(buf_msg), message, args);
+  fc_vsnprintf(buf, buflen, message, args);
   fc_snprintf(buf_where, sizeof(buf_where), "in %s() [%s::%d]: ",
               function, file, line);
 
   /* In the default configuration log_pre_callback is equal to log_real(). */
   if (log_pre_callback) {
-    log_pre_callback(level, print_from_where, buf_where, buf_msg);
+    log_pre_callback(level, print_from_where, buf_where, buf);
   }
 }
 
@@ -498,10 +497,12 @@
             bool print_from_where, enum log_level level,
             const char *message, ...)
 {
+  char buf[MAX_LEN_LOG_LINE];
   va_list args;
 
   va_start(args, message);
-  vdo_log(file, function, line, print_from_where, level, message, args);
+  vdo_log(file, function, line, print_from_where, level,
+          buf, MAX_LEN_LOG_LINE, message, args);
   va_end(args);
 }
 
@@ -531,10 +532,12 @@
 
   if (NULL != message && NOLOGMSG != message) {
     /* Additional message. */
+    char buf[MAX_LEN_LOG_LINE];
     va_list args;
 
     va_start(args, message);
-    vdo_log(file, function, line, FALSE, level, message, args);
+    vdo_log(file, function, line, FALSE, level, buf, MAX_LEN_LOG_LINE,
+            message, args);
     va_end(args);
   }
 

Modified: trunk/utility/log.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/log.h?rev=32112&r1=32111&r2=32112&view=diff
==============================================================================
--- trunk/utility/log.h (original)
+++ trunk/utility/log.h Sun Feb 28 13:12:57 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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
@@ -71,7 +71,7 @@
 
 void vdo_log(const char *file, const char *function, int line,
              bool print_from_where, enum log_level level,
-             const char *message, va_list args);
+             char *buf, int buflen, const char *message, va_list args);
 void do_log(const char *file, const char *function, int line,
             bool print_from_where, enum log_level level,
             const char *message, ...)
@@ -120,8 +120,9 @@
 
 #define log_va_list(level, msg, args)                                       \
   if (log_do_output_for_level(level)) {                                     \
+    char __buf_[1024];                                                      \
     vdo_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE,                     \
-            level, msg, args);                                              \
+            level, __buf_, sizeof(__buf_), msg, args);                      \
   }
 
 /* Used by game debug command */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to