// DWBS ------------------------------------------------------------------ DWBS
//
// PLATFORM		: ALL
// PRODUCT		: BIT_DEMON
// VISIBILITY	: PUBLIC
//
// DWBS ------------------------------------------------------------------ DWBS

#ifndef BD_LOG_CHANNEL_H
#define BD_LOG_CHANNEL_H

#include <bdCore/bdMemory/bdMemory.h>
#include <bdCore/bdContainers/bdSingleton.h>
#include <bdCore/bdContainers/bdHashMap.h>
#include <bdCore/bdThread/bdMutex.h>

class bdLogSubscriber;

class bdLogChannel
{
	public:

		BD_DECLARE_NEW_AND_DELETE_OPERATORS;

		/// Default constructor
		bdLogChannel(const bdNChar8 *const channelName);

		/// Virtual destructor
		~bdLogChannel();

		void log(const bdNChar8 *const file,
			     const bdNChar8 *const function,
				 const bdUInt line,
				 const bdNChar8 *const channelName,
				 const bdNChar8 *const msg);

		void addSubscriber(const bdNChar8 *const fullChannelName,
						   const bdNChar8 *const channelName,
						   bdLogSubscriber *const subscriber);

		void removeSubscriber(const bdNChar8 *const fullChannelName,
							  const bdNChar8 *const channelName,
							  bdLogSubscriber *const subscriber);

		void removeSubscriber(bdLogSubscriber *const subscriber);

	protected:

		bdString m_channelName;

		bdHashMap<bdString, bdLogChannel *> m_components;
		
		// In debug mode, we need to be thread safe when accessing the 
		// m_components map.
#ifdef BD_DEBUG
		bdMutex m_componentsLock;
#define BD_LOCK_COMPONENTS m_componentsLock.lock();
#define BD_UNLOCK_COMPONENTS m_componentsLock.unlock();
#else //BD_DEBUG
#define BD_LOCK_COMPONENTS
#define BD_UNLOCK_COMPONENTS
#endif //BD_DEBUG

		bdFastArray<bdLogSubscriber *> m_subscribers;
};

#endif // BD_LOG_CHANNEL_H
