[PATCH 4 of 4] Add dummy logging with ressourced messages

Wald Commits scm-commit at wald.intevation.org
Thu Jun 19 17:48:20 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1403192890 -7200
# Node ID bc02ee484067b4bcad83c5b39f7352aad3c967e2
# Parent  e780405f815062983da00c93a85e0be9df294cab
Add dummy logging with ressourced messages.

    The hack in icon.rc is necessary as with mingw 3.0 there appears
    to be a problem to include multiple resources after another.
    The data is included but the sections are not detected correctly
    in windows. Combining them in a single resource fixes this.

diff -r e780405f8150 -r bc02ee484067 common/events.mc
--- a/common/events.mc	Thu Jun 19 17:45:06 2014 +0200
+++ b/common/events.mc	Thu Jun 19 17:48:10 2014 +0200
@@ -5,7 +5,6 @@
 ; and comes with ABSOLUTELY NO WARRANTY!
 ; See LICENSE.txt for details. */
 
-MessageIdTypedef=DWORD
 
 SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
 Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
@@ -13,18 +12,66 @@
 Error=0x3:STATUS_SEVERITY_ERROR
 )
 
+FacilityNames=(System=0x0:FACILITY_SYSTEM
+               Runtime=0x2:FACILITY_RUNTIME
+               Stubs=0x3:FACILITY_STUBS
+               Io=0x4:FACILITY_IO_ERROR_CODE
+              )
+
 LanguageNames=(English=0x409:MSG00409)
 LanguageNames=(German=0x407:MSG00407)
 
+MessageIdTypedef=WORD
+
+MessageId=0x1
+SymbolicName=EVENT_CAT_TB
+Language=English
+Trustbridge
+.
+Language=German
+Trustbridge
+.
+
+MessageId=0x2
+SymbolicName=EVENT_CAT_CINST
+Language=English
+Certificate Installer2
+.
+Language=German
+Zertifikatsinstaller
+.
+
+
+MessageId=0x3
+SymbolicName=EVENT_CAT_NSS
+Language=English
+NSS
+.
+Language=German
+NSS
+.
 ;/* THE MESSAGES */
 
-MessageId=0x1
+MessageIdTypedef=DWORD
+
+MessageId=0x100
 Severity=Informational
-Facility=Application
+Facility=Runtime
 SymbolicName=MSG_DEFAULT_INFO
 Language=English
-Test %0 blub
+Test blub
 .
 Language=German
 Schlaand Schlaand %0 blubs
 .
+
+MessageId=0x101
+Severity=Error
+Facility=Runtime
+SymbolicName=MSG_DEFAULT_ERROR
+Language=English
+Test Error  blub
+.
+Language=German
+Schlaand Schlaand %0 ERROR  blubs
+.
diff -r e780405f8150 -r bc02ee484067 common/logging.c
--- a/common/logging.c	Thu Jun 19 17:45:06 2014 +0200
+++ b/common/logging.c	Thu Jun 19 17:48:10 2014 +0200
@@ -16,6 +16,7 @@
 
 #ifdef WIN32
 # include <windows.h>
+# include "events.h"
 #else
 # include <syslog.h>
 #endif
@@ -28,9 +29,7 @@
   HANDLE log_src = NULL,
          process_token = NULL;
   wchar_t *wmsg = NULL;
-  BOOL failure = TRUE;
-  WORD type = 0,
-       category = 0;
+  BOOL success = FALSE;
   char buffer[MAX_LOG+1];
   PTOKEN_USER user_struct = NULL;
   PSID user_sid = NULL;
@@ -38,7 +37,7 @@
   vsnprintf (buffer, MAX_LOG, format, ap);
   buffer[MAX_LOG] = '\0';
 
-  log_src = RegisterEventSourceA (NULL, LOG_NAME);
+  log_src = RegisterEventSourceW (NULL, L"" LOG_NAME);
 
   if (log_src == NULL)
     {
@@ -46,15 +45,6 @@
       return;
     }
 
