mirror of
https://github.com/deavmi/doap
synced 2024-07-04 16:10:15 +02:00
CoapMessagingLayer
- Now inherits from `CoapMessagingLayerFR` - Migrated to it CoapClient - Migrated to `CoapMessagingLayerFR`
This commit is contained in:
parent
013886c79f
commit
e354a33bcb
|
@ -2,6 +2,7 @@ module doap.client.client;
|
||||||
|
|
||||||
import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parseAddress, InternetAddress, SocketShutdown;
|
import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parseAddress, InternetAddress, SocketShutdown;
|
||||||
import doap.client.messaging : CoapMessagingLayer;
|
import doap.client.messaging : CoapMessagingLayer;
|
||||||
|
import doap.client.mesglayer : CoapMessagingLayerFR;
|
||||||
import doap.protocol;
|
import doap.protocol;
|
||||||
import doap.client.request : CoapRequestBuilder, CoapRequest, CoapRequestFuture;
|
import doap.client.request : CoapRequestBuilder, CoapRequest, CoapRequestFuture;
|
||||||
import core.sync.mutex : Mutex;
|
import core.sync.mutex : Mutex;
|
||||||
|
@ -28,7 +29,7 @@ public class CoapClient
|
||||||
* The messaging layer which provides
|
* The messaging layer which provides
|
||||||
* request-response message match-ups
|
* request-response message match-ups
|
||||||
*/
|
*/
|
||||||
private CoapMessagingLayer messaging;
|
private CoapMessagingLayerFR messaging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The request-response match list
|
* The request-response match list
|
||||||
|
@ -55,7 +56,7 @@ public class CoapClient
|
||||||
this(Address address)
|
this(Address address)
|
||||||
{
|
{
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.messaging = new CoapMessagingLayer(this);
|
this.messaging = new CoapMessagingLayer(this); //UDP transport
|
||||||
|
|
||||||
this.requestsLock = new Mutex();
|
this.requestsLock = new Mutex();
|
||||||
this.watcherSignal = new Condition(this.requestsLock);
|
this.watcherSignal = new Condition(this.requestsLock);
|
||||||
|
|
|
@ -15,6 +15,8 @@ import std.socket : Address;
|
||||||
|
|
||||||
import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parseAddress, InternetAddress, SocketShutdown;
|
import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parseAddress, InternetAddress, SocketShutdown;
|
||||||
|
|
||||||
|
import doap.client.mesglayer : CoapMessagingLayerFR;
|
||||||
|
|
||||||
// TODO: Generalize this and then make
|
// TODO: Generalize this and then make
|
||||||
// ... a UDP version of it
|
// ... a UDP version of it
|
||||||
|
|
||||||
|
@ -25,13 +27,8 @@ import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parse
|
||||||
* Handles the actual sending and receiving
|
* Handles the actual sending and receiving
|
||||||
* of datagrams and fulfilling of requests
|
* of datagrams and fulfilling of requests
|
||||||
*/
|
*/
|
||||||
class CoapMessagingLayer
|
public class CoapMessagingLayer : CoapMessagingLayerFR
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The client
|
|
||||||
*/
|
|
||||||
private CoapClient client;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reading-loop thread
|
* Reading-loop thread
|
||||||
*/
|
*/
|
||||||
|
@ -56,18 +53,7 @@ class CoapMessagingLayer
|
||||||
*/
|
*/
|
||||||
this(CoapClient client)
|
this(CoapClient client)
|
||||||
{
|
{
|
||||||
this.client = client;
|
super(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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +61,7 @@ class CoapMessagingLayer
|
||||||
* the underlying transport and then the
|
* the underlying transport and then the
|
||||||
* reader loop
|
* reader loop
|
||||||
*/
|
*/
|
||||||
public void begin() // Candidate for Interface
|
public override void begin() // Candidate for Interface
|
||||||
{
|
{
|
||||||
// TODO: Handle socket errors nicely?
|
// TODO: Handle socket errors nicely?
|
||||||
|
|
||||||
|
@ -100,7 +86,7 @@ class CoapMessagingLayer
|
||||||
* packet = the `CoapPacket`
|
* packet = the `CoapPacket`
|
||||||
* to transmit
|
* 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
|
// Encode the packet and send the bytes
|
||||||
ubyte[] encodedPacket = packet.getBytes();
|
ubyte[] encodedPacket = packet.getBytes();
|
||||||
|
@ -116,7 +102,7 @@ class CoapMessagingLayer
|
||||||
* Blocks till the reading loop
|
* Blocks till the reading loop
|
||||||
* has terminated
|
* has terminated
|
||||||
*/
|
*/
|
||||||
public void close() // Candidate for Interface
|
public override void close() // Candidate for Interface
|
||||||
{
|
{
|
||||||
// Set status to not running
|
// Set status to not running
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
@ -217,7 +203,7 @@ class CoapMessagingLayer
|
||||||
*/
|
*/
|
||||||
private void handlePacket(CoapPacket packet)
|
private void handlePacket(CoapPacket packet)
|
||||||
{
|
{
|
||||||
CoapRequest request = this.client.yankRequest(packet.getToken());
|
CoapRequest request = getClient().yankRequest(packet.getToken());
|
||||||
if(request)
|
if(request)
|
||||||
{
|
{
|
||||||
writeln("Matched response '"~packet.toString()~"' to request '"~request.toString()~"'");
|
writeln("Matched response '"~packet.toString()~"' to request '"~request.toString()~"'");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user