platform for developing on SQFMI's Watchy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
1.3 KiB

#ifndef _EVENTLISTENER_h
#define _EVENTLISTENER_h
#include "watchos_consts.h"
#include "Queue.h"
#include "Event.h"
/// <summary>
/// Mixin for a object which can receive events from the kernel
/// </summary>
class EventListener
{
private:
Queue* m_event_queue;
protected:
/// <summary>
/// Check whether there are any events available in the buffer
/// </summary>
/// <returns>True if there are events; False if no events</returns>
bool hasEvent();
/// <summary>
/// Fetch the next event from the buffer and return it
/// </summary>
/// <returns>A pointer to the next event in the buffer; shared, do not modify</returns>
Event* getEvent();
/// <summary>
/// Remove the last fetched event from the buffer; releases our reference to its handle
/// </summary>
void popEvent();
public:
/// <summary>
/// Initialize the ring buffer
/// </summary>
EventListener();
/// <summary>
/// Push an event into the queue
/// </summary>
/// <remarks>
/// This is passed a kernel handle so the event system may take a reference to it (increasing the
/// kernel's refcount) and eventually release it when processed (decreasing the refcount) so that
/// the kernel can handle allocating/releasing this for us.
/// </remarks>
/// <param name="handle"></param>
void pushEvent(kernel_handle_t handle);
};
#endif