Merge branch 'nextgen' of github.com:deavmi/tristanable into nextgen
This commit is contained in:
commit
ef95b15a2d
|
@ -55,7 +55,7 @@ DataMessage tristanEncoded = new DataMessage(tag, data);
|
||||||
socket.send(encodeForSend(tristanEncoded));
|
socket.send(encodeForSend(tristanEncoded));
|
||||||
```
|
```
|
||||||
|
|
||||||
And let tristanable handle it! We even handle the message lengths and everything using another great project [bformat](http://deavmi.assigned.network/projects/bformat).
|
And let tristanable handle it! We even handle the message lengths and everything using another great project [bformat](https://deavmi.assigned.network/projects/bformat).
|
||||||
|
|
||||||
## Format
|
## Format
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
module tristanable.encoding;
|
module tristanable.encoding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a tagged message that has been decoded
|
||||||
|
* from its raw byte encoding, this is a tuple of
|
||||||
|
* a numeric tag and a byte array of payload data
|
||||||
|
*
|
||||||
|
* Also provides a static method to decode from such
|
||||||
|
* raw encoding and an instance method to do the reverse
|
||||||
|
*/
|
||||||
public final class TaggedMessage
|
public final class TaggedMessage
|
||||||
{
|
{
|
||||||
private ulong tag;
|
private ulong tag;
|
||||||
|
@ -106,4 +114,10 @@ public final class TaggedMessage
|
||||||
{
|
{
|
||||||
this.tag = newTag;
|
this.tag = newTag;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
// TODO: Test encoding
|
||||||
|
// TODO: Test decoding
|
||||||
}
|
}
|
|
@ -1,11 +1,13 @@
|
||||||
/**
|
/**
|
||||||
* Management of a tristanable instance
|
* Management of a tristanable instance
|
||||||
*/
|
*/
|
||||||
module tristanable.manager;
|
module tristanable.manager.manager;
|
||||||
|
|
||||||
import std.socket;
|
import std.socket;
|
||||||
import tristanable.queue : Queue;
|
import tristanable.queue : Queue;
|
||||||
import core.sync.mutex : Mutex;
|
import core.sync.mutex : Mutex;
|
||||||
|
import tristanable.manager.watcher : Watcher;
|
||||||
|
import tristanable.encoding : TaggedMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages a provided socket by spawning
|
* Manages a provided socket by spawning
|
||||||
|
@ -30,6 +32,13 @@ public class Manager
|
||||||
private Queue[] queues;
|
private Queue[] queues;
|
||||||
private Mutex queuesLock;
|
private Mutex queuesLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watcher which manages the socket and
|
||||||
|
* enqueues new messages into the respective
|
||||||
|
* quueue for us
|
||||||
|
*/
|
||||||
|
private Watcher watcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new manager which will read from
|
* Constructs a new manager which will read from
|
||||||
* this socket and file mail for us
|
* this socket and file mail for us
|
||||||
|
@ -41,6 +50,14 @@ public class Manager
|
||||||
{
|
{
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.queuesLock = new Mutex();
|
this.queuesLock = new Mutex();
|
||||||
|
this.watcher = new Watcher(this, socket);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: comment
|
||||||
|
// Starts the watcher
|
||||||
|
public void start()
|
||||||
|
{
|
||||||
|
watcher.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,4 +69,25 @@ public class Manager
|
||||||
|
|
||||||
// TODO: Unlock queue
|
// TODO: Unlock queue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessage(TaggedMessage tag)
|
||||||
|
{
|
||||||
|
// TODO: Send the given message
|
||||||
|
|
||||||
|
// TODO: Encode into bytes; call it `x`
|
||||||
|
|
||||||
|
// TODO: Wrap `x` in bformat; call it `y`
|
||||||
|
|
||||||
|
// TODO: Do socket.send(`y`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
// TODO: Spawn server here
|
||||||
|
|
||||||
|
// TODO: wait for server to activate
|
||||||
|
// TODO: register tristanable quues
|
||||||
|
// TODO: make server then send something to us and chekc if queues active
|
||||||
}
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
module tristanable.manager;
|
||||||
|
|
||||||
|
public import tristanable.manager.manager : Manager;
|
|
@ -0,0 +1,44 @@
|
||||||
|
module tristanable.manager.watcher;
|
||||||
|
|
||||||
|
import core.thread : Thread;
|
||||||
|
import tristanable.manager.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;
|
||||||
|
|
||||||
|
// TODO: make package-level in a way such
|
||||||
|
// ... that only Manager can access this constructor
|
||||||
|
// TODO: Add constructor doc
|
||||||
|
package this(Manager manager, Socket socket)
|
||||||
|
{
|
||||||
|
this.manager = manager;
|
||||||
|
this.socket = socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void watch()
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// TODO: Implement me
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,30 @@
|
||||||
*/
|
*/
|
||||||
module tristanable;
|
module tristanable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface which manages a provided socket
|
||||||
|
* and enqueuing and dequeuing of queues
|
||||||
|
*/
|
||||||
|
public import tristanable.manager;
|
||||||
|
|
||||||
public import tristanable.manager : Manager;
|
// TODO: In future make `QueueItem` just `TaggedMessage`
|
||||||
|
/**
|
||||||
|
* A queue of queue items all of the same tag
|
||||||
|
*/
|
||||||
public import tristanable.queue : Queue;
|
public import tristanable.queue : Queue;
|
||||||
public import tristanable.queueitem : QueueItem;
|
|
||||||
|
/**
|
||||||
|
* A decoded item that is placed on the queue
|
||||||
|
* for consumption
|
||||||
|
*/
|
||||||
|
public import tristanable.queueitem : QueueItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error handling type definitions
|
||||||
|
*/
|
||||||
|
public import tristanable.exceptions : TristanableException, Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoding/decoding of the tristanable format
|
||||||
|
*/
|
||||||
|
public import tristanable.encoding : TaggedMessage;
|
||||||
|
|
Loading…
Reference in New Issue