Adding status enum to Clients; Added interface for these statuses

This commit is contained in:
Heath Volmer
2016-09-26 14:46:50 -06:00
parent a99a69b4bb
commit 69802c8bc5
10 changed files with 53 additions and 38 deletions

View File

@@ -10,7 +10,7 @@ namespace PepperDash.Core
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class GenericSshClient : Device, IBasicCommunication, IAutoReconnect public class GenericSshClient : Device, ISocketStatus, IAutoReconnect
{ {
/// <summary> /// <summary>
/// Event that fires when data is received. Delivers args with byte array /// Event that fires when data is received. Delivers args with byte array
@@ -27,6 +27,10 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public event EventHandler<SshConnectionChangeEventArgs> ConnectionChange; public event EventHandler<SshConnectionChangeEventArgs> ConnectionChange;
public event Crestron.SimplSharp.CrestronSockets.TCPClientSocketStatusChangeEventHandler SocketStatusChange;
/// <summary> /// <summary>
/// Address of server /// Address of server
/// </summary> /// </summary>
@@ -55,6 +59,15 @@ namespace PepperDash.Core
// returns false if no client or not connected // returns false if no client or not connected
get { return UStatus == 2; } get { return UStatus == 2; }
} }
/// <summary>
///
/// </summary>
public Crestron.SimplSharp.CrestronSockets.SocketStatus ClientStatus
{
get { throw new NotImplementedException(); }
}
/// <summary> /// <summary>
/// Contains the familiar Simpl analog status values. This drives the ConnectionChange event /// Contains the familiar Simpl analog status values. This drives the ConnectionChange event
/// and IsConnected with be true when this == 2. /// and IsConnected with be true when this == 2.

View File

@@ -11,7 +11,7 @@ using Newtonsoft.Json.Linq;
namespace PepperDash.Core namespace PepperDash.Core
{ {
public class GenericTcpIpClient : Device, IBasicCommunication, IAutoReconnect public class GenericTcpIpClient : Device, ISocketStatus, IAutoReconnect
{ {
/// <summary> /// <summary>
/// ///
@@ -23,6 +23,11 @@ namespace PepperDash.Core
/// </summary> /// </summary>
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived; public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
/// <summary>
///
/// </summary>
public event TCPClientSocketStatusChangeEventHandler SocketStatusChange;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@@ -82,7 +87,7 @@ namespace PepperDash.Core
: base(key) : base(key)
{ {
Client = new TCPClient(address, port, bufferSize); Client = new TCPClient(address, port, bufferSize);
Client.SocketStatusChange += new TCPClientSocketStatusChangeEventHandler(Client_SocketStatusChange); Client.SocketStatusChange += Client_SocketStatusChange;
} }
//public override bool CustomActivate() //public override bool CustomActivate()
@@ -175,40 +180,23 @@ namespace PepperDash.Core
void Client_SocketStatusChange(TCPClient client, SocketStatus clientSocketStatus) void Client_SocketStatusChange(TCPClient client, SocketStatus clientSocketStatus)
{ {
Debug.Console(2, this, "Socket status change {0} ({1})", clientSocketStatus, UClientStatus); Debug.Console(2, this, "Socket status change {0} ({1})", clientSocketStatus, UClientStatus);
if (client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED && !DisconnectCalledByUser) if (client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED && !DisconnectCalledByUser)
WaitAndTryReconnect(); WaitAndTryReconnect();
// Probably doesn't need to be a switch since all other cases were eliminated
switch (clientSocketStatus) switch (clientSocketStatus)
{ {
case SocketStatus.SOCKET_STATUS_BROKEN_LOCALLY:
break;
case SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY:
break;
case SocketStatus.SOCKET_STATUS_CONNECTED: case SocketStatus.SOCKET_STATUS_CONNECTED:
Client.ReceiveDataAsync(Receive); Client.ReceiveDataAsync(Receive);
DisconnectCalledByUser = false; DisconnectCalledByUser = false;
break; break;
case SocketStatus.SOCKET_STATUS_CONNECT_FAILED:
break;
case SocketStatus.SOCKET_STATUS_DNS_FAILED:
break;
case SocketStatus.SOCKET_STATUS_DNS_LOOKUP:
break;
case SocketStatus.SOCKET_STATUS_DNS_RESOLVED:
break;
case SocketStatus.SOCKET_STATUS_LINK_LOST:
break;
case SocketStatus.SOCKET_STATUS_NO_CONNECT:
break;
case SocketStatus.SOCKET_STATUS_SOCKET_NOT_EXIST:
break;
case SocketStatus.SOCKET_STATUS_WAITING:
break;
default:
break;
} }
// Relay the event
var handler = SocketStatusChange;
if (handler != null)
SocketStatusChange(client, clientSocketStatus);
} }
} }

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronSockets;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -23,6 +24,17 @@ namespace PepperDash.Core
void Connect(); void Connect();
} }
/// <summary>
/// For IBasicCommunication classes that have SocketStatus. GenericSshClient,
/// GenericTcpIpClient
/// </summary>
public interface ISocketStatus : IBasicCommunication
{
event TCPClientSocketStatusChangeEventHandler SocketStatusChange;
SocketStatus ClientStatus { get; }
}
public interface IAutoReconnect public interface IAutoReconnect
{ {
bool AutoReconnect { get; set; } bool AutoReconnect { get; set; }
@@ -78,6 +90,8 @@ namespace PepperDash.Core
public GenericCommMethodReceiveTextArgs() { } public GenericCommMethodReceiveTextArgs() { }
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@@ -85,7 +85,7 @@
<Programmer /> <Programmer />
<ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename> <ArchiveFilename>C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz</ArchiveFilename>
<MinFirmwareVersion>1.007.0017</MinFirmwareVersion> <MinFirmwareVersion>1.007.0017</MinFirmwareVersion>
<CompiledOn>9/26/2016 8:35:29 AM</CompiledOn> <CompiledOn>9/26/2016 9:02:28 AM</CompiledOn>
<AdditionalInfo /> <AdditionalInfo />
<EmbedSourceArchive>False</EmbedSourceArchive> <EmbedSourceArchive>False</EmbedSourceArchive>
<CopyTo /> <CopyTo />

View File

@@ -10,7 +10,7 @@
<ArchiveName /> <ArchiveName />
</RequiredInfo> </RequiredInfo>
<OptionalInfo> <OptionalInfo>
<CompiledOn>9/26/2016 8:35:29 AM</CompiledOn> <CompiledOn>9/26/2016 9:02:28 AM</CompiledOn>
<CompilerRev>1.0.0.13663</CompilerRev> <CompilerRev>1.0.0.14473</CompilerRev>
</OptionalInfo> </OptionalInfo>
</ProgramInfo> </ProgramInfo>

View File

@@ -1,4 +1,4 @@
MainAssembly=PepperDash_Core.dll:03807ccdf300afd429e7566545de5e6c MainAssembly=PepperDash_Core.dll:ddd7e6504766069b1c909eac0c499966
MainAssemblyMinFirmwareVersion=1.007.0017 MainAssemblyMinFirmwareVersion=1.007.0017
ü ü
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896 DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896