mirror of
https://github.com/deavmi/tristanable.git
synced 2024-09-21 23:02:53 +02:00
- Attempt merge
This commit is contained in:
parent
83b2a11c80
commit
f75604eca9
15
source/tristanable/exceptions.d
Normal file
15
source/tristanable/exceptions.d
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* Management of a tristanable instance
|
||||||
|
*/
|
||||||
module tristanable.manager;
|
module tristanable.manager;
|
||||||
|
|
||||||
|
import std.socket;
|
||||||
import tristanable.queue : Queue;
|
import tristanable.queue : Queue;
|
||||||
|
import core.sync.mutex : Mutex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows one to add new queues, control
|
* Manages a provided socket by spawning
|
||||||
* existing ones by waiting on them etc
|
* 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
|
public class Manager
|
||||||
{
|
{
|
||||||
/* 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 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
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,4 +5,5 @@ module tristanable;
|
|||||||
|
|
||||||
|
|
||||||
public import tristanable.manager : Manager;
|
public import tristanable.manager : Manager;
|
||||||
public import tristanable.queue : Queue, QueueItem;
|
public import tristanable.queue : Queue;
|
||||||
|
public import tristanable.queueitem : QueueItem;
|
@ -1,6 +1,10 @@
|
|||||||
module tristanable.queue;
|
module tristanable.queue;
|
||||||
|
|
||||||
|
// TODO: Examine the below import which seemingly fixes stuff for libsnooze
|
||||||
|
import libsnooze.clib;
|
||||||
import libsnooze;
|
import libsnooze;
|
||||||
|
|
||||||
|
import tristanable.queueitem : QueueItem;
|
||||||
import core.sync.mutex : Mutex;
|
import core.sync.mutex : Mutex;
|
||||||
|
|
||||||
public class Queue
|
public class Queue
|
||||||
@ -14,6 +18,11 @@ public class Queue
|
|||||||
private QueueItem queue;
|
private QueueItem queue;
|
||||||
private Mutex queueLock;
|
private Mutex queueLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This queue's unique ID
|
||||||
|
*/
|
||||||
|
private ulong queueID;
|
||||||
|
|
||||||
|
|
||||||
private this()
|
private this()
|
||||||
{
|
{
|
||||||
@ -25,8 +34,16 @@ public class Queue
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dequeue()
|
public void dequeue()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
// TODO: Make us wait on the event (optional with a time-out)
|
// 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
|
// TODO: Lock queue
|
||||||
queueLock.lock();
|
queueLock.lock();
|
||||||
@ -46,8 +63,3 @@ public class Queue
|
|||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QueueItem
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
6
source/tristanable/queueitem.d
Normal file
6
source/tristanable/queueitem.d
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module tristanable.queueitem;
|
||||||
|
|
||||||
|
public class QueueItem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
37
source/tristanable/watcher.d
Normal file
37
source/tristanable/watcher.d
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user