-  if (error)
-    {
-      type = EVENTLOG_ERROR_TYPE;
-    }
-  else
-    {
-      type = EVENTLOG_INFORMATION_TYPE;
-    }
-
   wmsg = utf8_to_wchar (buffer, strlen(buffer));
   if (wmsg == NULL)
     {
@@ -80,16 +70,16 @@
     }
 
 
-  failure = ReportEventW (log_src,
-                          type,
-                          category,
-                          0,
+  success = ReportEventW (log_src,
+                          error ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
+                          EVENT_CAT_TB,
+                          error ? MSG_DEFAULT_ERROR : MSG_DEFAULT_INFO,
                           user_sid,
                           1,
                           0,
                           (const WCHAR **) &wmsg,
                           NULL);
-  if (failure)
+  if (!success)
     {
       PRINTLASTERROR ("Failed to report event.");
     }
diff -r e780405f8150 -r bc02ee484067 ui/CMakeLists.txt
--- a/ui/CMakeLists.txt	Thu Jun 19 17:45:06 2014 +0200
+++ b/ui/CMakeLists.txt	Thu Jun 19 17:48:10 2014 +0200
@@ -109,7 +109,7 @@
 # Adding resources here in an extra variable to enable reuse of
 # TRUSTBRIDGE_SOURCES in the test subdirectory.
 set(TRUSTBRIDGE_MAIN_WITH_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/img/icon.rc)
+   ${CMAKE_CURRENT_SOURCE_DIR}/img/icon.rc)
 qt5_add_resources(TRUSTBRIDGE_MAIN_WITH_RESOURCES ${TRUSTBRIDGE_RESOURCES})
 
 set(ADMINISTRATOR_MAIN_WITH_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/administrator.cpp)
@@ -133,10 +133,9 @@
               ${CMAKE_BINARY_DIR}/common/events.rc
               ${CMAKE_BINARY_DIR}/common/MSG00407.bin
               ${CMAKE_BINARY_DIR}/common/MSG00409.bin
-       COMMAND ${MC_COMPILER} ${CMAKE_SOURCE_DIR}/common/events.mc -r ${CMAKE_BINARY_DIR}/common -h ${CMAKE_BINARY_DIR}/common
+       COMMAND ${MC_COMPILER} ${CMAKE_SOURCE_DIR}/common/events.mc -a -U -r ${CMAKE_BINARY_DIR}/common -h ${CMAKE_BINARY_DIR}/common
        DEPENDS ${CMAKE_SOURCE_DIR}/common/events.mc)
-   set(EXTRA_SOURCES ${CMAKE_BINARY_DIR}/common/events.h)
-   set(TRUSTBRIDGE_MAIN_WITH_RESOURCES ${TRUSTBRIDGE_MAIN_WITH_RESOURCES} ${CMAKE_BINARY_DIR}/common/events.rc)
+    add_custom_target(create_events DEPENDS ${CMAKE_BINARY_DIR}/common/events.rc)
 endif()
 
 if(Qt5LinguistTools_FOUND)
@@ -176,6 +175,10 @@
       ${TRUSTBRIDGE_MAIN_WITH_RESOURCES})
 endif()
 
+if (WIN32)
+   add_dependencies(trustbridge create_events)
+endif()
+
 add_library(ui_common STATIC ${UICOMMON_SOURCES})
 add_library(tbadminlib STATIC ${ADMINISTRATOR_SOURCES})
 add_library(tblib STATIC ${TRUSTBRIDGE_SOURCES})
diff -r e780405f8150 -r bc02ee484067 ui/img/icon.rc
--- a/ui/img/icon.rc	Thu Jun 19 17:45:06 2014 +0200
+++ b/ui/img/icon.rc	Thu Jun 19 17:48:10 2014 +0200
@@ -1,1 +1,2 @@
+#include "events.rc"
 IDI_ICON1               ICON    DISCARDABLE     "icon.ico"


More information about the Trustbridge-commits mailing list