/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__MESSAGING__
#define	__MESSAGING__


		#include "container/nlist.h"


namespace GS {
	namespace Messaging {

/*!
	@short	Low-level message broadcasting system.
	@author	Emmanuel Julien (ejulien@nworks.fr)
*/
template <class Message, class Listener, class From, class Parm = void *> class Broadcaster
{
protected:

		/// Message listener list.
		List <Listener *> listener_list;

public:

		bool		RegisterMessageListener(Listener *listener)
		{	return listener_list.Add(listener) ? true : false;	}
		bool		UnregisterMessageListener(Listener *listener)
		{	return listener_list.Remove(listener);	}

virtual	void		BroadcastMessage(const Message &msg, const From &from, const Parm &parm)
		{
			ListForeachPtr(Listener *, listener, listener_list)
				listener->ProcessMessage(msg, from, parm);
		}

virtual ~Broadcaster() {}
};

	} // Messaging
} // GS


#endif	// __MESSAGING__