CoapRequest

- Now takes in the original request packet, `CoapPacket` instead of the token
- Added `getToken()` to fetch the token (for matching purposes)
- Added `getRequestPacket()` to obtain the original request

CoapClient

- Use `getToken()`
- Pass the `CoapPacket` in rather
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-22 15:40:11 +02:00
parent 497dabf6bf
commit 2716fd3986
2 changed files with 18 additions and 8 deletions

View File

@ -151,7 +151,7 @@ public class CoapClient
CoapRequestFuture future = new CoapRequestFuture();
// Link the CoapRequest to the future so it can be signalled
CoapRequest request = new CoapRequest(requestPacket.getToken(), future);
CoapRequest request = new CoapRequest(requestPacket, future);
// Store the request
storeRequest(request);
@ -194,7 +194,7 @@ public class CoapClient
foreach(CoapRequest request; outgoingRequests)
{
if(request.token == token)
if(request.getToken() == token)
{
foundRequest = request;
break;

View File

@ -21,10 +21,10 @@ import doap.exceptions;
package class CoapRequest
{
/**
* The token to be able to match a response
* to
* The original packet (to be able to access the token
* such that we can match it up with a respnse)
*/
package ubyte[] token;
private CoapPacket requestPacket;
/**
* The future which we can fill up with the
@ -36,15 +36,25 @@ package class CoapRequest
* Constructs a new request
*
* Params:
* token = the token
* requestPacket = the actual request
* future = the `CoapRequestFuture` to wake up
* on data arrival
*/
this(ubyte[] token, CoapRequestFuture future)
this(CoapPacket requestPacket, CoapRequestFuture future)
{
this.token = token;
this.requestPacket = requestPacket;
this.future = future;
}
public CoapPacket getRequestPacket()
{
return this.requestPacket;
}
public ubyte[] getToken()
{
return this.requestPacket.getToken();
}
}
/**