#ifndef __EventSource__H
#define __EventSource__H

#include "WimpLib:std.h"
#include <stdbool.h>
#include "WimpLib:Event.h"
#include "WimpLib:EventSender.h"
#include "WimpLib:List.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct EvDispatcher
{
	int   m_type;
	List* m_pHandlers;
} EvDispatcher;

typedef struct EventSource
{
	EvDispatcher m_PreDispatcher;
	List*        m_pDispatchers;
	EvDispatcher m_PostDispatcher;
} EventSource;

// Constructor and destructor
void throw_EventSource_EventSource(EventSource*);
void EventSource_NotEventSource(EventSource*);

bool EventSource_ProcessEvent(EventSource*, const Event*);
bool EventSource_PreProcessEvent(EventSource*, const Event*);
bool EventSource_PostProcessEvent(EventSource*, const Event*);

void throw_EventSource_AddGlobalListener(EventSource*, Listener_FOnEvent pEventHandler, void* pHandle, bool bFirst);
void EventSource_RemoveGlobalListener(EventSource*, Listener_FOnEvent pEventHandler, void* pHandle);
bool EventSource_FindGlobalListener(EventSource*, Listener_FOnEvent pEventHandler, void* pHandle);
void throw_EventSource_AddListener(EventSource*, int event, Listener_FOnEvent pEventHandler, void* pHandle, bool bFirst);
void EventSource_RemoveListener(EventSource*, int event, Listener_FOnEvent pEventHandler, void* pHandle);
bool EventSource_FindListener(EventSource*, int event, Listener_FOnEvent pEventHandler, void* pHandle);

#ifdef __cplusplus
}
#endif

#endif
