azure-core-amqp
Loading...
Searching...
No Matches
transport.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// Copyright (c) Microsoft Corporation.
5// Licensed under the MIT License.
6
7#pragma once
8#include <azure/core/context.hpp>
9
10#include <exception>
11#include <functional>
12#include <memory>
13#include <stdexcept>
14#include <string>
15
16namespace Azure { namespace Core { namespace Amqp { namespace Network { namespace _detail {
17 struct TransportImpl;
18}}}}} // namespace Azure::Core::Amqp::Network::_detail
19
20namespace Azure { namespace Core { namespace Amqp { namespace Network { namespace _internal {
21
26 enum class TransportOpenStatus
27 {
29 Invalid,
31 Ok,
33 Error,
35 Cancelled,
36 };
37
41 enum class TransportSendStatus
42 {
44 Invalid,
45
47 Unknown,
48
50 Ok,
51
53 Error,
54
56 Cancelled,
57 };
58
59 class Transport;
60
66 class TransportEvents {
67 protected:
68 ~TransportEvents() {}
69
70 public:
78 virtual void OnBytesReceived(
79 Transport const& transport,
80 const unsigned char* buffer,
81 size_t size)
82 = 0;
83
85 virtual void OnIOError() = 0;
86 };
87
88 class Transport final {
89
90 public:
91 using TransportSendCompleteFn = std::function<void(TransportSendStatus)>;
92
94 ~Transport();
95
101 TransportOpenStatus Open(Context const& context = {});
102
108 void Close(Context const& context = {});
109
117 bool Send(uint8_t* buffer, size_t size, TransportSendCompleteFn callback) const;
118
121 void Poll() const;
122
131 void SetEventHandler(TransportEvents* events);
132
133 Transport(std::shared_ptr<_detail::TransportImpl> impl) : m_impl{impl} {}
134 std::shared_ptr<_detail::TransportImpl> GetImpl() const { return m_impl; }
135
136 private:
137 std::shared_ptr<_detail::TransportImpl> m_impl;
138 };
139}}}}} // namespace Azure::Core::Amqp::Network::_internal