From fc5fc02c3f44fff3d8fddf67a8fc61b432fb738d Mon Sep 17 00:00:00 2001 From: "Neo][" Date: Fri, 4 Mar 2016 16:03:00 +0500 Subject: [PATCH 1/2] Adding new kind of action which is performed in response to the error. The BTA_CUSTOM allows to specify custom handler that called at processing BugTrap action. --- source/Client/BugTrap.cpp | 18 ++++++++++++++++++ source/Client/BugTrap.h | 27 ++++++++++++++++++++++++++- source/Client/BugTrapUI.cpp | 5 +++++ source/Client/Globals.cpp | 5 +++++ source/Client/Globals.h | 5 +++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/source/Client/BugTrap.cpp b/source/Client/BugTrap.cpp index fb96d1a..782df47 100644 --- a/source/Client/BugTrap.cpp +++ b/source/Client/BugTrap.cpp @@ -936,6 +936,24 @@ extern "C" BUGTRAP_API BT_ErrHandler APIENTRY BT_GetPostErrHandler(void) return g_pfnPostErrHandler; } +/** +* @return address of custom activity handler called at processing BugTrap action. +*/ +extern "C" BUGTRAP_API BT_CustomActivityHandler APIENTRY BT_GetCustomActivityHandler(void) +{ + return g_pfnCustomActivityHandler; +} + +/** +* @param pfnCustomActivityHandler - address of custom activity handler called at processing BugTrap action. +* @param nCustomActivityHandlerParam - user-defined parameter of custom activity handler called at processing BugTrap action. +*/ +extern "C" BUGTRAP_API void APIENTRY BT_SetCustomActivityHandler(BT_CustomActivityHandler pfnCustomActivityHandler, INT_PTR nCustomActivityHandlerParam) +{ + g_pfnCustomActivityHandler = pfnCustomActivityHandler; + g_nCustomActivityHandlerParam = nCustomActivityHandlerParam; +} + /** * @param pfnPostErrHandler - address of error handler called after BugTrap dialog. * @param nPostErrHandlerParam - user-defined parameter of error handler called after BugTrap dialog. diff --git a/source/Client/BugTrap.h b/source/Client/BugTrap.h index 3608a9a..1fff3ea 100644 --- a/source/Client/BugTrap.h +++ b/source/Client/BugTrap.h @@ -66,7 +66,11 @@ typedef enum BUGTRAP_ACTIVITY_tag /** * @brief Automatically send bug report to support server. */ - BTA_SENDREPORT = 4 + BTA_SENDREPORT = 4, + /** + * @brief Call custom handler specified by BT_SetCustomActivityHandler(). + */ + BTA_CUSTOM = 5, } BUGTRAP_ACTIVITY; @@ -365,6 +369,11 @@ BUGTRAP_REGEXPORTENTRY; */ typedef void (CALLBACK * BT_ErrHandler)(INT_PTR nErrHandlerParam); +/** +* @brief Type definition of user-defined activity handler. +*/ +typedef void (CALLBACK * BT_CustomActivityHandler)(LPCTSTR pszReportFilePath, INT_PTR nCustomActivityHandlerParam); + /** @} */ /** @@ -648,6 +657,22 @@ BUGTRAP_API void APIENTRY BT_SetPostErrHandler(BT_ErrHandler pfnPostErrHandler, /** @} */ +/** +* @defgroup CustomActivityHandlers Custom activity handlers +* @{ +*/ + +/** +* @brief Get address of custom activity handler called at processing BugTrap action. +*/ +BUGTRAP_API BT_CustomActivityHandler APIENTRY BT_GetCustomActivityHandler(void); +/** +* @brief Set address of custom activity handler called at processing BugTrap action. +*/ +BUGTRAP_API void APIENTRY BT_SetCustomActivityHandler(BT_CustomActivityHandler pfnCustomActivityHandler, INT_PTR nCustomActivityHandlerParam); + +/** @} */ + /** * @defgroup TracingFunc Tracing functions * @{ diff --git a/source/Client/BugTrapUI.cpp b/source/Client/BugTrapUI.cpp index b8f8f7a..7daa75e 100644 --- a/source/Client/BugTrapUI.cpp +++ b/source/Client/BugTrapUI.cpp @@ -1358,6 +1358,11 @@ static void ExecuteHandlerAction(void) DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, MainDlgProc); } break; + case BTA_CUSTOM: + if (g_pfnCustomActivityHandler != NULL) + (*g_pfnCustomActivityHandler)(g_szInternalReportFilePath, g_nCustomActivityHandlerParam); + + break; } } // Remove temporarily generated report files. diff --git a/source/Client/Globals.cpp b/source/Client/Globals.cpp index 7dbb03b..20de01f 100644 --- a/source/Client/Globals.cpp +++ b/source/Client/Globals.cpp @@ -84,3 +84,8 @@ CStrHolder g_strUserMessage; CStrHolder g_strFirstIntroMesage; /// 2nd introduction message displayed on the dialog. CStrHolder g_strSecondIntroMesage; + +/// Address of custom activity handler called at processing BugTrap action. +extern BT_CustomActivityHandler g_pfnCustomActivityHandler = NULL; +/// User-defined parameter of custom activity handler. +extern INT_PTR g_nCustomActivityHandlerParam = 0; diff --git a/source/Client/Globals.h b/source/Client/Globals.h index 397ceb2..fb75053 100644 --- a/source/Client/Globals.h +++ b/source/Client/Globals.h @@ -116,3 +116,8 @@ extern CStrHolder g_strUserMessage; extern CStrHolder g_strFirstIntroMesage; /// 2nd introduction message displayed on the dialog. extern CStrHolder g_strSecondIntroMesage; + +/// Address of custom activity handler called at processing BugTrap action. +extern BT_CustomActivityHandler g_pfnCustomActivityHandler; +/// User-defined parameter of custom activity handler. +extern INT_PTR g_nCustomActivityHandlerParam; From 4e0e270da94f9aeedddd46e65d4a0d080a760fc2 Mon Sep 17 00:00:00 2001 From: "Neo][" Date: Sat, 5 Mar 2016 01:22:43 +0500 Subject: [PATCH 2/2] Adding new kind of action which is performed in response to the error(for managed version). The ActivityType.Custom allows to specify custom handler that called at processing BugTrap action --- source/Client/BugTrapNet.h | 29 +++++++++++++++++++++++++++-- source/Client/BugTrapUI.cpp | 12 ++++++++++-- source/Client/NetThunks.cpp | 12 ++++++++++++ source/Client/NetThunks.h | 2 ++ 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/source/Client/BugTrapNet.h b/source/Client/BugTrapNet.h index b72aac0..5bb2dbf 100644 --- a/source/Client/BugTrapNet.h +++ b/source/Client/BugTrapNet.h @@ -47,7 +47,8 @@ namespace IntelleSoft ShowUI = BTA_SHOWUI, SaveReport = BTA_SAVEREPORT, MailReport = BTA_MAILREPORT, - SendReport = BTA_SENDREPORT + SendReport = BTA_SENDREPORT, + Custom = BTA_CUSTOM }; [Flags] @@ -373,6 +374,8 @@ namespace IntelleSoft public delegate void UnhandledExceptionDelegate(Object^ sender, UnhandledExceptionEventArgs^ args); + public delegate void CustomActivityDelegate(Object^ sender, String^ reportFilePath); + public ref class ExceptionHandler { private: @@ -391,6 +394,7 @@ namespace IntelleSoft static void ValidateIoResult(BOOL bResult); + static event CustomActivityDelegate^ customActivityEvent; internal: static property System::Exception^ Exception { @@ -418,7 +422,7 @@ namespace IntelleSoft static void FireBeforeUnhandledExceptionEvent(void); static void FireAfterUnhandledExceptionEvent(void); - + static void FireCustomActivityEvent(String^ reportFilePath); public: static const int HttpPort = BUGTRAP_HTTP_PORT; @@ -434,6 +438,12 @@ namespace IntelleSoft void remove(UnhandledExceptionDelegate^ value); } + static event CustomActivityDelegate^ CustomActivity + { + void add(CustomActivityDelegate^ value); + void remove(CustomActivityDelegate^ value); + } + static property String^ AppName { String^ get(void); @@ -596,6 +606,11 @@ namespace IntelleSoft afterUnhandledExceptionEvent(Sender, Arguments); } + inline void ExceptionHandler::FireCustomActivityEvent(String^ reportFilePath) + { + customActivityEvent(Sender, reportFilePath); + } + inline void ExceptionHandler::BeforeUnhandledException::add(UnhandledExceptionDelegate^ value) { beforeUnhandledExceptionEvent += value; @@ -616,6 +631,16 @@ namespace IntelleSoft afterUnhandledExceptionEvent -= value; } + inline void ExceptionHandler::CustomActivity::add(CustomActivityDelegate^ value) + { + customActivityEvent += value; + } + + inline void ExceptionHandler::CustomActivity::remove(CustomActivityDelegate^ value) + { + customActivityEvent -= value; + } + inline String^ ExceptionHandler::AppName::get(void) { return gcnew String(BT_GetAppName()); diff --git a/source/Client/BugTrapUI.cpp b/source/Client/BugTrapUI.cpp index 7daa75e..756bcc3 100644 --- a/source/Client/BugTrapUI.cpp +++ b/source/Client/BugTrapUI.cpp @@ -28,6 +28,10 @@ #include "MemStream.h" #include "VersionInfoString.h" +#ifdef _MANAGED +#include "NetThunks.h" +#endif + #ifdef _DEBUG #define new DEBUG_NEW #endif @@ -1359,8 +1363,12 @@ static void ExecuteHandlerAction(void) } break; case BTA_CUSTOM: - if (g_pfnCustomActivityHandler != NULL) - (*g_pfnCustomActivityHandler)(g_szInternalReportFilePath, g_nCustomActivityHandlerParam); +#ifdef _MANAGED + NetThunks::FireCustomActivityEvent(g_szInternalReportFilePath); +#else + if (g_pfnCustomActivityHandler != NULL) + (*g_pfnCustomActivityHandler)(g_szInternalReportFilePath, g_nCustomActivityHandlerParam); +#endif // _MANAGED break; } diff --git a/source/Client/NetThunks.cpp b/source/Client/NetThunks.cpp index 082f666..3dc69f3 100644 --- a/source/Client/NetThunks.cpp +++ b/source/Client/NetThunks.cpp @@ -504,6 +504,18 @@ namespace NetThunks } } + void FireCustomActivityEvent(LPCTSTR pszReportFilePath) + { + try + { + ExceptionHandler::FireCustomActivityEvent(gcnew String(pszReportFilePath)); + } + catch (Exception^ exception) + { + Debug::WriteLine(exception); + } + } + void FlushTraceListeners(void) { try diff --git a/source/Client/NetThunks.h b/source/Client/NetThunks.h index 4170959..acb81fc 100644 --- a/source/Client/NetThunks.h +++ b/source/Client/NetThunks.h @@ -146,6 +146,8 @@ namespace NetThunks void FireAfterUnhandledExceptionEvent(void); + void FireCustomActivityEvent(LPCTSTR pszReportFilePath); + void FlushTraceListeners(void); inline gcroot GetCurrentThread(void)