diff --git a/source/tasky/engine.d b/source/tasky/engine.d index 3cdd4f6..a0b7ebd 100644 --- a/source/tasky/engine.d +++ b/source/tasky/engine.d @@ -1,2 +1,35 @@ module tasky.engine; +import tristanable : Manager, Queue, TaggedMessage; +import tasky.request : Request; + +public class Engine +{ + private Manager tManager; + + this(Manager tristanableManager) + { + this.tManager = tristanableManager; + } + + // TODO: Continue working on this + + public void makeRequest(Request req) + { + /* Get a unique queue */ + Queue newQueue = tManager.getUniqueQueue(); + + /* Create a tagged message with the tag */ + ulong tag = newQueue.getID(); + TaggedMessage tReq = new TaggedMessage(tag, req.getRequestData()); + + /* Send the message */ + tManager.sendMessage(tReq); + + /* Await for a response */ + byte[] resp = newQueue.dequeue().getPayload(); + + /* Run the response handler with the response */ + req.process(resp); + } +} \ No newline at end of file diff --git a/source/tasky/package.d b/source/tasky/package.d index 05da23b..fad8859 100644 --- a/source/tasky/package.d +++ b/source/tasky/package.d @@ -1,3 +1,4 @@ module tasky; -public import tasky.engine; \ No newline at end of file +public import tasky.engine; +public import tasky.request : Request, ResponseHandler; \ No newline at end of file diff --git a/source/tasky/request.d b/source/tasky/request.d new file mode 100644 index 0000000..d1b33f9 --- /dev/null +++ b/source/tasky/request.d @@ -0,0 +1,30 @@ +module tasky.request; + +import tristanable.encoding : TaggedMessage; + +public alias ResponseHandler = void function(byte[]); + +public abstract class Request +{ + private byte[] requestMessage; + + // TODO: Define the below with an alias for a function pointer that accepts a byte[] (the response data) + + private ResponseHandler respFunc; + + protected this(byte[] requestMessage, ResponseHandler respFunc) + { + this.requestMessage = requestMessage; + this.respFunc = respFunc; + } + + package final byte[] getRequestData() + { + return requestMessage; + } + + package final void process(byte[] responseData) + { + respFunc(responseData); + } +} \ No newline at end of file