1/**
2 * Copyright (c) 2006-2023 LOVE Development Team
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 **/
20
21#ifndef LOVE_EVENT_EVENT_H
22#define LOVE_EVENT_EVENT_H
23
24// LOVE
25#include "common/Module.h"
26#include "common/StringMap.h"
27#include "common/Variant.h"
28#include "keyboard/Keyboard.h"
29#include "mouse/Mouse.h"
30#include "joystick/Joystick.h"
31#include "thread/threads.h"
32
33// C++
34#include <queue>
35#include <vector>
36
37namespace love
38{
39namespace event
40{
41
42class Message : public Object
43{
44public:
45
46 Message(const std::string &name, const std::vector<Variant> &vargs = {});
47 ~Message();
48
49 int toLua(lua_State *L);
50 static Message *fromLua(lua_State *L, int n);
51
52 const std::string name;
53 const std::vector<Variant> args;
54
55}; // Message
56
57class Event : public Module
58{
59public:
60 virtual ~Event();
61
62 // Implements Module.
63 virtual ModuleType getModuleType() const { return M_EVENT; }
64
65 void push(Message *msg);
66 bool poll(Message *&msg);
67 virtual void clear();
68
69 virtual void pump() = 0;
70 virtual Message *wait() = 0;
71
72protected:
73 love::thread::MutexRef mutex;
74 std::queue<Message *> queue;
75
76}; // Event
77
78} // event
79} // love
80
81#endif // LOVE_EVENT_EVENT_H
82