azure-core-amqp
Loading...
Searching...
No Matches
link.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "azure/core/amqp/internal/models/message_source.hpp"
7#include "azure/core/amqp/internal/models/message_target.hpp"
8#include "azure/core/amqp/internal/models/performatives/amqp_transfer.hpp"
9#include "azure/core/amqp/models/amqp_value.hpp"
10#include "azure/core/context.hpp"
11
12#include <chrono>
13#include <memory>
14#include <string>
15#include <vector>
16
17namespace Azure { namespace Core { namespace Amqp { namespace _internal {
18 class Session;
19 class LinkEndpoint;
20 enum class SenderSettleMode;
21 enum class ReceiverSettleMode;
22
23 enum class LinkDurability
24 {
25 None,
26 Configuration,
27 UnsettledState,
28 };
29
30 enum class SessionRole
31 {
32 Sender,
33 Receiver,
34 };
35}}}} // namespace Azure::Core::Amqp::_internal
36
37namespace Azure { namespace Core { namespace Amqp { namespace _detail {
38 class LinkImpl;
39
40 enum class LinkState
41 {
42 Invalid,
43 Detached,
44 HalfAttachedAttachSent,
45 HalfAttachedAttachReceived,
46 Attached,
47 Error,
48 };
49
50 std::ostream& operator<<(std::ostream& stream, LinkState linkState);
51
52 enum class LinkTransferResult
53 {
54 Error,
55 Busy,
56 };
57
58 enum class LinkDeliverySettleReason
59 {
60 DispositionReceived,
61 Settled,
62 NotDelivered,
63 Timeout,
64 Cancelled,
65 Invalid
66 };
67
68#if defined(_azure_TESTING_BUILD)
69
70 // Note that this entire class is a test hook to enable testing of the Link family of apis. It is
71 // not exposed to customers because there are no customer scenarios for it.
72 class Link;
73 class LinkImplEvents;
74 class LinkImplEventsImpl;
75
76 class LinkEvents {
77 public:
78 virtual Models::AmqpValue OnTransferReceived(
79 Link const& link,
80 Models::_internal::Performatives::AmqpTransfer transfer,
81 uint32_t payloadSize,
82 const unsigned char* payloadBytes)
83 = 0;
84 virtual void OnLinkStateChanged(
85 Link const& link,
86 LinkState newLinkState,
87 LinkState previousLinkState)
88 = 0;
89 virtual void OnLinkFlowOn(Link const& link) = 0;
90 virtual ~LinkEvents() = default;
91 };
92
93 class Link final {
94 public:
95 Link(
96 _internal::Session const& session,
97 std::string const& name,
98 _internal::SessionRole role,
99 Models::_internal::MessageSource const& source,
100 Models::_internal::MessageTarget const& target,
101 LinkEvents* events = nullptr);
102 Link(
103 _internal::Session const& session,
104 _internal::LinkEndpoint& linkEndpoint,
105 std::string const& name,
106 _internal::SessionRole role,
107 Models::_internal::MessageSource const& source,
108 Models::_internal::MessageTarget const& target,
109 LinkEvents* events = nullptr);
110 ~Link() noexcept;
111
112 Link(Link const&) = default;
113 Link& operator=(Link const&) = default;
114 Link(Link&&) noexcept = default;
115 Link& operator=(Link&&) noexcept = default;
116
117 void SetSenderSettleMode(_internal::SenderSettleMode senderSettleMode);
118 _internal::SenderSettleMode GetSenderSettleMode() const;
119
120 void SetReceiverSettleMode(_internal::ReceiverSettleMode receiverSettleMode);
121 _internal::ReceiverSettleMode GetReceiverSettleMode() const;
122
123 void SetInitialDeliveryCount(uint32_t initialDeliveryCount);
124 uint32_t GetInitialDeliveryCount() const;
125
126 void SetMaxMessageSize(uint64_t maxMessageSize);
127 uint64_t GetMaxMessageSize() const;
128
129 uint64_t GetPeerMaxMessageSize() const;
130
131 void SetAttachProperties(Models::AmqpValue const& attachProperties);
132 void SetMaxLinkCredit(uint32_t maxLinkCredit);
133
134 void SetDesiredCapabilities(Models::AmqpValue const& desiredCapabilities);
135 Models::AmqpValue GetDesiredCapabilities() const;
136
137 void ResetLinkCredit(std::uint32_t linkCredit, bool drain);
138
139 std::string GetName() const;
140
141 Models::_internal::MessageTarget const& GetTarget() const;
142 Models::_internal::MessageSource const& GetSource() const;
143
144 uint32_t GetReceivedMessageId() const;
145
146 void Attach();
147
148 std::tuple<uint32_t, LinkDeliverySettleReason, Models::AmqpValue> Transfer(
149 std::vector<uint8_t> const& payload,
150 Azure::Core::Context const& context);
151
152 void Detach(
153 bool close,
154 std::string const& errorCondition,
155 std::string const& errorDescription,
156 const Models::AmqpValue& info);
157
158 private:
159 friend class LinkImpl;
160 friend class LinkImplEventsImpl;
161 Link(std::shared_ptr<LinkImpl> impl) : m_impl{impl} {}
162 std::shared_ptr<LinkImplEvents> m_implEvents;
163 std::shared_ptr<LinkImpl> m_impl;
164 };
165#endif // _azure_TESTING_BUILD
166}}}} // namespace Azure::Core::Amqp::_detail