Skip to content

Commit

Permalink
update api
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Nov 24, 2023
1 parent 6ae23c8 commit d118c61
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 40 deletions.
4 changes: 2 additions & 2 deletions bin/mqtt5_canary/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,14 @@ static int s_AwsMqtt5CanaryOperationSubscribe(struct AwsMqtt5CanaryTestClient *t
.WithNoLocal(false)
.WithQOS(Mqtt5::QOS::AWS_MQTT5_QOS_AT_LEAST_ONCE)
.WithRetainHandlingType(Mqtt5::RetainHandlingType::AWS_MQTT5_RHT_SEND_ON_SUBSCRIBE)
.WithRetain(false);
.WithRetainAsPublished(false);

Mqtt5::Subscription subscription2;
subscription2.WithTopicFilter(testClient->sharedTopic)
.WithNoLocal(false)
.WithQOS(Mqtt5::QOS::AWS_MQTT5_QOS_AT_LEAST_ONCE)
.WithRetainHandlingType(Mqtt5::RetainHandlingType::AWS_MQTT5_RHT_SEND_ON_SUBSCRIBE)
.WithRetain(false);
.WithRetainAsPublished(false);

std::shared_ptr<Mqtt5::SubscribePacket> packet = std::make_shared<Mqtt5::SubscribePacket>(allocator);
packet->WithSubscription(std::move(subscription1));
Expand Down
16 changes: 14 additions & 2 deletions include/aws/crt/mqtt/Mqtt5Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,27 @@ namespace Aws
*/
Mqtt5ClientOptions &WithConnackTimeoutMs(uint32_t connackTimeoutMs) noexcept;

/**
* @deprecated The function is deprecated, please use `WithAckTimeoutSec`
*
* Sets Operation Timeout(Seconds). Time interval to wait for an ack after sending a QoS 1+ PUBLISH,
* SUBSCRIBE, or UNSUBSCRIBE before failing the operation.
*
* @param ackTimeoutSec
*
* @return this option object
*/
Mqtt5ClientOptions &WithAckTimeoutSeconds(uint32_t ackTimeoutSec) noexcept;

/**
* Sets Operation Timeout(Seconds). Time interval to wait for an ack after sending a QoS 1+ PUBLISH,
* SUBSCRIBE, or UNSUBSCRIBE before failing the operation.
*
* @param ackTimeoutSeconds
* @param ackTimeoutSec
*
* @return this option object
*/
Mqtt5ClientOptions &WithAckTimeoutSeconds(uint32_t ackTimeoutSeconds) noexcept;
Mqtt5ClientOptions &WithAckTimeoutSec(uint32_t ackTimeoutSec) noexcept;

/**
* Sets callback for transform HTTP request.
Expand Down
34 changes: 27 additions & 7 deletions include/aws/crt/mqtt/Mqtt5Packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,17 @@ namespace Aws
uint16_t getReceiveMaximumFromServer() const noexcept;

/**
* @deprecated the function is deprecated, please use `getMaximumPacketSizeToServer`
*
* @return The maximum packet size the server is willing to accept.
*/
uint32_t getMaximumPacketSizeBytes() const noexcept;

/**
* @return The maximum packet size the server is willing to accept.
*/
uint32_t getMaximumPacketSizeToServer() const noexcept;

/**
* @return returns the maximum allowed topic alias value on publishes sent from client to server
*/
Expand All @@ -521,7 +528,7 @@ namespace Aws
*
* @return The maximum amount of time in seconds between client packets.
*/
uint16_t getServerKeepAlive() const noexcept;
uint16_t getServerKeepAliveSec() const noexcept;

/**
* @return Whether the server supports retained messages.
Expand Down Expand Up @@ -939,6 +946,8 @@ namespace Aws
const Crt::Optional<uint16_t> &getReceiveMaximum() const noexcept;

/**
* @deprecated The function is deprecated, please use `getMaximumPacketSizeToServer`
*
* Notifies the server of the maximum packet size the client is willing to handle. If
* omitted or null, then no limit beyond the natural limits of MQTT packet size is requested.
*
Expand All @@ -949,6 +958,17 @@ namespace Aws
*/
const Crt::Optional<uint32_t> &getMaximumPacketSizeBytes() const noexcept;

/**
* Notifies the server of the maximum packet size the client is willing to handle. If
* omitted or null, then no limit beyond the natural limits of MQTT packet size is requested.
*
* See [MQTT5 Maximum Packet
* Size](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901050)
*
* @return The maximum packet size the client is willing to handle
*/
const Crt::Optional<uint32_t> &getMaximumPacketSizeToServer() const noexcept;

/**
* A time interval, in seconds, that the server should wait (for a session reconnection) before sending
* the will message associated with the connection's session. If omitted or null, the server will send
Expand Down Expand Up @@ -1175,7 +1195,7 @@ namespace Aws
* @return A time interval, in seconds, that the server will persist this connection's MQTT session
* state for.
*/
const Crt::Optional<uint32_t> &getSessionExpiryInterval() const noexcept;
const Crt::Optional<uint32_t> &getSessionExpiryIntervalSec() const noexcept;

/**
* The maximum amount of in-flight QoS 1 or 2 messages that the server is willing to handle at once. If
Expand Down Expand Up @@ -1304,7 +1324,7 @@ namespace Aws
*
* @return Server-requested override of the keep alive interval, in seconds
*/
const Crt::Optional<uint16_t> &getServerKeepAlive() const noexcept;
const Crt::Optional<uint16_t> &getServerKeepAliveSec() const noexcept;

/**
* A value that can be used in the creation of a response topic associated with this connection.
Expand Down Expand Up @@ -1360,7 +1380,7 @@ namespace Aws
* See [MQTT5 Session Expiry
* Interval](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901082)
*/
Crt::Optional<uint32_t> m_sessionExpiryInterval;
Crt::Optional<uint32_t> m_sessionExpiryIntervalSec;

/**
* The maximum amount of in-flight QoS 1 or 2 messages that the server is willing to handle at once. If
Expand Down Expand Up @@ -1455,7 +1475,7 @@ namespace Aws
* See [MQTT5 Server Keep
* Alive](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901094)
*/
Crt::Optional<uint16_t> m_serverKeepAlive;
Crt::Optional<uint16_t> m_serverKeepAliveSec;

/**
* A value that can be used in the creation of a response topic associated with this connection.
Expand Down Expand Up @@ -1880,7 +1900,7 @@ namespace Aws
* @param retain bool
* @return The Subscription Object after setting the reason string.
*/
Subscription &WithRetain(bool retain) noexcept;
Subscription &WithRetainAsPublished(bool retain) noexcept;

/**
* Sets should messages sent due to this subscription keep the retain flag preserved on the message?
Expand Down Expand Up @@ -1937,7 +1957,7 @@ namespace Aws
* See [MQTT5 Subscription
* Options](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901169)
*/
bool m_retain;
bool m_retainAsPublished;

/**
* Should retained messages on matching topics be sent in reaction to this subscription? If undefined,
Expand Down
16 changes: 14 additions & 2 deletions include/aws/iot/Mqtt5Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,23 @@ namespace Aws
* Sets Operation Timeout(Seconds). Time interval to wait for an ack after sending a QoS 1+ PUBLISH,
* SUBSCRIBE, or UNSUBSCRIBE before failing the operation.
*
* @param ackTimeoutSeconds
* @param ackTimeoutSec
*
* @return this option object
*/
Mqtt5ClientBuilder &WithAckTimeoutSeconds(uint32_t ackTimeoutSeconds) noexcept;
Mqtt5ClientBuilder &WithAckTimeoutSec(uint32_t ackTimeoutSec) noexcept;

/**
* @deprecated the function is deprecated, please use `WithAckTimeoutSec`
*
* Sets Operation Timeout(Seconds). Time interval to wait for an ack after sending a QoS 1+ PUBLISH,
* SUBSCRIBE, or UNSUBSCRIBE before failing the operation.
*
* @param ackTimeoutSec
*
* @return this option object
*/
Mqtt5ClientBuilder &WithAckTimeoutSeconds(uint32_t ackTimeoutSec) noexcept;

/**
* Overrides the default SDK Name to send as a metric in the MQTT CONNECT packet.
Expand Down
12 changes: 9 additions & 3 deletions source/iot/Mqtt5Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ namespace Aws
Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithOfflineQueueBehavior(
ClientOperationQueueBehaviorType operationQueueBehavior) noexcept
{
m_options->WithAckTimeoutSeconds(operationQueueBehavior);
m_options->WithOfflineQueueBehavior(operationQueueBehavior);
return *this;
}

Expand Down Expand Up @@ -408,9 +408,15 @@ namespace Aws
return *this;
}

Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithAckTimeoutSeconds(uint32_t ackTimeoutSeconds) noexcept
Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithAckTimeoutSec(uint32_t ackTimeoutSec) noexcept
{
m_options->WithAckTimeoutSeconds(ackTimeoutSeconds);
m_options->WithAckTimeoutSec(ackTimeoutSec);
return *this;
}

Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithAckTimeoutSeconds(uint32_t ackTimeoutSec) noexcept
{
m_options->WithAckTimeoutSec(ackTimeoutSec);
return *this;
}

Expand Down
10 changes: 8 additions & 2 deletions source/mqtt/Mqtt5Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,15 @@ namespace Aws
return *this;
}

Mqtt5ClientOptions &Mqtt5ClientOptions::WithAckTimeoutSeconds(uint32_t ackTimeoutSeconds) noexcept
Mqtt5ClientOptions &Mqtt5ClientOptions::WithAckTimeoutSeconds(uint32_t ackTimeoutSec) noexcept
{
m_ackTimeoutSec = ackTimeoutSeconds;
m_ackTimeoutSec = ackTimeoutSec;
return *this;
}

Mqtt5ClientOptions &Mqtt5ClientOptions::WithAckTimeoutSec(uint32_t ackTimeoutSec) noexcept
{
m_ackTimeoutSec = ackTimeoutSec;
return *this;
}

Expand Down
39 changes: 23 additions & 16 deletions source/mqtt/Mqtt5Packets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ namespace Aws
return m_maximumPacketSizeBytes;
}

const Crt::Optional<uint32_t> &ConnectPacket::getMaximumPacketSizeToServer() const noexcept
{
return m_maximumPacketSizeBytes;
}

const Crt::Optional<uint32_t> &ConnectPacket::getWillDelayIntervalSec() const noexcept
{
return m_willDelayIntervalSeconds;
Expand Down Expand Up @@ -808,7 +813,7 @@ namespace Aws
{
m_sessionPresent = packet.session_present;
m_reasonCode = packet.reason_code;
setPacketOptional(m_sessionExpiryInterval, packet.session_expiry_interval);
setPacketOptional(m_sessionExpiryIntervalSec, packet.session_expiry_interval);
setPacketOptional(m_receiveMaximum, packet.receive_maximum);
setPacketOptional(m_maximumQOS, packet.maximum_qos);
setPacketOptional(m_retainAvailable, packet.retain_available);
Expand All @@ -820,7 +825,7 @@ namespace Aws
setPacketOptional(m_wildcardSubscriptionsAvailable, packet.wildcard_subscriptions_available);
setPacketOptional(m_subscriptionIdentifiersAvailable, packet.subscription_identifiers_available);
setPacketOptional(m_sharedSubscriptionsAvailable, packet.shared_subscriptions_available);
setPacketOptional(m_serverKeepAlive, packet.server_keep_alive);
setPacketOptional(m_serverKeepAliveSec, packet.server_keep_alive);
setPacketStringOptional(m_responseInformation, packet.response_information);
setPacketStringOptional(m_serverReference, packet.server_reference);
}
Expand All @@ -829,9 +834,9 @@ namespace Aws

ConnectReasonCode ConnAckPacket::getReasonCode() const noexcept { return m_reasonCode; }

const Crt::Optional<uint32_t> &ConnAckPacket::getSessionExpiryInterval() const noexcept
const Crt::Optional<uint32_t> &ConnAckPacket::getSessionExpiryIntervalSec() const noexcept
{
return m_sessionExpiryInterval;
return m_sessionExpiryIntervalSec;
}

const Crt::Optional<uint16_t> &ConnAckPacket::getReceiveMaximum() const noexcept
Expand Down Expand Up @@ -877,9 +882,9 @@ namespace Aws
return m_sharedSubscriptionsAvailable;
}

const Crt::Optional<uint16_t> &ConnAckPacket::getServerKeepAlive() const noexcept
const Crt::Optional<uint16_t> &ConnAckPacket::getServerKeepAliveSec() const noexcept
{
return m_serverKeepAlive;
return m_serverKeepAliveSec;
}

const Crt::Optional<String> &ConnAckPacket::getResponseInformation() const noexcept
Expand All @@ -894,14 +899,14 @@ namespace Aws

Subscription::Subscription(Allocator *allocator)
: m_allocator(allocator), m_topicFilter(""), m_qos(QOS::AWS_MQTT5_QOS_AT_MOST_ONCE), m_noLocal(false),
m_retain(false), m_retainHnadlingType(AWS_MQTT5_RHT_SEND_ON_SUBSCRIBE)
m_retainAsPublished(false), m_retainHnadlingType(AWS_MQTT5_RHT_SEND_ON_SUBSCRIBE)

{
}

Subscription::Subscription(Crt::String topicFilter, Mqtt5::QOS qos, Allocator *allocator)
: m_allocator(allocator), m_topicFilter(std::move(topicFilter)), m_qos(qos), m_noLocal(false),
m_retain(false), m_retainHnadlingType(AWS_MQTT5_RHT_SEND_ON_SUBSCRIBE)
m_retainAsPublished(false), m_retainHnadlingType(AWS_MQTT5_RHT_SEND_ON_SUBSCRIBE)
{
}

Expand All @@ -921,9 +926,9 @@ namespace Aws
m_noLocal = noLocal;
return *this;
}
Subscription &Subscription::WithRetain(bool retain) noexcept
Subscription &Subscription::WithRetainAsPublished(bool retain) noexcept
{
m_retain = retain;
m_retainAsPublished = retain;
return *this;
}
Subscription &Subscription::WithRetainHandlingType(RetainHandlingType retainHandlingType) noexcept
Expand All @@ -938,21 +943,21 @@ namespace Aws
raw_options.topic_filter = ByteCursorFromString(m_topicFilter);
raw_options.no_local = m_noLocal;
raw_options.qos = m_qos;
raw_options.retain_as_published = m_retain;
raw_options.retain_as_published = m_retainAsPublished;
raw_options.retain_handling_type = m_retainHnadlingType;
return true;
}

Subscription::Subscription(const Subscription &toCopy) noexcept
: m_allocator(toCopy.m_allocator), m_topicFilter(toCopy.m_topicFilter), m_qos(toCopy.m_qos),
m_noLocal(toCopy.m_noLocal), m_retain(toCopy.m_retain),
m_noLocal(toCopy.m_noLocal), m_retainAsPublished(toCopy.m_retainAsPublished),
m_retainHnadlingType(toCopy.m_retainHnadlingType)
{
}

Subscription::Subscription(Subscription &&toMove) noexcept
: m_allocator(toMove.m_allocator), m_topicFilter(std::move(toMove.m_topicFilter)), m_qos(toMove.m_qos),
m_noLocal(toMove.m_noLocal), m_retain(toMove.m_retain),
m_noLocal(toMove.m_noLocal), m_retainAsPublished(toMove.m_retainAsPublished),
m_retainHnadlingType(toMove.m_retainHnadlingType)
{
}
Expand All @@ -965,7 +970,7 @@ namespace Aws
m_qos = toCopy.m_qos;
m_topicFilter = toCopy.m_topicFilter;
m_noLocal = toCopy.m_noLocal;
m_retain = toCopy.m_retain;
m_retainAsPublished = toCopy.m_retainAsPublished;
m_retainHnadlingType = toCopy.m_retainHnadlingType;
}
return *this;
Expand All @@ -979,7 +984,7 @@ namespace Aws
m_qos = toMove.m_qos;
m_topicFilter = std::move(toMove.m_topicFilter);
m_noLocal = toMove.m_noLocal;
m_retain = toMove.m_retain;
m_retainAsPublished = toMove.m_retainAsPublished;
m_retainHnadlingType = toMove.m_retainHnadlingType;
}
return *this;
Expand Down Expand Up @@ -1215,6 +1220,8 @@ namespace Aws

uint32_t NegotiatedSettings::getMaximumPacketSizeBytes() const noexcept { return m_maximumPacketSizeBytes; }

uint32_t NegotiatedSettings::getMaximumPacketSizeToServer() const noexcept { return m_maximumPacketSizeBytes; }

uint16_t NegotiatedSettings::getTopicAliasMaximumToServer() const noexcept
{
return m_topicAliasMaximumToServer;
Expand All @@ -1225,7 +1232,7 @@ namespace Aws
return m_topicAliasMaximumToClient;
}

uint16_t NegotiatedSettings::getServerKeepAlive() const noexcept { return m_serverKeepAliveSec; }
uint16_t NegotiatedSettings::getServerKeepAliveSec() const noexcept { return m_serverKeepAliveSec; }

bool NegotiatedSettings::getRetainAvailable() const noexcept { return m_retainAvailable; }

Expand Down
Loading

0 comments on commit d118c61

Please sign in to comment.