Compare commits

...

4 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire a51df3b699 Engine
- If a `Request` is not expecting a response then do not call `dequeue()` on the `Queue` registered nor `process`byte[])`
- Added a TODO comment
2023-05-04 14:17:35 +02:00
Tristan B. Velloza Kildaire 8387d0ee78 Request
- Implemented `expectsResponse()` which returns `false` if no response handler is assigned (implying no response is expected), `true` otherwise
2023-05-04 14:15:19 +02:00
Tristan B. Velloza Kildaire 7af21a909a Request
- Allow constructing WITHOUT a `ResponseHandler` (it remains as `null)
2023-05-04 11:04:32 +02:00
Tristan B. Velloza Kildaire 7072c852dc Request
- Removed now-completed TODO
2023-05-04 11:03:11 +02:00
2 changed files with 21 additions and 6 deletions

View File

@ -14,6 +14,8 @@ public class Engine
// TODO: Continue working on this // TODO: Continue working on this
// TODO: Allow registering ResponseAnonymous with handlers etc
/** /**
* Takes a request and sends it through to the endpoint * Takes a request and sends it through to the endpoint
* afterwhich we block for a response and when we get one * afterwhich we block for a response and when we get one
@ -35,11 +37,16 @@ public class Engine
/* Send the message */ /* Send the message */
tManager.sendMessage(tReq); tManager.sendMessage(tReq);
/* Await for a response */ /* Does this Request expect a response? */
byte[] resp = newQueue.dequeue().getPayload(); // TODO: We need not register the queue even if this is the case
if(req.expectsResponse())
{
/* Await for a response */
byte[] resp = newQueue.dequeue().getPayload();
/* Run the response handler with the response */ /* Run the response handler with the response */
req.process(resp); req.process(resp);
}
/* De-register the queue */ /* De-register the queue */
tManager.releaseQueue(newQueue); tManager.releaseQueue(newQueue);

View File

@ -7,8 +7,6 @@ public alias ResponseHandler = void function(byte[]);
public abstract class Request public abstract class Request
{ {
private byte[] requestMessage; private byte[] requestMessage;
// TODO: Define the below with an alias for a function pointer that accepts a byte[] (the response data)
private ResponseHandler respFunc; private ResponseHandler respFunc;
@ -18,6 +16,11 @@ public abstract class Request
this.respFunc = respFunc; this.respFunc = respFunc;
} }
protected this(byte[] requestMessage)
{
this(requestMessage, null);
}
package final byte[] getRequestData() package final byte[] getRequestData()
{ {
return requestMessage; return requestMessage;
@ -27,4 +30,9 @@ public abstract class Request
{ {
respFunc(responseData); respFunc(responseData);
} }
package final bool expectsResponse()
{
return respFunc !is null;
}
} }