196 lines
8.1 KiB
C++
196 lines
8.1 KiB
C++
#pragma once
|
|
|
|
#ifndef _BLOOMBERG_REPORTER_H_
|
|
#define _BLOOMBERG_REPORTER_H_
|
|
|
|
#include "bloomberg_interface.h" // include's Bloomberg and Settings
|
|
#include "components/bloombergthreadinterface.h"
|
|
#include "report/reportmanager.h"
|
|
#include "report/Writer/datawriter.h"
|
|
|
|
namespace Bloomberg
|
|
{
|
|
class InternalLogFile;
|
|
class IniFile;
|
|
|
|
// Singleton
|
|
class Reporter
|
|
{
|
|
public:
|
|
|
|
// Master Bloomberg initializer. Starts Bloomberg, installs exception handlers.
|
|
static inline void Initialize(BloombergInterface* bloombergInterface);
|
|
|
|
// Singleton Implementation
|
|
static inline Reporter& GetInstance();
|
|
|
|
// Make sure that the user is connected. If not, ConnectionVerification is set to false.
|
|
void VerifyConnection();
|
|
|
|
// Stop Bloomberg and deinstall Bloomberg's crash handler.
|
|
// exceptionHandler: replacement crash handler to install (instead of Bloomberg's).
|
|
void UnInit(CrashHandler::ExceptionHandlerCb exceptionHandler = 0);
|
|
|
|
// Getter
|
|
inline Settings& GetSettings()
|
|
{
|
|
return m_Settings;
|
|
}
|
|
|
|
inline BloombergInterface& GetInterface()
|
|
{
|
|
return *m_bloombergInterface;
|
|
}
|
|
|
|
inline CrashHandler& GetCrashHandler()
|
|
{
|
|
return *m_CrashHandler;
|
|
}
|
|
|
|
inline BloombergThreadInterface& GetBloombergThread()
|
|
{
|
|
return *m_bloombergThread;
|
|
}
|
|
|
|
inline ReportManager& GetReportManager()
|
|
{
|
|
return *m_reportManager;
|
|
}
|
|
|
|
inline Dialog& GetDialog()
|
|
{
|
|
return *m_dialog;
|
|
}
|
|
|
|
inline static Bool HasBeenInit()
|
|
{
|
|
return m_HasBeenInit;
|
|
}
|
|
|
|
inline Bool GetCrashHandlerRegistered()
|
|
{
|
|
return m_crashHandlerRegistered;
|
|
}
|
|
|
|
const Char* GetBloombergLogFilePath();
|
|
|
|
// Warning - this call will block!!!
|
|
// Should be called from a separate, dedicated thread.
|
|
inline void WaitForConnections()
|
|
{
|
|
m_remoteDataWriter->WaitForConnections();
|
|
}
|
|
|
|
inline U16 GetRemoteDataPort()
|
|
{
|
|
return m_remoteDataWriter->GetPort();
|
|
}
|
|
|
|
inline RemoteDataCollector& GetRemoteDataCollector()
|
|
{
|
|
return *m_remoteDataCollector;
|
|
}
|
|
|
|
// set Bloomberg's behavior with regards to crashes
|
|
// - registerCrashHandler: make bloomberg catch crashes if True, stop Bloomberg from catching crashes if False
|
|
void RegisterCrashHandler(Bool registerCrashHandler);
|
|
|
|
// These are multi thread safe:
|
|
// 1. Trigger a report by passing down your own report to log some statistics or other things.
|
|
// 2. Trigger a crash by passing and error type, error message and some data (see crashhandler.h for specification)
|
|
// 3. For stats and flags you can either pass a ReportStats or ReportFlag (it will use the TriggerReport method)
|
|
// or use the internal ReportStats and ReportFlags by ignoring this parameters. In this case, and only for stats,
|
|
// the report will be processed asynchronously if you are using the BloombergThread.
|
|
//
|
|
// !You can't manually trigger a report when another is being analyze. It will be ignored. The only
|
|
// way to that is when PostProcess is called by the ReportManager (this method can be implemented in your BloombergInterface).
|
|
// Flushing the stats when an exception occurs is a good example of this case.
|
|
|
|
DialogDefinitions::DialogButton TriggerReport(ReportInterface& report);
|
|
DialogDefinitions::DialogButton TriggerError(ReportType type, const Char* errorMessage, void* pData = 0);
|
|
BLOOMBERG_DECLARE_DEPRECATED( DialogDefinitions::DialogButton TriggerCrash(ReportType type, const Char* errorMessage, void* pData = 0), "This method is deprecated. Please use the TriggerError method.");
|
|
|
|
// Async methods
|
|
DialogDefinitions::DialogButton TriggerErrorAsync(ReportType type, const Char* errorMessage, void* pData = 0);
|
|
DialogDefinitions::DialogButton TriggerErrorAsync(ReportType type, const Char* subtype, const Char* errorMessage, void* pData);
|
|
|
|
// Final method
|
|
DialogDefinitions::DialogButton TriggerError(ReportType type, const Char* subtype, const Char* errorMessage, void* pData, bool async = false);
|
|
BLOOMBERG_DECLARE_DEPRECATED( DialogDefinitions::DialogButton TriggerCrash(ReportType type, const Char* subtype, const Char* errorMessage, void* pData), "This method is deprecated. Please use the TriggerError method.");
|
|
|
|
DialogDefinitions::DialogButton TriggerFlag(ReportFlag* reportFlag = 0);
|
|
|
|
// Log some stats by passing a Stats object (see ReportStats.h)
|
|
STATS_RESULT LogStats(Stats* stats);
|
|
|
|
#if BLOOMBERG_PLATFORM == BLOOMBERG_PLATFORM_DURANGO || defined(BLOOMBERG_PLATFORM_PC)
|
|
// register a DLL about which information should always be retrieved in case of a crash or assert
|
|
void RegisterDLL(BLOOMBERG_MODULE_HANDLE hModule);
|
|
void UnregisterDLL(BLOOMBERG_MODULE_HANDLE hModule);
|
|
#endif
|
|
|
|
private:
|
|
Reporter(BloombergInterface* bloombergInterface);
|
|
// Avoid copy constructor and operator =
|
|
Reporter(const Reporter&) {}
|
|
void operator=(const Reporter&) {}
|
|
|
|
DialogDefinitions::DialogButton TriggerStats();
|
|
|
|
// Method
|
|
void InternalInit();
|
|
|
|
void InternalInitDefaultGameSettings();
|
|
void InternalInitDefaultBloombergSettings();
|
|
void InternalInitDefaultRuntimeSettings();
|
|
|
|
static bool ReadReporterConfigFile(File * reporterConfigFile, Char * bufferUserName, size_t bufferUserNameLength, Char * bufferReporterMachineName, size_t bufferReporterMachineNameLength);
|
|
void InternalInitSettingsFromFiles();
|
|
void InternalInitGameSettingsFromFile(const IniFile * settingsFile);
|
|
void InternalInitBloombergSettingsFromFile(const IniFile * bloombergSettingsFile);
|
|
void InternalInitRuntimeVarsFromFile(const IniFile * bloombergSettingsFile);
|
|
void InternalInitConnectionsFromFile(const IniFile * bloombergSettingsFile, File * connectionSettingsFile);
|
|
void InternalInitCrashSettingsFromFile(const IniFile * bloombergSettingsFile);
|
|
|
|
// Member
|
|
Settings m_Settings;
|
|
ReportManager* m_reportManager;
|
|
Dialog* m_dialog;
|
|
BloombergInterface* m_bloombergInterface;
|
|
File* m_logFile;
|
|
CrashHandler* m_CrashHandler;
|
|
BloombergThreadInterface* m_bloombergThread;
|
|
Bool m_crashHandlerRegistered;
|
|
RemoteDataWriter* m_remoteDataWriter;
|
|
RemoteDataCollector* m_remoteDataCollector;
|
|
|
|
static Bool m_HasBeenInit;
|
|
|
|
// Singleton
|
|
static Reporter* m_Instance;
|
|
|
|
friend class ReportStats;
|
|
};
|
|
|
|
//INLINE
|
|
|
|
inline Reporter& Reporter::GetInstance()
|
|
{
|
|
BLOOMBERG_ASSERTM(m_Instance, "Reporter::GetInstance: Bloomberg has not been initialized yet.");
|
|
return *m_Instance;
|
|
}
|
|
|
|
// Client has already instantiated his interface
|
|
inline void Reporter::Initialize(BloombergInterface* bloombergInterface)
|
|
{
|
|
BLOOMBERG_ASSERT(bloombergInterface);
|
|
if (!m_Instance)
|
|
{
|
|
FastStringManager::GetInstance();
|
|
m_Instance = BLOOMBERG_ALLOCATE_OBJECT(Reporter, "Bloomberg::Reporter")(bloombergInterface);
|
|
m_Instance->InternalInit();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif // _BLOOMBERG_REPORTER_H_
|