From b94c5fbb3599909b8e1a3ee3669881afd2342b80 Mon Sep 17 00:00:00 2001 From: Iker Celorrio Date: Tue, 13 Dec 2022 13:39:51 +0100 Subject: [PATCH] Improve ISmppClient interface --- AberrantSMPP/ISmppClient.cs | 45 ++++++++++++++++++- AberrantSMPP/SMPPCommunicator.cs | 13 +++++- TestClient/Facilities/ISmppClientAdapter.cs | 2 - .../Facilities/SMPPCommunicatorAdapter.cs | 2 - 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/AberrantSMPP/ISmppClient.cs b/AberrantSMPP/ISmppClient.cs index a0c384c..f17d234 100644 --- a/AberrantSMPP/ISmppClient.cs +++ b/AberrantSMPP/ISmppClient.cs @@ -16,18 +16,18 @@ * along with AberrantSMPP. If not, see . */ using System; +using System.Collections.Generic; using System.Security.Authentication; using AberrantSMPP.EventObjects; using AberrantSMPP.Packet; using AberrantSMPP.Packet.Request; +using AberrantSMPP.Packet.Response; namespace AberrantSMPP { public interface ISmppClient : IDisposable { - // FIXME: This should expose all that is common to both Smpp client implementations.. - /// /// The host to bind this ISmppClient to. /// @@ -99,6 +99,47 @@ public interface ISmppClient : IDisposable /// bool DisableSslRevocationChecking { get; } + /// + /// Gets or sets the response timeout (in miliseconds) + /// + /// The response timeout. + TimeSpan ResponseTimeout { get; set; } + + /// + /// Sends a user-specified Pdu(see the RoaminSMPP base library for + /// Pdu types). This allows complete flexibility for sending Pdus. + /// + /// The Pdu to send. + /// The sequence number of the sent PDU, or null if failed. + uint SendPdu(Pdu packet); + + /// + /// Sends a request and waits for the appropriate response. + /// If no response is received before RequestTimeout seconds, an + /// SmppTimeoutException is thrown. + /// If a response is received w/ CommandStatus != OK, an + /// SmppRequestException is thrown. + /// + /// The request. + SmppResponse SendAndWait(SmppRequest request); + + /// + /// Sends an SMS message synchronouslly, possibly splitting it on multiple PDUs + /// using the specified segmentation & reassembly method. + /// + /// The list of messageIds assigned by remote party to each submitted PDU. + IEnumerable SendAndWait(IEnumerable requests); + + /// + /// Sends an SMS message synchronouslly, possibly splitting it on multiple PDUs + /// using the specified segmentation & reassembly method. + /// + /// The pdu. + /// The method. + /// The list of messageIds assigned by remote party to each submitted PDU. + IEnumerable SendAndWait(SmppSubmitSm pdu, SmppSarMethod method); + + #region events /// /// Event called when the client receives a bind response. diff --git a/AberrantSMPP/SMPPCommunicator.cs b/AberrantSMPP/SMPPCommunicator.cs index 53d8d0c..39fbfa8 100644 --- a/AberrantSMPP/SMPPCommunicator.cs +++ b/AberrantSMPP/SMPPCommunicator.cs @@ -1,4 +1,4 @@ -/* AberrantSMPP: SMPP communication library +/* AberrantSMPP: SMPP communication library * Copyright (C) 2004, 2005 Christopher M. Bouzek * Copyright (C) 2010, 2011 Pablo Ruiz García * @@ -1309,6 +1309,17 @@ protected override void Dispose(bool disposing) } base.Dispose(disposing); + } + + #region explicit ISmppClient adapter methods + TimeSpan ISmppClient.ResponseTimeout + { + get => TimeSpan.FromMilliseconds(ResponseTimeout); + set => ResponseTimeout = (int)value.TotalMilliseconds; } + SmppResponse ISmppClient.SendAndWait(SmppRequest request) => SendRequest(request); + IEnumerable ISmppClient.SendAndWait(IEnumerable requests) => SendRequests(requests); + IEnumerable ISmppClient.SendAndWait(SmppSubmitSm pdu, SmppSarMethod method) => Send(pdu, method); + #endregion } } diff --git a/TestClient/Facilities/ISmppClientAdapter.cs b/TestClient/Facilities/ISmppClientAdapter.cs index f6a9f21..44a1af1 100644 --- a/TestClient/Facilities/ISmppClientAdapter.cs +++ b/TestClient/Facilities/ISmppClientAdapter.cs @@ -15,8 +15,6 @@ internal interface ISmppClientAdapter : ISmppClient //void Connect(); //void Disconnect(); bool IsClientReady(); - SmppResponse SendAndWait(SmppRequest request); - uint SendPdu(Pdu packet); SmppClientStatus Status { get; } } } diff --git a/TestClient/Facilities/SMPPCommunicatorAdapter.cs b/TestClient/Facilities/SMPPCommunicatorAdapter.cs index ee20f75..4a727d9 100644 --- a/TestClient/Facilities/SMPPCommunicatorAdapter.cs +++ b/TestClient/Facilities/SMPPCommunicatorAdapter.cs @@ -12,8 +12,6 @@ public void Configure() // intentionally empty } - public SmppResponse SendAndWait(SmppRequest request) => SendRequest(request); - public void Start() => _bound = Bind(); public void Stop()