From e354a33bcbf5554ae4bce14d3dd7c3ee21f9f23f Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Fri, 22 Sep 2023 18:00:49 +0200 Subject: [PATCH] CoapMessagingLayer - Now inherits from `CoapMessagingLayerFR` - Migrated to it CoapClient - Migrated to `CoapMessagingLayerFR` --- source/doap/client/client.d | 5 +++-- source/doap/client/messaging.d | 30 ++++++++---------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/source/doap/client/client.d b/source/doap/client/client.d index df3232c..3e83367 100644 --- a/source/doap/client/client.d +++ b/source/doap/client/client.d @@ -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); diff --git a/source/doap/client/messaging.d b/source/doap/client/messaging.d index 6847e4e..014e16a 100644 --- a/source/doap/client/messaging.d +++ b/source/doap/client/messaging.d @@ -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()~"'");