/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
****************************************************************************/

#pragma once

#include "glmCoreAPI.h"

#include <string>

namespace google_breakpad
{
	class ClientInfo;
	class ExceptionHandler;
	class CrashGenerationServer;
	struct CustomInfoEntry;
	class MinidumpDescriptor;
}

namespace glm
{
	class GLM_CORE_API Minidump
	{
	public:
        typedef void (*glmCrashCallback)();

		struct Reporting
		{
			enum Value
			{
				NO_REPORT,
				MESSAGE_BOX,
				END
			};
		};

		Minidump();
		~Minidump();

		void start(Reporting::Value reporting = Reporting::NO_REPORT);
		void stop();

		void setCrashCallback(glmCrashCallback callback)	{	_crashCallback = callback;	}
        glmCrashCallback getCrashCallback() const	{	return _crashCallback;	}

		static const unsigned int _directoryPathLengthMax = 1024; // access needed for Crowd
		char _directory[_directoryPathLengthMax]; // access needed for Crowd

	private:
		static void getDefaultDirectory(char* charBuffer, const unsigned int charBufferSize);
		static void strcpySafe(char* destBuffer, const unsigned int destBufferSize, const char* srcBuffer);

		google_breakpad::ExceptionHandler* _exceptionHandler;
        glmCrashCallback _crashCallback = NULL;

#ifdef _MSC_VER
		static void showDumpResults(	void* context,
			const google_breakpad::ClientInfo* client_info,
			const std::wstring* file_path);

		void crashServerStart(Reporting::Value reporting);
		void crashServerStop();

		google_breakpad::CrashGenerationServer* _crashGenerationServer;

		static const size_t _customInfoCount = 2;
		google_breakpad::CustomInfoEntry* _customInfoEntries;	
#else
		google_breakpad::MinidumpDescriptor* _minidumpDescriptor;	
#endif
	};
}

