|
|
@@ -6,24 +6,22 @@
|
|
|
#pragma once
|
|
|
|
|
|
#include "device/types.h"
|
|
|
-#include "core/thread/spsc_queue.inl"
|
|
|
#include <string.h> // memcpy
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
-/// Single Producer Single Consumer event queue.
|
|
|
-/// Used only to pass events from os thread to main thread.
|
|
|
-/// https://www.irif.fr/~guatto/papers/sbac13.pdf
|
|
|
+typedef bool (*QueuePushFunction)(const OsEvent &ev);
|
|
|
+
|
|
|
+/// Used only to pass events from OS to main thread.
|
|
|
///
|
|
|
/// @ingroup Device
|
|
|
struct DeviceEventQueue
|
|
|
{
|
|
|
-#define MAX_OS_EVENTS 128
|
|
|
- SPSCQueue<OsEvent, MAX_OS_EVENTS> _queue;
|
|
|
+ QueuePushFunction _queue_push_function;
|
|
|
|
|
|
///
|
|
|
- DeviceEventQueue(Allocator &a)
|
|
|
- : _queue(a)
|
|
|
+ DeviceEventQueue(QueuePushFunction fn)
|
|
|
+ : _queue_push_function(fn)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
@@ -36,7 +34,7 @@ struct DeviceEventQueue
|
|
|
ev.button.button_num = button_id;
|
|
|
ev.button.pressed = pressed;
|
|
|
|
|
|
- push_event(ev);
|
|
|
+ _queue_push_function(ev);
|
|
|
}
|
|
|
|
|
|
void push_axis_event(u16 device_id, u16 device_num, u16 axis_id, s16 axis_x, s16 axis_y, s16 axis_z)
|
|
|
@@ -50,7 +48,7 @@ struct DeviceEventQueue
|
|
|
ev.axis.axis_y = axis_y;
|
|
|
ev.axis.axis_z = axis_z;
|
|
|
|
|
|
- push_event(ev);
|
|
|
+ _queue_push_function(ev);
|
|
|
}
|
|
|
|
|
|
void push_status_event(u16 device_id, u16 device_num, bool connected)
|
|
|
@@ -61,7 +59,7 @@ struct DeviceEventQueue
|
|
|
ev.status.device_num = device_num;
|
|
|
ev.status.connected = connected;
|
|
|
|
|
|
- push_event(ev);
|
|
|
+ _queue_push_function(ev);
|
|
|
}
|
|
|
|
|
|
void push_resolution_event(u16 width, u16 height)
|
|
|
@@ -71,7 +69,7 @@ struct DeviceEventQueue
|
|
|
ev.resolution.width = width;
|
|
|
ev.resolution.height = height;
|
|
|
|
|
|
- push_event(ev);
|
|
|
+ _queue_push_function(ev);
|
|
|
}
|
|
|
|
|
|
void push_exit_event()
|
|
|
@@ -79,7 +77,7 @@ struct DeviceEventQueue
|
|
|
OsEvent ev;
|
|
|
ev.type = OsEventType::EXIT;
|
|
|
|
|
|
- push_event(ev);
|
|
|
+ _queue_push_function(ev);
|
|
|
}
|
|
|
|
|
|
void push_text_event(u8 len, u8 utf8[4])
|
|
|
@@ -89,17 +87,7 @@ struct DeviceEventQueue
|
|
|
ev.text.len = len;
|
|
|
memcpy(ev.text.utf8, utf8, sizeof(ev.text.utf8));
|
|
|
|
|
|
- push_event(ev);
|
|
|
- }
|
|
|
-
|
|
|
- bool push_event(const OsEvent &ev)
|
|
|
- {
|
|
|
- return _queue.push(ev);
|
|
|
- }
|
|
|
-
|
|
|
- bool pop_event(OsEvent &ev)
|
|
|
- {
|
|
|
- return _queue.pop(ev);
|
|
|
+ _queue_push_function(ev);
|
|
|
}
|
|
|
};
|
|
|
|