WIP: reserved tags/notifcation system
This commit is contained in:
parent
4623cbd304
commit
47565b5692
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue