Skip to content

Commit

Permalink
Merge pull request #20 from NeoAnomaly/master
Browse files Browse the repository at this point in the history
Adding new kind of action which is performed in response to the error.
  • Loading branch information
bchavez committed Mar 5, 2016
2 parents ffdfdcb + 4e0e270 commit 34b1646
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 3 deletions.
18 changes: 18 additions & 0 deletions source/Client/BugTrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 26 additions & 1 deletion source/Client/BugTrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

/** @} */

/**
Expand Down Expand Up @@ -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
* @{
Expand Down
29 changes: 27 additions & 2 deletions source/Client/BugTrapNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -391,6 +394,7 @@ namespace IntelleSoft

static void ValidateIoResult(BOOL bResult);

static event CustomActivityDelegate^ customActivityEvent;
internal:
static property System::Exception^ Exception
{
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down
13 changes: 13 additions & 0 deletions source/Client/BugTrapUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "MemStream.h"
#include "VersionInfoString.h"

#ifdef _MANAGED
#include "NetThunks.h"
#endif

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
Expand Down Expand Up @@ -1357,6 +1361,15 @@ static void ExecuteHandlerAction(void)
else if (DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_SIMPLE_DLG), GetForegroundWindow(), SimpleDlgProc) == TRUE)
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, MainDlgProc);
}
break;
case BTA_CUSTOM:
#ifdef _MANAGED
NetThunks::FireCustomActivityEvent(g_szInternalReportFilePath);
#else
if (g_pfnCustomActivityHandler != NULL)
(*g_pfnCustomActivityHandler)(g_szInternalReportFilePath, g_nCustomActivityHandlerParam);
#endif // _MANAGED

break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions source/Client/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions source/Client/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 12 additions & 0 deletions source/Client/NetThunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions source/Client/NetThunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ namespace NetThunks

void FireAfterUnhandledExceptionEvent(void);

void FireCustomActivityEvent(LPCTSTR pszReportFilePath);

void FlushTraceListeners(void);

inline gcroot<Thread^> GetCurrentThread(void)
Expand Down

0 comments on commit 34b1646

Please sign in to comment.