WIP: reserved tags/notifcation system

This commit is contained in:
Tristan 🅱. Kildaire 2020-09-24 20:49:59 +02:00
parent 4623cbd304
commit 47565b5692
2 changed files with 56 additions and 1 deletions

View File

@ -18,5 +18,22 @@ module tristanable.notifications;
public class NotificationReply public class NotificationReply
{ {
private ulong tag;
private byte[] data;
this(ulong tag, byte[] data)
{
this.tag = tag;
this.data = data;
}
public byte[] getData()
{
return data;
}
public ulong getTag()
{
return tag;
}
} }

View File

@ -40,6 +40,11 @@ public final class Manager
*/ */
private Mutex queueMutex; private Mutex queueMutex;
/**
* The notification queue mutex
*/
private Mutex notificationMutex;
/** /**
* The remote host * The remote host
*/ */
@ -64,6 +69,9 @@ public final class Manager
/* Initialize the `requestQueue` mutex */ /* Initialize the `requestQueue` mutex */
queueMutex = new Mutex(); queueMutex = new Mutex();
/* Initialize the `notificationQueue` mutex */
notificationMutex = new Mutex();
/* Start the watcher */ /* Start the watcher */
watcher.start(); watcher.start();
@ -216,6 +224,36 @@ public final class Manager
queueMutex.unlock(); queueMutex.unlock();
} }
public void lockNotificationQueue()
{
notificationMutex.lock();
}
public void unlockNotificationQueue()
{
notificationMutex.unlock();
}
public NotificationReply[] popNotifications()
{
/* The notifications at this moment */
NotificationReply[] currentNotificationSet;
/* Lock the notification queue */
lockNotificationQueue();
/* Copy the current notifications */
currentNotificationSet = notificationQueue;
/* Empty the notification list */
notificationQueue.length = 0;
/* Unlock the notification queue */
unlockNotificationQueue();
return currentNotificationSet;
}
public void reserveTag(ulong tag) public void reserveTag(ulong tag)
{ {
reservedTags ~= tag; reservedTags ~= tag;