/*	XGBroadcast.cpp
 *
 *		This is a global class which uses static (global) methods for
 *	broadcasting messages
 */

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <XEvent.h>

/************************************************************************/
/*																		*/
/*	Globals																*/
/*																		*/
/************************************************************************/

XGSend XGBroadcast::gSend;
XGSDynArray<_PostRecord> XGBroadcast::gPostStack;

/************************************************************************/
/*																		*/
/*	PostBroadcast Support												*/
/*																		*/
/************************************************************************/

// @G"Public methods"

/*	@F"XGBroadcast::PostBroadcast" @I
 *
 *		This takes the arguments and creates a _PostRecord which
 *	contains the arguments, for later posting.
 *
 *		WARNING: As the messages are sent later, putting the 'parg'
 *	object on the stack would be a problem.
 */

void XGBroadcast::PostBroadcast(long msg, long arg, void *parg)
{
	_PostRecord p;
	
	p.msg = msg;
	p.arg = arg;
	p.parg = parg;
	gPostStack += p;
}

/*	@F"XGBroadcast::SendPostBroadcast" @I
 *
 *		Run the list and send all the messages that were delayed. This
 *	is called from the internal YAAF event loop.
 */

void XGBroadcast::SendPostBroadcast()
{
	long i,len;
	
	len = gPostStack.Length();
	for (i = 0; i < len; i++) {
		gSend.SendMessage(gPostStack[i].msg,
						  gPostStack[i].arg,
						  gPostStack[i].parg);
	}
	gPostStack.DeleteAll();
}
