azure-core-amqp
Loading...
Searching...
No Matches
endpoint.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "azure/core/amqp/models/amqp_value.hpp"
7#include "common/async_operation_queue.hpp"
8#include "connection_string_credential.hpp"
9
10#include <chrono>
11#include <memory>
12#include <string>
13#include <vector>
14
15extern "C"
16{
17 struct ENDPOINT_INSTANCE_TAG;
18 struct LINK_ENDPOINT_INSTANCE_TAG;
19}
20namespace Azure { namespace Core { namespace Amqp { namespace _detail {
21 class EndpointFactory;
22 class LinkEndpointFactory;
23}}}} // namespace Azure::Core::Amqp::_detail
24namespace Azure { namespace Core { namespace Amqp { namespace _internal {
25 class ConnectionEvents;
26
27 // An "Endpoint" is an intermediate type used to create sessions in an OnNewSession callback.
28 class Endpoint final {
29 public:
30 ~Endpoint();
31 Endpoint(Endpoint&& that) noexcept : m_endpoint{that.m_endpoint} { that.m_endpoint = nullptr; }
32
33 private:
34 ENDPOINT_INSTANCE_TAG* m_endpoint;
35 Endpoint(ENDPOINT_INSTANCE_TAG* endpoint) : m_endpoint{endpoint} {};
36
37 Endpoint(Endpoint const&) = delete;
38 Endpoint& operator=(Endpoint const&) = delete;
39 Endpoint& operator=(Endpoint&& other) noexcept;
40 ENDPOINT_INSTANCE_TAG* Release()
41 {
42 ENDPOINT_INSTANCE_TAG* rv = m_endpoint;
43 m_endpoint = nullptr;
44 return rv;
45 }
46 friend class _detail::EndpointFactory;
47 friend class _internal::ConnectionEvents;
48 };
49
50 // A "Link Endpoint" is an intermediate type used to create new Links in an OnLinkAttached
51 // callback. Note that LinkEndpoints do not support copy semantics, and the only way to
52 // retrieve the underlying LINK_ENDPOINT_INSTANCE_TAG is to call Release(). That is because
53 // the primary use scenario for a LinkEndpoint is to call link_create_from_endpoint, and
54 // link_create_from_endpoint takes ownership of the underlying LINK_ENDPOINT object.
55 class LinkEndpoint final {
56 public:
57 LinkEndpoint(LinkEndpoint&& that) noexcept : m_endpoint{that.m_endpoint}
58 {
59 that.m_endpoint = nullptr;
60 }
61 ~LinkEndpoint(){};
62
63 LINK_ENDPOINT_INSTANCE_TAG* Get() const { return m_endpoint; }
64 std::uint32_t GetHandle() const;
65
66 private:
67 LINK_ENDPOINT_INSTANCE_TAG* m_endpoint;
68
69 LinkEndpoint(LINK_ENDPOINT_INSTANCE_TAG* endpoint) : m_endpoint{endpoint} {};
70 LINK_ENDPOINT_INSTANCE_TAG* Release()
71 {
72 LINK_ENDPOINT_INSTANCE_TAG* rv = m_endpoint;
73 m_endpoint = nullptr;
74 return rv;
75 }
76
77 /* NOTE: We do *NOT* own a LinkEndpoint object, it is completely controlled by uAMQP-c. As
78 * such, we are not allowed to free it.*/
79 LinkEndpoint(Endpoint const&) = delete;
80 LinkEndpoint& operator=(LinkEndpoint const&) = delete;
81
82 LinkEndpoint& operator=(Endpoint&& other);
83 friend class _detail::LinkEndpointFactory;
84 };
85}}}} // namespace Azure::Core::Amqp::_internal
86
87namespace Azure { namespace Core { namespace Amqp { namespace _detail {
88 class EndpointFactory final {
89 public:
90 static _internal::Endpoint CreateEndpoint(ENDPOINT_INSTANCE_TAG* endpoint);
91 static ENDPOINT_INSTANCE_TAG* Release(_internal::Endpoint& endpoint)
92 {
93 return endpoint.Release();
94 }
95 };
96 class LinkEndpointFactory final {
97 public:
98 static _internal::LinkEndpoint CreateLinkEndpoint(LINK_ENDPOINT_INSTANCE_TAG* endpoint);
99 static LINK_ENDPOINT_INSTANCE_TAG* Release(_internal::LinkEndpoint& linkEndpoint)
100 {
101 return linkEndpoint.Release();
102 }
103 };
104
105}}}} // namespace Azure::Core::Amqp::_detail