CoapMessagingLayer

- Now inherits from `CoapMessagingLayerFR`
- Migrated to it

CoapClient

- Migrated to `CoapMessagingLayerFR`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-22 18:00:49 +02:00
parent 013886c79f
commit e354a33bcb
2 changed files with 11 additions and 24 deletions

View File

@ -2,6 +2,7 @@ module doap.client.client;
import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parseAddress, InternetAddress, SocketShutdown;
import doap.client.messaging : CoapMessagingLayer;
import doap.client.mesglayer : CoapMessagingLayerFR;
import doap.protocol;
import doap.client.request : CoapRequestBuilder, CoapRequest, CoapRequestFuture;
import core.sync.mutex : Mutex;
@ -28,7 +29,7 @@ public class CoapClient
* The messaging layer which provides
* request-response message match-ups
*/
private CoapMessagingLayer messaging;
private CoapMessagingLayerFR messaging;
/**
* The request-response match list
@ -55,7 +56,7 @@ public class CoapClient
this(Address address)
{
this.address = address;
this.messaging = new CoapMessagingLayer(this);
this.messaging = new CoapMessagingLayer(this); //UDP transport
this.requestsLock = new Mutex();
this.watcherSignal = new Condition(this.requestsLock);

View File

@ -15,6 +15,8 @@ import std.socket : Address;
import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parseAddress, InternetAddress, SocketShutdown;
import doap.client.mesglayer : CoapMessagingLayerFR;
// TODO: Generalize this and then make
// ... a UDP version of it
@ -25,13 +27,8 @@ import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parse
* Handles the actual sending and receiving
* of datagrams and fulfilling of requests
*/
class CoapMessagingLayer
public class CoapMessagingLayer : CoapMessagingLayerFR
{
/**
* The client
*/
private CoapClient client;
/**
* Reading-loop thread
*/
@ -56,18 +53,7 @@ class CoapMessagingLayer
*/
this(CoapClient client)
{
this.client = client;
}
/**
* Retrieves the CoAP endpoint the client is
* connected to
*
* Returns: the endpoint address
*/
protected final Address getEndpointAddress() // Final in Interface
{
return this.client.address;
super(client);
}
/**
@ -75,7 +61,7 @@ class CoapMessagingLayer
* the underlying transport and then the
* reader loop
*/
public void begin() // Candidate for Interface
public override void begin() // Candidate for Interface
{
// TODO: Handle socket errors nicely?
@ -100,7 +86,7 @@ class CoapMessagingLayer
* packet = the `CoapPacket`
* to transmit
*/
public void send(CoapPacket packet) // Candidate for Interface
public override void send(CoapPacket packet) // Candidate for Interface
{
// Encode the packet and send the bytes
ubyte[] encodedPacket = packet.getBytes();
@ -116,7 +102,7 @@ class CoapMessagingLayer
* Blocks till the reading loop
* has terminated
*/
public void close() // Candidate for Interface
public override void close() // Candidate for Interface
{
// Set status to not running
this.running = false;
@ -217,7 +203,7 @@ class CoapMessagingLayer
*/
private void handlePacket(CoapPacket packet)
{
CoapRequest request = this.client.yankRequest(packet.getToken());
CoapRequest request = getClient().yankRequest(packet.getToken());
if(request)
{
writeln("Matched response '"~packet.toString()~"' to request '"~request.toString()~"'");