//
// Asura_DemonWare_LogSubscriber.h
//
// Created by Andrew Catlender - 15 March 2006 14:50:47
//
// Copyright (C) 2006 Rebellion (Derby), All Rights Reserved.
//
//
// Wrapper class to allow integration of DemonWare's Matchmaking+ SDK
//

#if defined(ASURA_USE_PRAGMA_ONCE)
#pragma once
#endif

#if !defined(__ASURA_DEMONWARE_LOGSUBSCRIBER_H__)
#define __ASURA_DEMONWARE_LOGSUBSCRIBER_H__

#if defined(ASURA_SUPPORT_EXTERNAL_NETWORK) && defined (ASURA_SUPPORT_DEMONWARE) && defined(ASURA_LOGFILES_ENABLED)

// Definition to help debug messages
#if defined(__FUNCSIG__)
#define ASURA_FUNCSIG __FUNCSIG__
#else
#define ASURA_FUNCSIG ""
#endif // __FUNCSIG__

// Belt and braces stuff
#if !defined(ASURA_DEMONWARE_PROJECT_NAME)
#define ASURA_DEMONWARE_PROJECT_NAME "NoProjectName!"
#endif ASURA_DEMONWARE_PROJECT_NAME

// Forward declarations
#if defined(ASURA_LOGFILES_ENABLED) && defined(ASURA_DEMONWARE_LOGFILES_ENABLED)
#define ASURA_DEMONWARE_LOG(params) { Asura_DemonWare_LogSubscriber_Singleton::GetInstance()->GetLog()->location(ASURA_DEMONWARE_PROJECT_NAME, __FILE__, ASURA_FUNCSIG, __LINE__); Asura_DemonWare_LogSubscriber_Singleton::GetInstance()->GetLog()->message params; }
#else
#define ASURA_DEMONWARE_LOG(ignore)
#endif // ASURA_LOGFILES_ENABLED && ASURA_DEMONWARE_LOGFILES_ENABLED

// Middleware includes (must be guarded by Asura_MemoryManagement_DebugOff/On)
#if defined(SN_TARGET_PS2)
// ARC - 23 March 2006 16:13:24 - I know this is supposed to be platform independent, but it's necessary for the DemonWare stuff
#pragma mathwarn off
#endif // SN_TARGET_PS2

#include "Core/Asura_MemoryManagement_DebugOff.h"
#include "DemonWare/bdCore/bdLog/bdLogSubscriber.h"

#if defined(SN_TARGET_PS2)
#pragma mathwarn on
#endif // SN_TARGET_PS2

//
//	Asura_DemonWare_LogSubscriber
//
class Asura_DemonWare_LogSubscriber : public bdLogSubscriber
{
public:
	BD_DECLARE_NEW_AND_DELETE_OPERATORS

	Asura_DemonWare_LogSubscriber();
	virtual ~Asura_DemonWare_LogSubscriber();

	// Used to log DemonWare information
	virtual void publish(const char* const szFullChannelName, const char* const szFile, const char* const szFunction, const unsigned int uiLine, const char* const szMessage);

	virtual void location(const char* const szFullChannelName, const char* const szFile, const char* const szFunction, const unsigned int uiLine);
	virtual void message(const char* const szFormat, ...);
	char* GetTimeString(void);

protected:
	char m_szBuffer[1024];

private:

};

//
//	Asura_DemonWare_LogSubscriber_Singleton
//
class Asura_DemonWare_LogSubscriber_Singleton
{
	// Needed to create a singleton to 'own' the Asura_DemonWare_LogSubscriber class
	// instead of directly making Asura_DemonWare_LogSubscriber a singleton itself
	// as it inherits from bdLogSubscriber which overloads new and delete at a class
	// level.  If I didn't, it would result in an infinite loop as the GetInstance()
	// member function tries to create a new instance...
public:
	static Asura_DemonWare_LogSubscriber_Singleton* const GetInstance(void);
	static void DeleteInstance(void);

	Asura_DemonWare_LogSubscriber* GetLog(void);

protected:
	Asura_DemonWare_LogSubscriber_Singleton();
	~Asura_DemonWare_LogSubscriber_Singleton();

private:

protected:
	static Asura_DemonWare_LogSubscriber_Singleton* s_pxInstance;
	Asura_DemonWare_LogSubscriber m_xLogSubscriber;
};

#endif // ASURA_SUPPORT_EXTERNAL_NETWORK && ASURA_SUPPORT_DEMONWARE && ASURA_LOGFILES_ENABLED

#endif // __ASURA_DEMONWARE_LOGSUBSCRIBER_H__