Skip to content

Commit 34b1646

Browse files
committed
Merge pull request #20 from NeoAnomaly/master
Adding new kind of action which is performed in response to the error.
2 parents ffdfdcb + 4e0e270 commit 34b1646

8 files changed

+108
-3
lines changed

source/Client/BugTrap.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,24 @@ extern "C" BUGTRAP_API BT_ErrHandler APIENTRY BT_GetPostErrHandler(void)
936936
return g_pfnPostErrHandler;
937937
}
938938

939+
/**
940+
* @return address of custom activity handler called at processing BugTrap action.
941+
*/
942+
extern "C" BUGTRAP_API BT_CustomActivityHandler APIENTRY BT_GetCustomActivityHandler(void)
943+
{
944+
return g_pfnCustomActivityHandler;
945+
}
946+
947+
/**
948+
* @param pfnCustomActivityHandler - address of custom activity handler called at processing BugTrap action.
949+
* @param nCustomActivityHandlerParam - user-defined parameter of custom activity handler called at processing BugTrap action.
950+
*/
951+
extern "C" BUGTRAP_API void APIENTRY BT_SetCustomActivityHandler(BT_CustomActivityHandler pfnCustomActivityHandler, INT_PTR nCustomActivityHandlerParam)
952+
{
953+
g_pfnCustomActivityHandler = pfnCustomActivityHandler;
954+
g_nCustomActivityHandlerParam = nCustomActivityHandlerParam;
955+
}
956+
939957
/**
940958
* @param pfnPostErrHandler - address of error handler called after BugTrap dialog.
941959
* @param nPostErrHandlerParam - user-defined parameter of error handler called after BugTrap dialog.

source/Client/BugTrap.h

+26-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ typedef enum BUGTRAP_ACTIVITY_tag
6666
/**
6767
* @brief Automatically send bug report to support server.
6868
*/
69-
BTA_SENDREPORT = 4
69+
BTA_SENDREPORT = 4,
70+
/**
71+
* @brief Call custom handler specified by BT_SetCustomActivityHandler().
72+
*/
73+
BTA_CUSTOM = 5,
7074
}
7175
BUGTRAP_ACTIVITY;
7276

@@ -365,6 +369,11 @@ BUGTRAP_REGEXPORTENTRY;
365369
*/
366370
typedef void (CALLBACK * BT_ErrHandler)(INT_PTR nErrHandlerParam);
367371

372+
/**
373+
* @brief Type definition of user-defined activity handler.
374+
*/
375+
typedef void (CALLBACK * BT_CustomActivityHandler)(LPCTSTR pszReportFilePath, INT_PTR nCustomActivityHandlerParam);
376+
368377
/** @} */
369378

370379
/**
@@ -648,6 +657,22 @@ BUGTRAP_API void APIENTRY BT_SetPostErrHandler(BT_ErrHandler pfnPostErrHandler,
648657

649658
/** @} */
650659

