- Attempt merge

This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-27 15:41:50 +02:00
parent 83b2a11c80
commit f75604eca9
6 changed files with 123 additions and 12 deletions

View File

@ -0,0 +1,15 @@
module tristanable.exceptions;
public enum Error
{
QueueExists
}
public class TristanableException : Exception
{
this(Error err)
{
// TODO: Do this
super("TODO: Do this");
}
}

View File

@ -1,15 +1,55 @@
/**
* Management of a tristanable instance
*/
module tristanable.manager;
import std.socket;
import tristanable.queue : Queue;
import core.sync.mutex : Mutex;
/**
* Allows one to add new queues, control
* existing ones by waiting on them etc
* Manages a provided socket by spawning
* a watcher thread to read from it and file
* mail into the corresponding queues.
*
* Queues are managed via this an instance
* of a manager.
*/
public class Manager
{
/* Queues */
private Queue[] queues;
/**
* The underlying socket to read from
*/
private Socket socket;
/**
* Currently registered queues
*
* NOTE: Make a ulong map to this later
*/
private Queue[] queues;
private Mutex queuesLock;
/**
* Constructs a new manager which will read from
* this socket and file mail for us
*
* Params:
* socket = the underlying socket to use
*/
this(Socket socket)
{
this.socket = socket;
this.queuesLock = new Mutex();
}
public void registerQueue(Queue queue)
{
// TODO: Lock queue
// TODO: Insert queue only if non-existent, else throw an exception
// TODO: Unlock queue
}
}

View File

@ -5,4 +5,5 @@ module tristanable;
public import tristanable.manager : Manager;
public import tristanable.queue : Queue, QueueItem;
public import tristanable.queue : Queue;
public import tristanable.queueitem : QueueItem;

View File

@ -1,6 +1,10 @@
module tristanable.queue;
// TODO: Examine the below import which seemingly fixes stuff for libsnooze
import libsnooze.clib;
import libsnooze;
import tristanable.queueitem : QueueItem;
import core.sync.mutex : Mutex;
public class Queue
@ -13,6 +17,11 @@ public class Queue
private QueueItem queue;
private Mutex queueLock;
/**
* This queue's unique ID
*/
private ulong queueID;
private this()
@ -26,7 +35,15 @@ public class Queue
public void dequeue()
{
// TODO: Make us wait on the event (optional with a time-out)
try
{
// TODO: Make us wait on the event (optional with a time-out)
event.wait();
}
catch(SnoozeError snozErr)
{
// TODO: Add error handling for libsnooze exceptions here
}
// TODO: Lock queue
queueLock.lock();
@ -45,9 +62,4 @@ public class Queue
return queue;
}
}
public class QueueItem
{
}

View File

@ -0,0 +1,6 @@
module tristanable.queueitem;
public class QueueItem
{
}

View File

@ -0,0 +1,37 @@
module tristanable.watcher;
import core.thread : Thread;
import tristanable.manager : Manager;
import std.socket;
/**
* Watches the socket on a thread of its own,
* performs the decoding of the incoming messages
* and places them into the correct queues via
* the associated Manager instance
*/
public class Watcher : Thread
{
/**
* The associated manager to use
* such that we can place new mail
* into their respective inboxes (queues)
*/
private Manager manager;
/**
* The underlying socket to read from
*/
private Socket socket;
private void watch()
{
while(true)
{
// TODO: Implement me
}
}
}