/*****************************************************************************
 * $LastChangedDate: 2011-04-23 21:07:07 -0400 (Sat, 23 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Queues for different kinds of SDL events
 *//*
 * LEGAL:   COPYRIGHT (C) 2009 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#if COMPILE_SDL
#ifndef GLUE_SDL_QUEUE_HH
#define GLUE_SDL_QUEUE_HH 1

#define GET_SDL_QUEUE() (glue::SDLQueue::GetInstance())

#include <deque>
#include "base/singleton.hh"
#include <SDL.h>
// SDL header defines a main() macro, undefine it.
#undef main

namespace glue {

////////////////////////////////////////////////////////////////////////////////
/// @brief Queues for different kinds of SDL events.
///
/// This separates different kinds of SDL events into separate queues.
/// The rationale is to let a module dequeue only specific kinds of events.
/// For example, DequeueJoystickEvent() dequenes only joystick events.
///
/// Implementation:
/// Pulse() is called whenever the common subroutine DequeueEvent() method is called,
/// so no need to register a timer functor.
///
class SDLQueue
{
PREVENT_COPYING(SDLQueue)
private:
                SDLQueue( void );
                ~SDLQueue();
    void        Pulse( void );
    bool        DequeueEvent( SDL_Event& sdlEvent /*OUT*/, std::deque<SDL_Event>& queue );

// Interface:
public:
                DEFINE_GetInstance( SDLQueue )
    bool        DequeueJoystickEvent( SDL_Event& sdlEvent /*OUT*/ );

private:
    CLASS_VAR SDLQueue*   msInstance;
    std::deque<SDL_Event> mJoystickQueue;     ///< joystick events
};

} // namespace glue

#endif // GLUE_SDL_QUEUE_HH
#endif // COMPILE_SDL
