-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interfaces, optimize performance, fix QoS level 2
- Loading branch information
Showing
27 changed files
with
198 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using MQTTnet.Core.Packets; | ||
|
||
namespace MQTTnet.Core.Client | ||
{ | ||
public interface IMqttClient | ||
{ | ||
bool IsConnected { get; } | ||
|
||
event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived; | ||
event EventHandler Connected; | ||
event EventHandler Disconnected; | ||
|
||
Task ConnectAsync(MqttApplicationMessage willApplicationMessage = null); | ||
Task DisconnectAsync(); | ||
Task PublishAsync(MqttApplicationMessage applicationMessage); | ||
Task<IList<MqttSubscribeResult>> SubscribeAsync(IList<TopicFilter> topicFilters); | ||
Task<IList<MqttSubscribeResult>> SubscribeAsync(params TopicFilter[] topicFilters); | ||
Task Unsubscribe(IList<string> topicFilters); | ||
Task Unsubscribe(params string[] topicFilters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...re/Packets/IPacketWithPacketIdentifier.cs → ...Core/Packets/IMqttPacketWithIdentifier.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
using System; | ||
|
||
namespace MQTTnet.Core.Packets | ||
namespace MQTTnet.Core.Packets | ||
{ | ||
public abstract class MqttBasePacket | ||
{ | ||
public TResponsePacket CreateResponse<TResponsePacket>() | ||
{ | ||
var responsePacket = Activator.CreateInstance<TResponsePacket>(); | ||
var responsePacketWithIdentifier = responsePacket as IPacketWithIdentifier; | ||
if (responsePacketWithIdentifier != null) | ||
{ | ||
var requestPacketWithIdentifier = this as IPacketWithIdentifier; | ||
if (requestPacketWithIdentifier == null) | ||
{ | ||
throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not."); | ||
} | ||
|
||
responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier; | ||
} | ||
|
||
return responsePacket; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace MQTTnet.Core.Packets | ||
{ | ||
public static class MqttPacketExtensions | ||
{ | ||
public static TResponsePacket CreateResponse<TResponsePacket>(this MqttBasePacket packet) | ||
{ | ||
if (packet == null) throw new ArgumentNullException(nameof(packet)); | ||
|
||
var responsePacket = Activator.CreateInstance<TResponsePacket>(); | ||
|
||
if (responsePacket is IMqttPacketWithIdentifier responsePacketWithIdentifier) | ||
{ | ||
var requestPacketWithIdentifier = packet as IMqttPacketWithIdentifier; | ||
if (requestPacketWithIdentifier == null) | ||
{ | ||
throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not."); | ||
} | ||
|
||
responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier; | ||
} | ||
|
||
return responsePacket; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using MQTTnet.Core.Adapter; | ||
|
||
namespace MQTTnet.Core.Server | ||
{ | ||
public interface IMqttServer | ||
{ | ||
event EventHandler<MqttApplicationMessageReceivedEventArgs> ApplicationMessageReceived; | ||
event EventHandler<MqttClientConnectedEventArgs> ClientConnected; | ||
|
||
IList<string> GetConnectedClients(); | ||
void InjectClient(string identifier, IMqttCommunicationAdapter adapter); | ||
void Publish(MqttApplicationMessage applicationMessage); | ||
void Start(); | ||
void Stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.