660+
/**
661+
* @defgroup CustomActivityHandlers Custom activity handlers
662+
* @{
663+
*/
664+
665+
/**
666+
* @brief Get address of custom activity handler called at processing BugTrap action.
667+
*/
668+
BUGTRAP_API BT_CustomActivityHandler APIENTRY BT_GetCustomActivityHandler(void);
669+
/**
670+
* @brief Set address of custom activity handler called at processing BugTrap action.
671+
*/
672+
BUGTRAP_API void APIENTRY BT_SetCustomActivityHandler(BT_CustomActivityHandler pfnCustomActivityHandler, INT_PTR nCustomActivityHandlerParam);
673+
674+
/** @} */
675+
651676
/**
652677
* @defgroup TracingFunc Tracing functions
653678
* @{

source/Client/BugTrapNet.h

+27-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ namespace IntelleSoft
4747
ShowUI = BTA_SHOWUI,
4848
SaveReport = BTA_SAVEREPORT,
4949
MailReport = BTA_MAILREPORT,
50-
SendReport = BTA_SENDREPORT
50+
SendReport = BTA_SENDREPORT,
51+
Custom = BTA_CUSTOM
5152
};
5253

5354
[Flags]
@@ -373,6 +374,8 @@ namespace IntelleSoft
373374

374375
public delegate void UnhandledExceptionDelegate(Object^ sender, UnhandledExceptionEventArgs^ args);
375376

377+
public delegate void CustomActivityDelegate(Object^ sender, String^ reportFilePath);
378+
376379
public ref class ExceptionHandler
377380
{
378381
private:
@@ -391,6 +394,7 @@ namespace IntelleSoft
391394

392395
static void ValidateIoResult(BOOL bResult);
393396

397+
static event CustomActivityDelegate^ customActivityEvent;
394398
internal:
395399
static property System::Exception^ Exception
396400
{
@@ -418,7 +422,7 @@ namespace IntelleSoft
418422

419423
static void FireBeforeUnhandledExceptionEvent(void);
420424
static void FireAfterUnhandledExceptionEvent(void);
421-
425+
static void FireCustomActivityEvent(String^ reportFilePath);
422426
public:
423427
static const int HttpPort = BUGTRAP_HTTP_PORT;
424428

@@ -434,6 +438,12 @@ namespace IntelleSoft
434438
void remove(UnhandledExceptionDelegate^ value);
435439
}
436440

441+
static event CustomActivityDelegate^ CustomActivity
442+
{
443+
void add(CustomActivityDelegate^ value);
444+
void remove(CustomActivityDelegate^ value);
445+
}
446+
437447
static property String^ AppName
438448
{
439449
String^ get(void);
@@ -596,6 +606,11 @@ namespace IntelleSoft
596606
afterUnhandledExceptionEvent(Sender, Arguments);
597607
}
598608

609+
inline void ExceptionHandler::FireCustomActivityEvent(String^ reportFilePath)
610+
{
611+
customActivityEvent(Sender, reportFilePath);
612+
}
613+
599614
inline void ExceptionHandler::BeforeUnhandledException::add(UnhandledExceptionDelegate^ value)
600615
{
601616
beforeUnhandledExceptionEvent += value;
@@ -616,6 +631,16 @@ namespace IntelleSoft
616631
afterUnhandledExceptionEvent -= value;
617632
}
618633

634+
inline void ExceptionHandler::CustomActivity::add(CustomActivityDelegate^ value)
635+
{
636+
customActivityEvent += value;
637+
}
638+
639+
inline void ExceptionHandler::CustomActivity::remove(CustomActivityDelegate^ value)
640+
{
641+
customActivityEvent -= value;
642+
}
643+
619644
inline String^ ExceptionHandler::AppName::get(void)
620645
{
621646
return gcnew String(BT_GetAppName());

source/Client/BugTrapUI.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "MemStream.h"
2929
#include "VersionInfoString.h"
3030

31+
#ifdef _MANAGED
32+
#include "NetThunks.h"
33+
#endif
34+
3135
#ifdef _DEBUG
3236
#define new DEBUG_NEW
3337
#endif
@@ -1357,6 +1361,15 @@ static void ExecuteHandlerAction(void)
13571361
else if (DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_SIMPLE_DLG), GetForegroundWindow(), SimpleDlgProc) == TRUE)
13581362
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, MainDlgProc);
13591363
}
1364+
break;
1365+
case BTA_CUSTOM:
1366+
#ifdef _MANAGED
1367+
NetThunks::FireCustomActivityEvent(g_szInternalReportFilePath);
1368+
#else
1369+
if (g_pfnCustomActivityHandler != NULL)
1370+
(*g_pfnCustomActivityHandler)(g_szInternalReportFilePath, g_nCustomActivityHandlerParam);
1371+
#endif // _MANAGED
1372+
13601373
break;
13611374
}
13621375
}

source/Client/Globals.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ CStrHolder g_strUserMessage;
8484
CStrHolder g_strFirstIntroMesage;
8585
/// 2nd introduction message displayed on the dialog.
8686
CStrHolder g_strSecondIntroMesage;
87+
88+
/// Address of custom activity handler called at processing BugTrap action.
89+
extern BT_CustomActivityHandler g_pfnCustomActivityHandler = NULL;
90+
/// User-defined parameter of custom activity handler.
91+
extern INT_PTR g_nCustomActivityHandlerParam = 0;

source/Client/Globals.h

+5
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,8 @@ extern CStrHolder g_strUserMessage;
116116
extern CStrHolder g_strFirstIntroMesage;
117117
/// 2nd introduction message displayed on the dialog.
118118
extern CStrHolder g_strSecondIntroMesage;
119+
120+
/// Address of custom activity handler called at processing BugTrap action.
121+
extern BT_CustomActivityHandler g_pfnCustomActivityHandler;
122+
/// User-defined parameter of custom activity handler.
123+
extern INT_PTR g_nCustomActivityHandlerParam;

source/Client/NetThunks.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ namespace NetThunks
504504
}
505505
}
506506

507+
void FireCustomActivityEvent(LPCTSTR pszReportFilePath)
508+
{
509+
try
510+
{
511+
ExceptionHandler::FireCustomActivityEvent(gcnew String(pszReportFilePath));
512+
}
513+
catch (Exception^ exception)
514+
{
515+
Debug::WriteLine(exception);
516+
}
517+
}
518+
507519
void FlushTraceListeners(void)
508520
{
509521
try

source/Client/NetThunks.h

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ namespace NetThunks
146146

147147
void FireAfterUnhandledExceptionEvent(void);
148148

149+
void FireCustomActivityEvent(LPCTSTR pszReportFilePath);
150+
149151
void FlushTraceListeners(void);
150152

151153
inline gcroot<Thread^> GetCurrentThread(void)

0 commit comments

Comments
 (0)